diff options
Diffstat (limited to 'src/jogl/classes/jogamp')
-rw-r--r-- | src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java | 127 |
1 files changed, 81 insertions, 46 deletions
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java index 1f7134e14..d412562a3 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java @@ -41,37 +41,29 @@ import com.jogamp.graph.geom.Vertex.Factory; * http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6.html */ public class TypecastRenderer { - private static final boolean DEBUG = false; + private static final boolean DEBUG = true; private static void addShapeMoveTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1) { - shape.closeLastOutline(); + shape.closeLastOutline(false); shape.addEmptyOutline(); - shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, true)); // p1.onCurve)); + shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, p1.onCurve)); } 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(p1.x, p1.y, 0, p1.onCurve)); } 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(p1.x, p1.y, 0, p1.onCurve)); + shape.addVertex(0, vertexFactory.create(p2.x, p2.y, 0, p2.onCurve)); } 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)); // p2OnCurve)); + shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, p1.onCurve)); + shape.addVertex(0, vertexFactory.create(p2x, p2y, 0, p2OnCurve)); } - /** private static void addShapeCubicTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1, Point p2, Point p3) { - shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, false)); // p1.onCurve)); - shape.addVertex(0, vertexFactory.create(p2.x, p2.y, 0, false)); // p2.onCurve)); - shape.addVertex(0, vertexFactory.create(p3.x, p3.y, 0, true)); // p3.onCurve)); - // 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(); + shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, p1.onCurve)); + shape.addVertex(0, vertexFactory.create(p2.x, p2.y, 0, p2.onCurve)); + shape.addVertex(0, vertexFactory.create(p3.x, p3.y, 0, p3.onCurve)); } - */ public static OutlineShape buildShape(char symbol, OTGlyph glyph, Factory<? extends Vertex> vertexFactory) { // @@ -83,7 +75,13 @@ public class TypecastRenderer { } final OutlineShape shape = new OutlineShape(vertexFactory); + buildShapeImpl(shape, symbol, glyph, vertexFactory); + shape.closeLastOutline(false); + return shape; + } + /** + private static void buildShapeImpl02(final OutlineShape shape, char symbol, OTGlyph glyph, Factory<? extends Vertex> vertexFactory) { // 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; @@ -91,26 +89,57 @@ public class TypecastRenderer { for (int i = 0; i < glyph.getPointCount(); i++) { count++; if ( glyph.getPoint(i).endOfContour ) { + for(int j=0; j<count; j++) { + final Point p = glyph.getPoint(startIndex + j); + shape.addVertex(0, vertexFactory.create(p.x, p.y, 0, p.onCurve)); + } + shape.closeLastOutline(false); + startIndex = i + 1; + count = 0; + } + } + } */ + + private static void buildShapeImpl(final OutlineShape shape, char symbol, OTGlyph glyph, Factory<? extends Vertex> vertexFactory) { + // 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; + int count = 0; + final int totalPoints = glyph.getPointCount(); + for (int i = 0; i < totalPoints; i++) { + count++; + if ( glyph.getPoint(i).endOfContour ) { int offset = 0; - while (offset < count) { + while ( offset < count - 1 ) { // require at least +1 point (last one is end-of-contour) 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); + final Point point_plus3 = glyph.getPoint(startIndex + (offset+3)%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); + System.err.println("GlyphShape<"+symbol+">: "+count+"/"+totalPoints+" points, offset "+offset); + final int pMIdx= (offset==0) ? startIndex+count-1 : startIndex+(offset-1)%count; + final Point point_minus1 = glyph.getPoint(pMIdx); + final int p0Idx = startIndex + offset%count; + final int p1Idx = startIndex + (offset+1)%count; + final int p2Idx = startIndex + (offset+2)%count; + final int p3Idx = startIndex + (offset+3)%count; + System.err.println("\t pM["+pMIdx+"] "+point_minus1); + System.err.println("\t p0["+p0Idx+"] "+point); + System.err.println("\t p1["+p1Idx+"] "+point_plus1); + System.err.println("\t p2["+p2Idx+"] "+point_plus2); + System.err.println("\t p3["+p3Idx+"] "+point_plus3); } - if(offset == 0) - { + if(offset == 0) { addShapeMoveTo(shape, vertexFactory, point); // gp.moveTo(point.x, point.y); } - if (point.onCurve) { + if( point.endOfContour ) { + // Branch-0: EOC ** SHALL NEVER HAPPEN ** + if( DEBUG ) { System.err.println("B0 .. end-of-contour **** EOC"); } + shape.closeLastOutline(false); + break; + } else if (point.onCurve) { if (point_plus1.onCurve) { // Branch-1: point.onCurve && point_plus1.onCurve if( DEBUG ) { System.err.println("B1 .. line-to p0-p1"); } @@ -129,32 +158,39 @@ public class TypecastRenderer { addShapeQuadTo(shape, vertexFactory, point_plus1, point_plus2); offset+=2; } else { - // Branch-3: point.onCurve && !point_plus1.onCurve && !point_plus2.onCurve - if( DEBUG ) { System.err.println("B3 .. quad-to p0-p1-p2h **** MID"); } + if (point_plus3.onCurve) { + // Branch-3: point.onCurve && !point_plus1.onCurve && !point_plus2.onCurve && point_plus3.onCurve + if( DEBUG ) { System.err.println("B3 .. cubic-to p0-p1-p2-p3 **** CUBIC"); } + addShapeCubicTo(shape, vertexFactory, point_plus1, point_plus2, point_plus3); + offset+=3; + } else { + // Branch-4: point.onCurve && !point_plus1.onCurve && !point_plus2.onCurve && !point_plus3.onCurve + if( DEBUG ) { System.err.println("B4 .. 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 + // 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), true); + // 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"); } + // Branch-5: !point.onCurve && !point_plus1.onCurve + if( DEBUG ) { System.err.println("B5 .. 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); + midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y), true); offset++; } else { - // Branch-5: !point.onCurve && point_plus1.onCurve - if( DEBUG ) { System.err.println("B5 .. quad-to pM-p0-p1"); } + // Branch-6: !point.onCurve && point_plus1.onCurve + if( DEBUG ) { System.err.println("B6 .. 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); @@ -163,12 +199,11 @@ public class TypecastRenderer { } } } + shape.closeLastOutline(false); startIndex = i + 1; count = 0; } } - shape.closeLastOutline(); - return shape; } private static float midValue(float a, float b) { |