diff --git a/assets/silly/bmf/nds12.png b/assets/silly/bmf/nds12_0.png similarity index 100% rename from assets/silly/bmf/nds12.png rename to assets/silly/bmf/nds12_0.png diff --git a/assets/silly/bmf/onds12.png b/assets/silly/bmf/onds12_0.png similarity index 100% rename from assets/silly/bmf/onds12.png rename to assets/silly/bmf/onds12_0.png diff --git a/raw/nds12/nds12.png b/raw/nds12/nds12_0.png similarity index 100% rename from raw/nds12/nds12.png rename to raw/nds12/nds12_0.png diff --git a/raw/nds12/onds12.fnt b/raw/nds12/onds12.fnt index a41868f..6c8d748 100644 Binary files a/raw/nds12/onds12.fnt and b/raw/nds12/onds12.fnt differ diff --git a/src/sillysagiri/BMF.java b/src/sillysagiri/BMF.java index ea87b92..f0ee47a 100644 --- a/src/sillysagiri/BMF.java +++ b/src/sillysagiri/BMF.java @@ -126,6 +126,53 @@ public class BMF { } } + // TODO: handle multiline + public short[] Measure(String str) + { + short left = 0; + short right = 0; + short top = 0; + short bottom = 0; + short[] cursor = new short[]{0, 0}; + boolean isFirst = true; + + for (int i=0; i 127)) index = 127; + + if (index == '\n') + { + isFirst = true; + cursor[1] += lineHeight; + cursor[0] = 0; + continue; + } + + short[] ch = chars[index-32]; + int[] offset = new int[]{ch[XOFF]+cursor[0], ch[YOFF]+cursor[1]}; + + // check first XOFF + if (isFirst) + { + left = (short)Math.min(ch[XOFF], left); + isFirst = false; + } + + right = (short)Math.max(right, offset[0]+ch[WIDTH]); + top = (short)Math.min(top, offset[1]); + bottom = (short)Math.max(bottom, offset[1]+ch[HEIGHT]); + + cursor[0] += ch[XADV]; + } + + return new short[]{ + (short)(right+Math.abs(left)), // x + (short)(bottom+Math.abs(top)), // y + left, top // xoff, yoff + }; + } + public void Draw(Graphics g, String str, int x, int y) { short[] cursor = new short[]{0, 0}; @@ -148,7 +195,7 @@ public class BMF { img, ch[X], ch[Y], ch[WIDTH], ch[HEIGHT], Sprite.TRANS_NONE, - x+offset[0], y+offset[1], + offset[0], offset[1], Graphics.TOP | Graphics.LEFT); cursor[0] += ch[XADV];