Преглед изворни кода

Fixed some really odd text advance behavior that
caused letters and characters to overlap each other.
Basically, the offset was being included in the next
chars position... and it shouldn't be.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8472 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

PSp..om пре 14 година
родитељ
комит
ee2f44f340
2 измењених фајлова са 14 додато и 1 уклоњено
  1. 13 0
      engine/src/core/com/jme3/font/LetterQuad.java
  2. 1 1
      engine/src/core/com/jme3/font/Letters.java

+ 13 - 0
engine/src/core/com/jme3/font/LetterQuad.java

@@ -293,6 +293,15 @@ class LetterQuad {
                 x0 = bound.x;
                 x0 = bound.x;
             } else {
             } else {
                 x0 = previous.getNextX() + xOffset * incrScale;
                 x0 = previous.getNextX() + xOffset * incrScale;
+                
+                // Since x0 will have offset baked into it then we
+                // need to counteract that in xAdvance.  This is better
+                // than removing it in getNextX() because we also need
+                // to take kerning into account below... which will also
+                // get baked in.
+                // Without this, getNextX() will return values too far to
+                // the left, for example.
+                xAdvance -= xOffset * incrScale; 
             }
             }
             y0 = lineY + LINE_DIR*yOffset;
             y0 = lineY + LINE_DIR*yOffset;
 
 
@@ -301,6 +310,10 @@ class LetterQuad {
             if (lastChar != null && block.isKerning()) {
             if (lastChar != null && block.isKerning()) {
                 kernAmount = lastChar.getKerning(c) * sizeScale;
                 kernAmount = lastChar.getKerning(c) * sizeScale;
                 x0 += kernAmount * incrScale;
                 x0 += kernAmount * incrScale;
+                
+                // Need to unbake the kerning from xAdvance since it
+                // is baked into x0... see above.
+                xAdvance -= kernAmount * incrScale; 
             }
             }
         }
         }
         if (isEndOfLine()) {
         if (isEndOfLine()) {

+ 1 - 1
engine/src/core/com/jme3/font/Letters.java

@@ -77,7 +77,7 @@ class Letters {
         int lineCount = 1;
         int lineCount = 1;
         BitmapCharacter ellipsis = font.getCharSet().getCharacter(block.getEllipsisChar());
         BitmapCharacter ellipsis = font.getCharSet().getCharacter(block.getEllipsisChar());
         float ellipsisWidth = ellipsis!=null? ellipsis.getWidth()*getScale(): 0;
         float ellipsisWidth = ellipsis!=null? ellipsis.getWidth()*getScale(): 0;
-        
+ 
         while (!l.isTail()) {
         while (!l.isTail()) {
             if (l.isInvalid()) {
             if (l.isInvalid()) {
                 l.update(block);
                 l.update(block);