From 9cefde9395002717bb6bfde461f4a65c69a888dd Mon Sep 17 00:00:00 2001 From: Rami Santina Date: Thu, 2 Jun 2011 16:00:01 +0300 Subject: Font and TypecastRender generate array of OutlineShapes instead of Path2D GlyphShape and GlyphString use only OutlineShapes --- src/jogl/classes/jogamp/graph/font/FontInt.java | 9 ++-- .../jogamp/graph/font/typecast/TypecastFont.java | 12 +++-- .../graph/font/typecast/TypecastRenderer.java | 61 +++++++++++++++++++++- 3 files changed, 74 insertions(+), 8 deletions(-) (limited to 'src/jogl/classes/jogamp/graph/font') diff --git a/src/jogl/classes/jogamp/graph/font/FontInt.java b/src/jogl/classes/jogamp/graph/font/FontInt.java index 6c25f9a80..37660bb2c 100644 --- a/src/jogl/classes/jogamp/graph/font/FontInt.java +++ b/src/jogl/classes/jogamp/graph/font/FontInt.java @@ -27,11 +27,14 @@ */ package jogamp.graph.font; -import jogamp.graph.geom.plane.AffineTransform; +import java.util.ArrayList; + import jogamp.graph.geom.plane.Path2D; import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.font.Font; +import com.jogamp.graph.geom.Vertex; +import com.jogamp.graph.geom.Vertex.Factory; public interface FontInt extends Font { @@ -46,7 +49,5 @@ public interface FontInt extends Font { public Path2D getPath(float pixelSize); } - public void getPaths(CharSequence string, float pixelSize, - AffineTransform transform, Path2D[] result); - //TODO: Rami - ADD getOutlines without path2D + public ArrayList getOutlineShapes(CharSequence string, float pixelSize, Factory vertexFactory); } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java index 2e692e5ce..8806f537d 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java @@ -27,6 +27,8 @@ */ package jogamp.graph.font.typecast; +import java.util.ArrayList; + import jogamp.graph.font.FontInt; import jogamp.graph.font.typecast.ot.OTFont; import jogamp.graph.font.typecast.ot.OTFontCollection; @@ -39,9 +41,12 @@ import jogamp.graph.geom.plane.AffineTransform; import jogamp.graph.geom.plane.Path2D; import com.jogamp.common.util.IntObjectHashMap; +import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; import com.jogamp.graph.geom.AABBox; +import com.jogamp.graph.geom.Vertex; +import com.jogamp.graph.geom.Vertex.Factory; class TypecastFont implements FontInt { static final boolean DEBUG = false; @@ -208,9 +213,10 @@ class TypecastFont implements FontInt { } return result; } - - public void getPaths(CharSequence string, float pixelSize, AffineTransform transform, Path2D[] result) { - TypecastRenderer.getPaths(this, string, pixelSize, transform, result); + + public ArrayList getOutlineShapes(CharSequence string, float pixelSize, Factory vertexFactory) { + AffineTransform transform = new AffineTransform(vertexFactory); + return TypecastRenderer.getOutlineShapes(this, string, pixelSize, transform, vertexFactory); } public float getStringWidth(CharSequence string, float pixelSize) { diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java index 310b2b274..50b510d23 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java @@ -27,12 +27,19 @@ */ package jogamp.graph.font.typecast; +import java.util.ArrayList; + +import jogamp.graph.curve.text.GlyphShape; import jogamp.graph.font.typecast.ot.OTGlyph; import jogamp.graph.font.typecast.ot.Point; import jogamp.graph.geom.plane.AffineTransform; import jogamp.graph.geom.plane.Path2D; +import jogamp.graph.geom.plane.PathIterator; +import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.font.Font; +import com.jogamp.graph.geom.Vertex; +import com.jogamp.graph.geom.Vertex.Factory; /** * Factory to build a {@link com.jogamp.graph.geom.Path2D Path2D} from @@ -40,7 +47,7 @@ import com.jogamp.graph.font.Font; */ public class TypecastRenderer { - public static void getPaths(TypecastFont font, + private static void getPaths(TypecastFont font, CharSequence string, float pixelSize, AffineTransform transform, Path2D[] p) { if (string == null) { @@ -82,6 +89,58 @@ public class TypecastRenderer { } } + public static ArrayList getOutlineShapes(TypecastFont font, CharSequence string, float pixelSize, AffineTransform transform, Factory vertexFactory) { + Path2D[] paths = new Path2D[string.length()]; + getPaths(font, string, pixelSize, transform, paths); + + ArrayList shapes = new ArrayList(); + final int numGlyps = paths.length; + for (int index=0;index vertexFactory, float[] coords, int segmentType){ + switch(segmentType) { + case PathIterator.SEG_MOVETO: + shape.closeLastOutline(); + shape.addEmptyOutline(); + shape.addVertex(0, vertexFactory.create(coords, 0, 2, true)); + //numVertices++; + break; + case PathIterator.SEG_LINETO: + shape.addVertex(0, vertexFactory.create(coords, 0, 2, true)); + break; + case PathIterator.SEG_QUADTO: + shape.addVertex(0, vertexFactory.create(coords, 0, 2, false)); + shape.addVertex(0, vertexFactory.create(coords, 2, 2, true)); + break; + case PathIterator.SEG_CUBICTO: + 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)); + break; + case PathIterator.SEG_CLOSE: + shape.closeLastOutline(); + break; + default: + throw new IllegalArgumentException("Unhandled Segment Type: "+segmentType); + } + } + /** * Build a {@link com.jogamp.graph.geom.Path2D Path2D} from a * {@link jogamp.graph.font.typecast.ot.OTGlyph Glyph}. This glyph path can then -- cgit v1.2.3