diff options
6 files changed, 35 insertions, 40 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 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<string.length(); i++) { final char character = string.charAt(i); if (character != ' ') { - final Glyph glyph = getGlyph(character); + final Glyph glyph = getGlyph(getGlyphID(character)); height = (int)Math.ceil(Math.max(glyph.getBBoxFU().getHeight(), height)); } } @@ -348,14 +346,17 @@ class TypecastFont implements Font { float y = 0; float advanceTotal = 0; + Font.Glyph left_glyph = null; for(int i=0; i< charCount; i++) { final char character = string.charAt(i); if( '\n' == character ) { y -= lineHeight; advanceTotal = 0; + left_glyph = null; } else if (character == ' ') { advanceTotal += getAdvanceWidthFU(Glyph.ID_SPACE); + left_glyph = null; } else { // reset transform if( null != transform ) { @@ -363,17 +364,19 @@ class TypecastFont implements Font { } else { temp1.setToIdentity(); } - temp1.translate(advanceTotal, y, temp2); - tbox.reset(); - - final Font.Glyph glyph = getGlyph(character); - res.resize(temp1.transform(glyph.getBBoxFU(), tbox)); - - final OutlineShape glyphShape = glyph.getShape(); - if( null == glyphShape ) { + final int glyph_id = getGlyphID(character); + final Font.Glyph glyph = getGlyph(glyph_id); + if( null == glyph.getShape() ) { + left_glyph = null; continue; } + if( null != left_glyph ) { + advanceTotal += left_glyph.getKerningFU(glyph_id); + } + temp1.translate(advanceTotal, y, temp2); + res.resize(temp1.transform(glyph.getBBoxFU(), tbox)); advanceTotal += glyph.getAdvanceFU(); + left_glyph = glyph; } } return res; diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java index e6a655661..d8f46090b 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java @@ -104,7 +104,6 @@ public final class TypecastGlyph implements Font.Glyph { return dst; } - private final char symbol; private final int id; private final int[/*right_glyphid*/][/*value*/] kerning; private final boolean kerning_horizontal; @@ -115,15 +114,13 @@ public final class TypecastGlyph implements Font.Glyph { /** * * @param font - * @param symbol * @param id * @param bbox in font-units * @param advance from hmtx in font-units * @param shape */ - protected TypecastGlyph(final TypecastFont font, final char symbol, final int id, final AABBox bbox, final int advance, + protected TypecastGlyph(final TypecastFont font, final int id, final AABBox bbox, final int advance, final KernSubtable kernSub, final OutlineShape shape) { - this.symbol = symbol; this.id = id; if( null != kernSub && kernSub.areKerningValues() ) { int pair_sz = 64; @@ -160,11 +157,6 @@ public final class TypecastGlyph implements Font.Glyph { return this.metrics.getFont(); } - @Override - public final char getSymbol() { - return this.symbol; - } - public final Metrics getMetrics() { return this.metrics; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java index 60319d842..8099a2ff7 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java @@ -75,7 +75,7 @@ public class TypecastRenderer { shape.addVertex(0, p3.x/unitsPerEM, p3.y/unitsPerEM, p3.onCurve); } */ - public static OutlineShape buildShape(final int unitsPerEM, final char symbol, final jogamp.graph.font.typecast.ot.Glyph glyph, final Factory<? extends Vertex> vertexFactory) { + public static OutlineShape buildShape(final int unitsPerEM, final jogamp.graph.font.typecast.ot.Glyph glyph, final Factory<? extends Vertex> 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; diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestFontsNEWT00.java b/src/test/com/jogamp/opengl/test/junit/graph/TestFontsNEWT00.java index be654d345..5b254d46d 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestFontsNEWT00.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestFontsNEWT00.java @@ -83,7 +83,7 @@ public class TestFontsNEWT00 extends UITestCase { void testFontGlyph01(final Font font, final char c, final float pixelSize) { final int glyphID = font.getGlyphID(c); final int s0 = font.getAdvanceWidthFU(glyphID); - final Font.Glyph glyph = font.getGlyph(c); + final Font.Glyph glyph = font.getGlyph(glyphID); final int s1 = glyph.getAdvanceFU(); final int unitsPerEM = font.getMetrics().getUnitsPerEM(); @@ -117,7 +117,7 @@ public class TestFontsNEWT00 extends UITestCase { void testFontGlyph02(final Font font, final char left, final char right) { final int glyphid_left = font.getGlyphID(left); final int glyphid_right = font.getGlyphID(right); - final Font.Glyph glyph_left = font.getGlyph(left); + final Font.Glyph glyph_left = font.getGlyph(glyphid_left); final int k_val = glyph_left.getKerningFU(glyphid_right); |