From ee2f44f34049f02ba8b13685ba2575ed647a9c22 Mon Sep 17 00:00:00 2001 From: "PSp..om" Date: Fri, 21 Oct 2011 08:27:09 +0000 Subject: [PATCH] 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 --- engine/src/core/com/jme3/font/LetterQuad.java | 13 +++++++++++++ engine/src/core/com/jme3/font/Letters.java | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/engine/src/core/com/jme3/font/LetterQuad.java b/engine/src/core/com/jme3/font/LetterQuad.java index edb3f5308..bf4b082bb 100644 --- a/engine/src/core/com/jme3/font/LetterQuad.java +++ b/engine/src/core/com/jme3/font/LetterQuad.java @@ -293,6 +293,15 @@ class LetterQuad { x0 = bound.x; } else { 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; @@ -301,6 +310,10 @@ class LetterQuad { if (lastChar != null && block.isKerning()) { kernAmount = lastChar.getKerning(c) * sizeScale; x0 += kernAmount * incrScale; + + // Need to unbake the kerning from xAdvance since it + // is baked into x0... see above. + xAdvance -= kernAmount * incrScale; } } if (isEndOfLine()) { diff --git a/engine/src/core/com/jme3/font/Letters.java b/engine/src/core/com/jme3/font/Letters.java index 198c4974b..34cd7dc4b 100644 --- a/engine/src/core/com/jme3/font/Letters.java +++ b/engine/src/core/com/jme3/font/Letters.java @@ -77,7 +77,7 @@ class Letters { int lineCount = 1; BitmapCharacter ellipsis = font.getCharSet().getCharacter(block.getEllipsisChar()); float ellipsisWidth = ellipsis!=null? ellipsis.getWidth()*getScale(): 0; - + while (!l.isTail()) { if (l.isInvalid()) { l.update(block);