diff options
Diffstat (limited to 'src/jogl/classes/jogamp')
3 files changed, 89 insertions, 63 deletions
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java index c8feb26d3..1f7134e14 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java @@ -37,30 +37,27 @@ import com.jogamp.graph.geom.Vertex.Factory; /** * Factory to build an {@link OutlineShape} from * {@link jogamp.graph.font.typecast.ot.OTGlyph Glyph}s. + * + * http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6.html */ public class TypecastRenderer { + private static final boolean DEBUG = false; private static void addShapeMoveTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1) { shape.closeLastOutline(); shape.addEmptyOutline(); shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, true)); // p1.onCurve)); - // shape.addVertex(0, vertexFactory.create(coords, 0, 2, true)); } private static void addShapeLineTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1) { shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, true)); // p1.onCurve)); - // shape.addVertex(0, vertexFactory.create(coords, 0, 2, true)); } private static void addShapeQuadTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1, Point p2) { shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, false)); // p1.onCurve)); shape.addVertex(0, vertexFactory.create(p2.x, p2.y, 0, true)); // p2.onCurve)); - // shape.addVertex(0, vertexFactory.create(coords, 0, 2, false)); - // shape.addVertex(0, vertexFactory.create(coords, 2, 2, true)); } - private static void addShapeQuadTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1, int p2x, int p2y) { + private static void addShapeQuadTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1, float p2x, float p2y, boolean p2OnCurve) { shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, false)); // p1.onCurve)); - shape.addVertex(0, vertexFactory.create(p2x, p2y, 0, true)); // p2.onCurve)); - // shape.addVertex(0, vertexFactory.create(coords, 0, 2, false)); - // shape.addVertex(0, vertexFactory.create(coords, 2, 2, true)); + shape.addVertex(0, vertexFactory.create(p2x, p2y, 0, true)); // p2OnCurve)); } /** private static void addShapeCubicTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1, Point p2, Point p3) { @@ -70,13 +67,16 @@ public class TypecastRenderer { // shape.addVertex(0, vertexFactory.create(coords, 0, 2, false)); // shape.addVertex(0, vertexFactory.create(coords, 2, 2, false)); // shape.addVertex(0, vertexFactory.create(coords, 4, 2, true)); - } private static void addShapeClose(final OutlineShape shape, Factory<? extends Vertex> vertexFactory) { shape.closeLastOutline(); - } */ + } + */ - public static OutlineShape buildShape(OTGlyph glyph, Factory<? extends Vertex> vertexFactory) { + public static OutlineShape buildShape(char symbol, OTGlyph glyph, Factory<? extends Vertex> vertexFactory) { + // + // See Typecast: GlyphPathFactory.addContourToPath(..) + // if (glyph == null) { return null; @@ -90,59 +90,78 @@ public class TypecastRenderer { int count = 0; for (int i = 0; i < glyph.getPointCount(); i++) { count++; - if (glyph.getPoint(i).endOfContour) { - { - int offset = 0; - while (offset < count) { - final Point point = glyph.getPoint(startIndex + offset%count); - final Point point_plus1 = glyph.getPoint(startIndex + (offset+1)%count); - final Point point_plus2 = glyph.getPoint(startIndex + (offset+2)%count); - if(offset == 0) - { - addShapeMoveTo(shape, vertexFactory, point); - // gp.moveTo(point.x, point.y); - } + if ( glyph.getPoint(i).endOfContour ) { + int offset = 0; + while (offset < count) { + final Point point = glyph.getPoint(startIndex + offset%count); + final Point point_plus1 = glyph.getPoint(startIndex + (offset+1)%count); + final Point point_plus2 = glyph.getPoint(startIndex + (offset+2)%count); + if( DEBUG ) { + final Point point_minus1 = glyph.getPoint((offset==0) ? startIndex+count-1 : startIndex+(offset-1)%count); + System.err.println("GlyphShape<"+symbol+">: "+count+" points, offset "+offset); + System.err.println("\t p-1 "+point_minus1); + System.err.println("\t p0 "+point); + System.err.println("\t p1 "+point_plus1); + System.err.println("\t p2 "+point_plus2); + } + if(offset == 0) + { + addShapeMoveTo(shape, vertexFactory, point); + // gp.moveTo(point.x, point.y); + } - if (point.onCurve) { - if (point_plus1.onCurve) { - // s = new Line2D.Float(point.x, point.y, point_plus1.x, point_plus1.y); - addShapeLineTo(shape, vertexFactory, point_plus1); - // gp.lineTo( point_plus1.x, point_plus1.y ); - offset++; - } else { - if (point_plus2.onCurve) { - // s = new QuadCurve2D.Float( point.x, point.y, point_plus1.x, point_plus1.y, point_plus2.x, point_plus2.y); - addShapeQuadTo(shape, vertexFactory, point_plus1, point_plus2); - // gp.quadTo(point_plus1.x, point_plus1.y, point_plus2.x, point_plus2.y); - offset+=2; - } else { - // s = new QuadCurve2D.Float(point.x,point.y,point_plus1.x,point_plus1.y, - // midValue(point_plus1.x, point_plus2.x), midValue(point_plus1.y, point_plus2.y)); - addShapeQuadTo(shape, vertexFactory, point_plus1, midValue(point_plus1.x, point_plus2.x), midValue(point_plus1.y, point_plus2.y)); - // gp.quadTo(point_plus1.x, point_plus1.y, midValue(point_plus1.x, point_plus2.x), midValue(point_plus1.y, point_plus2.y)); - offset+=2; - } - } + if (point.onCurve) { + if (point_plus1.onCurve) { + // Branch-1: point.onCurve && point_plus1.onCurve + if( DEBUG ) { System.err.println("B1 .. line-to p0-p1"); } + + // s = new Line2D.Float(point.x, point.y, point_plus1.x, point_plus1.y); + // gp.lineTo( point_plus1.x, point_plus1.y ); + addShapeLineTo(shape, vertexFactory, point_plus1); + offset++; } else { - if (point_plus1.onCurve) { - // s = new QuadCurve2D.Float(midValue(point_minus1.x, point.x), midValue(point_minus1.y, point.y), - // point.x, point.y, point_plus1.x, point_plus1.y); - //gp.curve3(point_plus1.x, point_plus1.y, point.x, point.y); - addShapeQuadTo(shape, vertexFactory, point, point_plus1); - // gp.quadTo(point.x, point.y, point_plus1.x, point_plus1.y); - offset++; + if (point_plus2.onCurve) { + // Branch-2: point.onCurve && !point_plus1.onCurve && point_plus2.onCurve + if( DEBUG ) { System.err.println("B2 .. quad-to p0-p1-p2"); } + // s = new QuadCurve2D.Float( point.x, point.y, point_plus1.x, point_plus1.y, point_plus2.x, point_plus2.y); + // gp.quadTo(point_plus1.x, point_plus1.y, point_plus2.x, point_plus2.y); + addShapeQuadTo(shape, vertexFactory, point_plus1, point_plus2); + offset+=2; } else { - // s = new QuadCurve2D.Float(midValue(point_minus1.x, point.x), midValue(point_minus1.y, point.y), point.x, point.y, - // midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y)); - //gp.curve3(midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y), point.x, point.y); - addShapeQuadTo(shape, vertexFactory, point, midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y)); - // gp.quadTo(point.x, point.y, midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y)); - offset++; + // Branch-3: point.onCurve && !point_plus1.onCurve && !point_plus2.onCurve + if( DEBUG ) { System.err.println("B3 .. quad-to p0-p1-p2h **** MID"); } + + // s = new QuadCurve2D.Float(point.x,point.y,point_plus1.x,point_plus1.y, + // midValue(point_plus1.x, point_plus2.x), midValue(point_plus1.y, point_plus2.y)); + // gp.quadTo(point_plus1.x, point_plus1.y, midValue(point_plus1.x, point_plus2.x), midValue(point_plus1.y, point_plus2.y)); + addShapeQuadTo(shape, vertexFactory, point_plus1, + midValue(point_plus1.x, point_plus2.x), + midValue(point_plus1.y, point_plus2.y), false); + // offset++; // Don't skip point_plus2, not completed yet FIXME ? + offset+=2; // As done in Typecast } } + } else { + if (!point_plus1.onCurve) { + // Branch-4: !point.onCurve && !point_plus1.onCurve + if( DEBUG ) { System.err.println("B4 .. quad-to pM-p0-p1h ***** MID"); } + // s = new QuadCurve2D.Float(midValue(point_minus1.x, point.x), midValue(point_minus1.y, point.y), + // point.x, point.y, + // midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y)); + addShapeQuadTo(shape, vertexFactory, point, + midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y), false); + offset++; + } else { + // Branch-5: !point.onCurve && point_plus1.onCurve + if( DEBUG ) { System.err.println("B5 .. quad-to pM-p0-p1"); } + // s = new QuadCurve2D.Float(midValue(point_minus1.x, point.x), midValue(point_minus1.y, point.y), + // point.x, point.y, point_plus1.x, point_plus1.y); + // gp.quadTo(point.x, point.y, point_plus1.x, point_plus1.y); + addShapeQuadTo(shape, vertexFactory, point, point_plus1); + offset++; + } } - } startIndex = i + 1; count = 0; @@ -152,7 +171,11 @@ public class TypecastRenderer { return shape; } - private static int midValue(int a, int b) { - return a + (b - a)/2; + private static float midValue(float a, float b) { + return a + (b - a)/2f; } + /** + private static Point midPoint(Point a, Point b, boolean onCurve) { + return new Point(midValue(a.x, b.x), midValue(a.y, b.y), onCurve, false); + } */ } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/Point.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/Point.java index f1a090d68..0cac8ab44 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/Point.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/Point.java @@ -18,7 +18,6 @@ public class Point { public int y = 0; public boolean onCurve = true; public boolean endOfContour = false; - public boolean touched = false; public Point(int x, int y, boolean onCurve, boolean endOfContour) { this.x = x; @@ -26,4 +25,8 @@ public class Point { this.onCurve = onCurve; this.endOfContour = endOfContour; } + + public String toString() { + return "P["+x+"/"+y+", on "+onCurve+", end "+endOfContour+"]"; + } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/t2/T2Interpreter.java b/src/jogl/classes/jogamp/graph/font/typecast/t2/T2Interpreter.java index 181ec7e10..73f26b27c 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/t2/T2Interpreter.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/t2/T2Interpreter.java @@ -39,11 +39,11 @@ public class T2Interpreter { private static final int SUBR_STACK_LIMIT = 10; private static final int TRANSIENT_ARRAY_ELEMENT_COUNT = 32; - private Number[] _argStack = new Number[ARGUMENT_STACK_LIMIT]; + private final Number[] _argStack = new Number[ARGUMENT_STACK_LIMIT]; private int _argStackIndex = 0; - private int[] _subrStack = new int[SUBR_STACK_LIMIT]; + private final int[] _subrStack = new int[SUBR_STACK_LIMIT]; private int _subrStackIndex = 0; - private Number[] _transientArray = new Number[TRANSIENT_ARRAY_ELEMENT_COUNT]; + private final Number[] _transientArray = new Number[TRANSIENT_ARRAY_ELEMENT_COUNT]; private ArrayList<Point> _points; |