diff options
6 files changed, 98 insertions, 95 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java index 073afe9bd..5e25a4ced 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java @@ -31,18 +31,11 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; -import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; import jogamp.graph.curve.text.GlyphString; -import jogamp.graph.font.FontInt; -import jogamp.graph.geom.plane.AffineTransform; -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 abstract class TextRenderer extends Renderer { /** diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java index ed51cce98..578148699 100644 --- a/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java +++ b/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java @@ -29,10 +29,9 @@ package jogamp.graph.curve.text; import java.util.ArrayList; -import jogamp.graph.geom.plane.PathIterator; - import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.Triangle; +import com.jogamp.graph.geom.Vertex.Factory; import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.math.Quaternion; @@ -40,7 +39,6 @@ import com.jogamp.graph.math.Quaternion; public class GlyphShape { private Quaternion quat= null; - private int numVertices = 0; private OutlineShape shape = null; /** Create a new Glyph shape @@ -50,70 +48,24 @@ public class GlyphShape { shape = new OutlineShape(factory); } - /** Create a GlyphShape from a font Path Iterator - * @param pathIterator the path iterator - * - * @see PathIterator + /** Create a new GlyphShape from a {@link OutlineShape} + * @param factory vertex impl factory {@link Factory} + * @param shape {@link OutlineShape} representation of the Glyph */ - public GlyphShape(Vertex.Factory<? extends Vertex> factory, PathIterator pathIterator){ + public GlyphShape(Vertex.Factory<? extends Vertex> factory, OutlineShape shape){ this(factory); - - if(null != pathIterator){ - while(!pathIterator.isDone()){ - float[] coords = new float[6]; - int segmentType = pathIterator.currentSegment(coords); - addOutlineVerticesFromGlyphVector(coords, segmentType); - - pathIterator.next(); - } - } - shape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS); + this.shape = shape; + this.shape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS); } public final Vertex.Factory<? extends Vertex> vertexFactory() { return shape.vertexFactory(); } - private void addVertexToLastOutline(Vertex vertex) { - //FIXME: assuming font outline comes in CW order - shape.addVertex(0, vertex); - } - - private void addOutlineVerticesFromGlyphVector(float[] coords, int segmentType){ - switch(segmentType) { - case PathIterator.SEG_MOVETO: - shape.closeLastOutline(); - shape.addEmptyOutline(); - addVertexToLastOutline(vertexFactory().create(coords, 0, 2, true)); - numVertices++; - break; - case PathIterator.SEG_LINETO: - addVertexToLastOutline(vertexFactory().create(coords, 0, 2, true)); - numVertices++; - break; - case PathIterator.SEG_QUADTO: - addVertexToLastOutline(vertexFactory().create(coords, 0, 2, false)); - addVertexToLastOutline(vertexFactory().create(coords, 2, 2, true)); - numVertices+=2; - break; - case PathIterator.SEG_CUBICTO: - addVertexToLastOutline(vertexFactory().create(coords, 0, 2, false)); - addVertexToLastOutline(vertexFactory().create(coords, 2, 2, false)); - addVertexToLastOutline(vertexFactory().create(coords, 4, 2, true)); - numVertices+=3; - break; - case PathIterator.SEG_CLOSE: - shape.closeLastOutline(); - break; - default: - throw new IllegalArgumentException("Unhandled Segment Type: "+segmentType); - } - } - public OutlineShape getShape() { return shape; } public int getNumVertices() { - return numVertices; + return shape.getVertices().size(); } /** Get the rotational Quaternion attached to this Shape diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java index cd6cd56aa..c07b41a7b 100644 --- a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java +++ b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java @@ -40,10 +40,6 @@ import javax.media.opengl.GL2ES2; import jogamp.graph.curve.opengl.RegionFactory; import jogamp.graph.font.FontInt; -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.curve.Region; @@ -68,9 +64,9 @@ public class GlyphString { * <p>No caching is performed.</p> * * @param shape is not null, add all {@link GlyphShape}'s {@link Outline} to this instance. - * @param vertexFactory - * @param font - * @param str + * @param vertexFactory vertex impl factory {@link Factory} + * @param font the target {@link Font} + * @param str string text * @return the created {@link GlyphString} instance */ public static GlyphString createString(OutlineShape shape, Factory<? extends Vertex> vertexFactory, Font font, String str) { @@ -81,20 +77,17 @@ public class GlyphString { * <p>No caching is performed.</p> * * @param shape is not null, add all {@link GlyphShape}'s {@link Outline} to this instance. - * @param vertexFactory - * @param font - * @param size - * @param str + * @param vertexFactory vertex impl factory {@link Factory} + * @param font the target {@link Font} + * @param size font size + * @param str string text * @return the created {@link GlyphString} instance */ public static GlyphString createString(OutlineShape shape, Factory<? extends Vertex> vertexFactory, Font font, int fontSize, String str) { - AffineTransform affineTransform = new AffineTransform(vertexFactory); - - Path2D[] paths = new Path2D[str.length()]; - ((FontInt)font).getPaths(str, fontSize, affineTransform, paths); + ArrayList<OutlineShape> shapes = ((FontInt)font).getOutlineShapes(str, fontSize, vertexFactory); GlyphString glyphString = new GlyphString(font.getName(Font.NAME_UNIQUNAME), str); - glyphString.createfromFontPath(vertexFactory, paths, affineTransform); + glyphString.createfromOutlineShapes(vertexFactory, shapes); if(null != shape) { for(int i=0; i<glyphString.glyphs.size(); i++) { shape.addOutlineShape(glyphString.glyphs.get(i).getShape()); @@ -121,19 +114,17 @@ public class GlyphString { return str; } - /** Creates the Curve based Glyphs from a Font + /**Creates the Curve based Glyphs from a list of {@link OutlineShape} * @param vertexFactory vertex impl factory {@link Factory} - * @param paths a list of FontPath2D objects that define the outline - * @param affineTransform a global affine transformation applied to the paths. + * @param shapes list of {@link OutlineShape} */ - public void createfromFontPath(Factory<? extends Vertex> vertexFactory, Path2D[] paths, AffineTransform affineTransform) { - final int numGlyps = paths.length; + public void createfromOutlineShapes(Factory<? extends Vertex> vertexFactory, ArrayList<OutlineShape> shapes) { + final int numGlyps = shapes.size(); for (int index=0;index<numGlyps;index++){ - if(paths[index] == null){ + if(shapes.get(index) == null){ continue; } - PathIterator iterator = paths[index].iterator(affineTransform); - GlyphShape glyphShape = new GlyphShape(vertexFactory, iterator); + GlyphShape glyphShape = new GlyphShape(vertexFactory, shapes.get(index)); if(glyphShape.getNumVertices() < 3) { continue; @@ -142,6 +133,7 @@ public class GlyphString { } } + /** Generate a OGL Region to represent this Object. * @param gl the current gl object * @param rs the current attached RenderState 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<OutlineShape> getOutlineShapes(CharSequence string, float pixelSize, Factory<? extends Vertex> 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<OutlineShape> getOutlineShapes(CharSequence string, float pixelSize, Factory<? extends Vertex> 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<OutlineShape> getOutlineShapes(TypecastFont font, CharSequence string, float pixelSize, AffineTransform transform, Factory<? extends Vertex> vertexFactory) { + Path2D[] paths = new Path2D[string.length()]; + getPaths(font, string, pixelSize, transform, paths); + + ArrayList<OutlineShape> shapes = new ArrayList<OutlineShape>(); + final int numGlyps = paths.length; + for (int index=0;index<numGlyps;index++) { + if(paths[index] == null){ + continue; + } + OutlineShape shape = new OutlineShape(vertexFactory); + shapes.add(shape); + PathIterator iterator = paths[index].iterator(transform); + if(null != iterator){ + while(!iterator.isDone()){ + float[] coords = new float[6]; + int segmentType = iterator.currentSegment(coords); + addPathVertexToOutline(shape, vertexFactory, coords, segmentType); + iterator.next(); + } + } + } + return shapes; + } + private static void addPathVertexToOutline(OutlineShape shape, Factory<? extends Vertex> 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 |