From 3c3f663bfe25e296b46344a2825c6a2714c29c89 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 14 Feb 2023 09:42:34 +0100 Subject: Graph Font: getGlyph(char symbol -> int glyph_id), add kerning to getPointsBoundsFU(); Glyph: Drop getSymbol() --- .../jogamp/graph/font/typecast/TypecastFont.java | 45 ++++++++++++---------- .../jogamp/graph/font/typecast/TypecastGlyph.java | 10 +---- .../graph/font/typecast/TypecastRenderer.java | 8 ++-- 3 files changed, 29 insertions(+), 34 deletions(-) (limited to 'src/jogl/classes/jogamp') diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java index 382d35a73..b45e2c215 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java @@ -56,7 +56,7 @@ class TypecastFont implements Font { /* pp */ final TTFont font; private final CmapFormat cmapFormat; private final int cmapentries; - private final IntObjectHashMap char2Glyph; + private final IntObjectHashMap idToGlyph; private final TypecastHMetrics metrics; // FIXME: Add cache size to limit memory usage ?? @@ -147,7 +147,7 @@ class TypecastFont implements Font { } } } - char2Glyph = new IntObjectHashMap(cmapentries + cmapentries/4); + idToGlyph = new IntObjectHashMap(cmapentries + cmapentries/4); metrics = new TypecastHMetrics(this); } @@ -197,11 +197,9 @@ class TypecastFont implements Font { } @Override - public Glyph getGlyph(final char symbol) { - TypecastGlyph result = (TypecastGlyph) char2Glyph.get(symbol); + public Glyph getGlyph(final int glyph_id) { + TypecastGlyph result = (TypecastGlyph) idToGlyph.get(glyph_id); if (null == result) { - final int glyph_id = getGlyphID( symbol ); - jogamp.graph.font.typecast.ot.Glyph glyph = font.getGlyph(glyph_id); final int glyph_advance; final AABBox glyph_bbox; @@ -222,9 +220,9 @@ class TypecastFont implements Font { break; } if(null == glyph) { - throw new RuntimeException("Could not retrieve glyph for symbol: <"+symbol+"> "+(int)symbol+" -> glyph id "+glyph_id); + throw new RuntimeException("Could not retrieve glyph for glyph id "+glyph_id); } - final OutlineShape shape = TypecastRenderer.buildShape(metrics.getUnitsPerEM(), symbol, glyph, vertexFactory); + final OutlineShape shape = TypecastRenderer.buildShape(metrics.getUnitsPerEM(), glyph, vertexFactory); KernSubtable kernSub = null; { final KernTable kern = font.getKernTable(); @@ -232,17 +230,17 @@ class TypecastFont implements Font { kernSub = kern.getSubtable0(); } } - result = new TypecastGlyph(this, symbol, glyph_id, glyph_bbox, glyph_advance, kernSub, shape); + result = new TypecastGlyph(this, glyph_id, glyph_bbox, glyph_advance, kernSub, shape); if(DEBUG) { final PostTable post = font.getPostTable(); final String glyph_name = null != post ? post.getGlyphName(glyph_id) : "n/a"; - System.err.println("New glyph: " + (int)symbol + " ( " + symbol +" ) -> " + glyph_id + "/'"+glyph_name+"', contours " + glyph.getPointCount() + ": " + shape); + System.err.println("New glyph: " + glyph_id + "/'"+glyph_name+"', contours " + glyph.getPointCount() + ": " + shape); System.err.println(" "+glyph); System.err.println(" "+result); } glyph.clearPointData(); - char2Glyph.put(symbol, result); + idToGlyph.put(glyph_id, result); } return result; } @@ -276,7 +274,7 @@ class TypecastFont implements Font { if (character == '\n') { width = 0; } else { - final Glyph glyph = getGlyph(character); + final Glyph glyph = getGlyph(getGlyphID(character)); width += glyph.getAdvanceFU(); } } @@ -295,7 +293,7 @@ class TypecastFont implements Font { for (int i=0; i vertexFactory) { + public static OutlineShape buildShape(final int unitsPerEM, final jogamp.graph.font.typecast.ot.Glyph glyph, final Factory vertexFactory) { // // See Typecast: GlyphPathFactory.addContourToPath(..) // @@ -84,12 +84,12 @@ public class TypecastRenderer { } final OutlineShape shape = new OutlineShape(vertexFactory); - buildShapeImpl(unitsPerEM, shape, symbol, glyph); + buildShapeImpl(unitsPerEM, shape, glyph); shape.setIsQuadraticNurbs(); return shape; } - private static void buildShapeImpl(final float unitsPerEM, final OutlineShape shape, final char symbol, final jogamp.graph.font.typecast.ot.Glyph glyph) { + private static void buildShapeImpl(final float unitsPerEM, final OutlineShape shape, final jogamp.graph.font.typecast.ot.Glyph glyph) { // Iterate through all of the points in the glyph. Each time we find a // contour end point, add the point range to the path. int startIndex = 0; @@ -105,7 +105,7 @@ public class TypecastRenderer { final Point p2 = glyph.getPoint(startIndex + (offset+2)%count); final Point p3 = offset+3 < count ? glyph.getPoint(startIndex + offset+3) : null; if( DEBUG ) { - System.err.println("GlyphShape<"+symbol+">: offset "+offset+" of "+count+"/"+totalPoints+" points"); + System.err.println("GlyphShape<"+glyph.getGlyphIndex()+">: offset "+offset+" of "+count+"/"+totalPoints+" points"); final int pMIdx= (offset==0) ? startIndex+count-1 : startIndex+(offset-1)%count; final Point pM = glyph.getPoint(pMIdx); final int p0Idx = startIndex + offset%count; -- cgit v1.2.3