diff options
author | Sven Gothel <[email protected]> | 2023-02-12 07:17:16 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-02-12 07:17:16 +0100 |
commit | 93c51380f34c3eb203f46df52fed49a8a967510e (patch) | |
tree | 52d8745dffc4f7581efdc118f7ec0792b7b75315 /src/jogl/classes/com/jogamp/graph/curve | |
parent | 87060fe41b559418ea7b383e162d3d80fb515e0b (diff) |
Graph font/typecast: Adopt to our Typecast updates (see below); Fix kerning; Use TestTextRendererNEWT01 to produce validation snaps
- Move kerning handling from Font to Font.Glyph using binary-search for right-glyph-id on kerning subset from this instance (left)
- TextRegionUtil: Kerning must be added before translation as it applies before the current right-glyph.
- TestTextRendererNEWT01 produces validation snapshots against LibreOffice print-preview snapshots
- GPUTextRendererListenerBase01 added another text for kerning validation, show more font-size details (pt, px, mm)
Diffstat (limited to 'src/jogl/classes/com/jogamp/graph/curve')
-rw-r--r-- | src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java index 5aa2be258..a4ba4bf52 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java @@ -89,25 +89,21 @@ public class TextRegionUtil { final int charCount = str.length(); // region.setFlipped(true); - final Font.Metrics metrics = font.getMetrics(); final int lineHeight = font.getLineHeightFU(); int y = 0; int advanceTotal = 0; - char left_character = 0; - int left_glyphid = 0; + Font.Glyph left_glyph = null; for(int i=0; i< charCount; i++) { final char character = str.charAt(i); if( '\n' == character ) { y -= lineHeight; advanceTotal = 0; - left_glyphid = 0; - left_character = 0; + left_glyph = null; } else if (character == ' ') { advanceTotal += font.getAdvanceWidthFU(Glyph.ID_SPACE); - left_glyphid = 0; - left_character = character; + left_glyph = null; } else { // reset transform if( null != transform ) { @@ -115,27 +111,20 @@ public class TextRegionUtil { } else { temp1.setToIdentity(); } - temp1.translate(advanceTotal, y, temp2); - final Font.Glyph glyph = font.getGlyph(character); final OutlineShape glyphShape = glyph.getShape(); if( null == glyphShape ) { - left_glyphid = 0; + left_glyph = null; + temp1.translate(advanceTotal, y, temp2); continue; } - visitor.visit(glyphShape, temp1); - final int right_glyphid = glyph.getID(); - final int kern = font.getKerningFU(left_glyphid, right_glyphid); - final int advance = glyph.getAdvanceFU(); - advanceTotal += advance + kern; - if( Region.DEBUG_INSTANCE && 0 != left_character && kern > 0f ) { - System.err.println(": '"+left_character+"'/"+left_glyphid+" -> '"+character+"'/"+right_glyphid+ - ": a "+advance+"px + k ["+kern+"em, "+kern+"px = "+(advance+kern)+"px -> "+advanceTotal+"px, y "+y); + if( null != left_glyph ) { + advanceTotal += left_glyph.getKerningFU(glyph.getID()); } - // advanceTotal += glyph.getAdvance(pixelSize, true) - // + font.getKerning(left_glyphid, right_glyphid); - left_glyphid = right_glyphid; - left_character = character; + temp1.translate(advanceTotal, y, temp2); + visitor.visit(glyphShape, temp1); + advanceTotal += glyph.getAdvanceFU(); + left_glyph = glyph; } } } @@ -351,7 +340,7 @@ public class TextRegionUtil { protected final String getKey(final Font font, final CharSequence str, final int special) { final StringBuilder sb = new StringBuilder(); - return font.getName(sb, Font.NAME_UNIQUNAME) + return sb.append( font.getName(Font.NAME_UNIQUNAME) ) .append(".").append(str.hashCode()).append(".").append(special).toString(); } |