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/curve/opengl/TextRegionUtil.java | 5 ++- src/jogl/classes/com/jogamp/graph/font/Font.java | 3 +- .../jogamp/graph/font/typecast/TypecastFont.java | 45 ++++++++++++---------- .../jogamp/graph/font/typecast/TypecastGlyph.java | 10 +---- .../graph/font/typecast/TypecastRenderer.java | 8 ++-- 5 files changed, 33 insertions(+), 38 deletions(-) (limited to 'src/jogl') 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 4af40bf1c..f9db8c655 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java @@ -119,14 +119,15 @@ public class TextRegionUtil { } else { temp1.setToIdentity(); } - final Font.Glyph glyph = font.getGlyph(character); + final int glyph_id = font.getGlyphID(character); + final Font.Glyph glyph = font.getGlyph(glyph_id); final OutlineShape glyphShape = glyph.getShape(); if( null == glyphShape ) { left_glyph = null; continue; } if( null != left_glyph ) { - advanceTotal += left_glyph.getKerning(glyph.getID()); + advanceTotal += left_glyph.getKerning(glyph_id); } temp1.translate(advanceTotal, y, temp2); visitor.visit(glyphShape, temp1); diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java index 2d26b1a85..1b852436f 100644 --- a/src/jogl/classes/com/jogamp/graph/font/Font.java +++ b/src/jogl/classes/com/jogamp/graph/font/Font.java @@ -161,7 +161,6 @@ public interface Font { public static final int ID_SPACE = 3; Font getFont(); - char getSymbol(); /** Return this glyph's ID */ int getID(); @@ -262,7 +261,7 @@ public interface Font { int getGlyphID(final char symbol); - Glyph getGlyph(final char symbol); + Glyph getGlyph(final int glyph_id); int getNumGlyphs(); 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