[Committed] Vertical offset for BitmapFont

Well, the actual LineHeight of a Text block is not the actual height of a line of text in respect to the baseline of the text. I needed to adjust the BitmapFont so that i can set a Y axis offset so it can be correctly placed. So, one can change the overall vertical position of a BitmapFont by setting it at runtime or letting the BitmapFontLoader read it from the .fnt file. The additional code is short an not complex:



Index: src/com/jmex/angelfont/BitmapCharacterSet.java
===================================================================
--- src/com/jmex/angelfont/BitmapCharacterSet.java   (revision 4682)
+++ src/com/jmex/angelfont/BitmapCharacterSet.java   (working copy)
@@ -46,6 +46,7 @@
     private int renderedSize;
     private int width;
     private int height;
+    private int yOffset;
     private Map<Integer, BitmapCharacter> characters;
 
     public BitmapCharacterSet() {
@@ -99,4 +100,12 @@
     public void setHeight(int height) {
         this.height = height;
     }
+
+    public void setyOffset(int yOffset) {
+        this.yOffset = yOffset;
+    }
+
+    public int getyOffset() {
+        return yOffset;
+    }
 }
No newline at end of file
Index: src/com/jmex/angelfont/BitmapFont.java
===================================================================
--- src/com/jmex/angelfont/BitmapFont.java   (revision 4682)
+++ src/com/jmex/angelfont/BitmapFont.java   (working copy)
@@ -124,7 +124,7 @@
                 float height = 0;
                 if (c != null) {
                     xOffset = c.getXOffset() * sizeScale;
-                    yOffset = c.getYOffset() * sizeScale;
+                    yOffset = (charSet.getyOffset() + c.getYOffset()) * sizeScale;
                     xAdvance = c.getXAdvance() * sizeScale;
                     width = c.getWidth() * sizeScale;
                     height = c.getHeight() * sizeScale;
@@ -310,7 +310,7 @@
                 float height = 0;
                if (c != null) {
                   xOffset = c.getXOffset() * sizeScale;
-                  yOffset = c.getYOffset() * sizeScale;
+                  yOffset = (charSet.getyOffset() + c.getYOffset()) * sizeScale;
                   xAdvance = c.getXAdvance() * sizeScale;
                   width = c.getWidth() * sizeScale;
                   height = c.getHeight() * sizeScale;
@@ -331,7 +331,7 @@
                             BitmapCharacter localChar = q.getBitmapChar();
 
                             float localxOffset = localChar.getXOffset() * sizeScale;
-                            float localyOffset = localChar.getYOffset() * sizeScale;
+                            float localyOffset = (charSet.getyOffset() + localChar.getYOffset()) * sizeScale;
                             float localxAdvance = localChar.getXAdvance() * sizeScale;
 
                             // Move current word to the left side of the text
Index: src/com/jmex/angelfont/BitmapFontLoader.java
===================================================================
--- src/com/jmex/angelfont/BitmapFontLoader.java   (revision 4682)
+++ src/com/jmex/angelfont/BitmapFontLoader.java   (working copy)
@@ -118,6 +118,8 @@
                             charSet.setWidth(Integer.parseInt(tokens[i + 1]));
                         } else if (token.equals("scaleH")) {
                             charSet.setHeight(Integer.parseInt(tokens[i + 1]));
+                        } else if (token.equals("yoffset")) {
+                            charSet.setyOffset(Integer.parseInt(tokens[i + 1]));
                         } // else if
                     }
                 } else if (tokens[0].equals("char")) {
Index: src/com/jmex/angelfont/angelFont.fnt
===================================================================
--- src/com/jmex/angelfont/angelFont.fnt   (revision 4682)
+++ src/com/jmex/angelfont/angelFont.fnt   (working copy)
@@ -1,5 +1,5 @@
 info face="Impact" size=64 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=2,2 outline=0

-common lineHeight=64 base=53 scaleW=512 scaleH=512 pages=1 packed=0 alphaChnl=0 redChnl=0 greenChnl=0 blueChnl=0

+common lineHeight=64 base=53 scaleW=512 scaleH=512 pages=1 packed=0 alphaChnl=0 redChnl=0 greenChnl=0 blueChnl=0 yoffset=0

 page id=0 file="numbers_00.png"

 chars count=195

 char id=32   x=505   y=97    width=1     height=1     xoffset=0     yoffset=53    xadvance=9     page=0  chnl=15