Commits

Michael Ludwig committed ddd4ccd

Correct bugs in text layout width computation.

  • Participants
  • Parent commits c5589c9

Comments (0)

Files changed (3)

File ferox-renderer/ferox-renderer-api/src/main/java/com/ferox/util/geom/text/CharacterSet.java

      */
     public CharacterSet(Font font, String characterSet, boolean antiAlias, boolean useNpotTexture) {
         if (font == null)
-            font = Font.decode("Arial-PLAIN-12");
+            font = Font.decode("Arial-BOLD-14");
         if (characterSet == null)
             characterSet = DEFAULT_CHAR_SET;
 
 
     /*
      * Turn the string into an array of characters, and add the missing glyph
-     * code. Only includes characters the font can render. Excludes whitespace
+     * code. Only includes characters the font can render.
      */
     private char[] getCharArray(String characterSet) {
         Set<Character> set = new HashSet<Character>();

File ferox-renderer/ferox-renderer-api/src/main/java/com/ferox/util/geom/text/Text.java

         float[] v = new float[vertexCount * 8]; // V3F_N3F_T2F
 
         // compute centering information
-        float xOffset = -width / 2f;//0f;
-        float yOffset = height / 2f;//0f;
+        float xOffset = -width / 2f;
+        float yOffset = height / 2f;
 
         // extract individual arrays from interleaved array into nio buffers
         int i = 0;
         private float cursorX;
         private float cursorY;
 
-        private final float leftEdge;
         // amount to subtract cursorY to get the next line
         private final float height;
         private final float ascent, descent;
 
         private float maxWidth;
+        private float lineWidth;
         private final float wrapWidth;
 
         private final CharacterSet charSet;
          * lm must not be null.
          */
         public TextLayout(CharacterSet charSet, LineMetrics lm, float wrapWidth) {
-            leftEdge = 0f;
-
             height = lm.getHeight();
             ascent = lm.getAscent();
             descent = lm.getDescent();
          */
         public float[] doLayout(String text) {
             // reset values for the layout
-            maxWidth = leftEdge;
+            maxWidth = 0;
+            lineWidth = 0;
 
-            cursorX = leftEdge;
+            cursorX = 0;
             cursorY = -ascent;
 
             // we're being conservative here, but memory is cheap
             // add in last word, if needed
             coordIndex = placeWord(currentWord, coords, coordIndex);
 
-            maxWidth = Math.max(maxWidth, cursorX);
+            maxWidth = Math.max(maxWidth, lineWidth);
             return coords;
         }
 
                     // just advance the space width, but don't place glyphs
                     // only place space if we've moved off of left edge, or on first line
                     g = charSet.getGlyph(' ');
-                    if (cursorX > leftEdge || cursorY == -ascent)
+                    if (cursorX > 0 || cursorY == -ascent)
                         cursorX += g.getAdvance();
                     break;
                 default:
                         // place a newline if the char can't fit on this line
                         // and it wasn't the first char for the line (we always
                         // put 1 char)
-                        if (cursorX > leftEdge && cursorX + g.getAdvance() > wrapWidth)
+                        if (cursorX > 0 && cursorX + g.getAdvance() > wrapWidth)
                             newline();
                     }
                     index = placeGlyph(g, coords, index);
             coords[index++] = tcT;
             coords[index++] = vtL;
             coords[index++] = vtT;
-
+            
             // advance the x position
             cursorX += g.getAdvance();
+            lineWidth = vtR;
 
             return index;
         }
          * the newline.
          */
         private void newline() {
-            maxWidth = Math.max(maxWidth, cursorX);
-
-            cursorX = leftEdge;
+            cursorX = 0;
             cursorY -= height;
+            maxWidth = Math.max(maxWidth, lineWidth);
+            lineWidth = 0;
         }
 
         /*

File ferox-renderer/ferox-renderer-api/src/main/java/com/ferox/util/geom/text/TextRenderer.java

                     ffp.setMaterial(BLACK, textColor, BLACK, BLACK);
                     
                     ffp.setTexture(0, charSet.getTexture());
-                    // FIXME any texture combine changes needed?
-                    
+                                        
                     for (Entry<Geometry, Matrix4> e: textLayout.entrySet()) {
                         ffp.setModelViewMatrix(e.getValue());