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 | |
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')
-rw-r--r-- | src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java | 35 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/graph/font/Font.java | 56 |
2 files changed, 48 insertions, 43 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(); } diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java index 9f25b5481..5c63227b3 100644 --- a/src/jogl/classes/com/jogamp/graph/font/Font.java +++ b/src/jogl/classes/com/jogamp/graph/font/Font.java @@ -144,6 +144,8 @@ public interface Font { Font getFont(); char getSymbol(); + + /** Return this glyph's ID */ int getID(); /** @@ -188,20 +190,49 @@ public interface Font { */ float getAdvance(final float pixelSize); + /** True if kerning values are horizontal, otherwise vertical */ + boolean isKerningHorizontal(); + /** True if kerning values are perpendicular to text flow, otherwise along with flow */ + boolean isKerningCrossstream(); + + /** Return the number of kerning values stored for this glyph, associated to a right hand glyph. */ + int getKerningPairCount(); + + /** + * Returns the optional kerning inter-glyph distance within words between this glyph and the given right glyph_id in font-units to be divided by unitsPerEM + * + * @param right_glyphid right glyph code id + * @return font-units to be divided by unitsPerEM + */ + int getKerningFU(final int right_glyphid); + + /** + * Returns the optional kerning inter-glyph distance within words between this glyph and the given right glyph_id in fractional font em-size [0..1]. + * + * @param right_glyphid right glyph code id + * @return fractional font em-size distance [0..1] + */ + float getKerning(final int right_glyphid); + OutlineShape getShape(); @Override int hashCode(); + + @Override + String toString(); + + /** Return all glyph details as string. */ + String fullString(); } String getName(final int nameIndex); - StringBuilder getName(final StringBuilder string, final int nameIndex); /** Shall return the family and subfamily name, separated a dash. * <p>{@link #getName(StringBuilder, int)} w/ {@link #NAME_FAMILY} and {@link #NAME_SUBFAMILY}</p> * <p>Example: "{@code Ubuntu-Regular}"</p> */ - StringBuilder getFullFamilyName(final StringBuilder buffer); + String getFullFamilyName(); StringBuilder getAllNames(final StringBuilder string, final String separator); @@ -225,27 +256,12 @@ public interface Font { */ int getAdvanceWidthFU(final int glyphID); - /** - * Returns the optional kerning inter-glyph distance within words in fractional font em-size [0..1]. - * - * @param left_glyphid left glyph code id - * @param right_glyphid right glyph code id - * @return fractional font em-size distance [0..1] - */ - float getKerning(final int left_glyphid, final int right_glyphid); - - /** - * Returns the optional kerning inter-glyph distance within words in fractional font-units to be divided by unitsPerEM - * - * @param left_glyphid left glyph code id - * @param right_glyphid right glyph code id - * @return font-units to be divided by unitsPerEM - */ - int getKerningFU(final int left_glyphid, final int right_glyphid); - Metrics getMetrics(); + int getGlyphID(final char symbol); + Glyph getGlyph(final char symbol); + int getNumGlyphs(); /** |