From fc5b810cb210f22572815642cdc810c7dc472319 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 8 May 2011 05:36:01 +0200 Subject: Graph/GLyph*: Add static factory method for non Renderer creation, separating text->OutlineShape and OutlineShape->Region step. --- .../jogamp/graph/curve/text/GlyphShape.java | 10 +- .../jogamp/graph/curve/text/GlyphString.java | 107 +++++++++++++++------ 2 files changed, 83 insertions(+), 34 deletions(-) diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java index 749292297..b6f37a610 100644 --- a/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java +++ b/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java @@ -72,16 +72,14 @@ public class GlyphShape { public final Vertex.Factory vertexFactory() { return shape.vertexFactory(); } - private void addVertexToLastOutline(Vertex vertex){ + private void addVertexToLastOutline(Vertex vertex) { shape.addVertex(vertex); } private void addOutlineVerticesFromGlyphVector(float[] coords, int segmentType){ switch(segmentType) { case PathIterator.SEG_MOVETO: - if(!shape.getLastOutline().isEmpty()){ - shape.addEmptyOutline(); - } + shape.addEmptyOutline(); addVertexToLastOutline(vertexFactory().create(coords, 0, 2, true)); numVertices++; break; @@ -108,6 +106,10 @@ public class GlyphShape { } } + public OutlineShape getShape() { + return shape; + } + public int getNumVertices() { return numVertices; } diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java index 852d84f5a..53a3ec5e0 100644 --- a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java +++ b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java @@ -29,6 +29,7 @@ package jogamp.graph.curve.text; import java.util.ArrayList; +import com.jogamp.graph.font.Font; import com.jogamp.graph.geom.AABBox; import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.Triangle; @@ -37,23 +38,71 @@ import com.jogamp.graph.geom.opengl.SVertex; 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; -import com.jogamp.graph.curve.RegionFactory; +import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RenderState; public class GlyphString { + /** Static font size for all default font OutlineShape generations via {@link #createString(OutlineShape, Factory, Font, String)}. + *

The actual font size shall be accomplished by the GL PMV matrix.

+ */ + public static final int STATIC_FONT_SIZE = 10; + private ArrayList glyphs = new ArrayList(); private CharSequence str; private String fontname; - private Region region; + private GLRegion region; private SVertex origin = new SVertex(); + /** + *

Uses {@link #STATIC_FONT_SIZE}.

+ *

No caching is performed.

+ * + * @param shape is not null, add all {@link GlyphShape}'s {@link Outline} to this instance. + * @param vertexFactory + * @param font + * @param str + * @return the created {@link GlyphString} instance + */ + public static GlyphString createString(OutlineShape shape, Factory vertexFactory, Font font, String str) { + return createString(shape, vertexFactory, font, STATIC_FONT_SIZE, str); + } + + /** + *

No caching is performed.

+ * + * @param shape is not null, add all {@link GlyphShape}'s {@link Outline} to this instance. + * @param vertexFactory + * @param font + * @param size + * @param str + * @return the created {@link GlyphString} instance + */ + public static GlyphString createString(OutlineShape shape, Factory 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); + + GlyphString glyphString = new GlyphString(font.getName(Font.NAME_UNIQUNAME), str); + glyphString.createfromFontPath(vertexFactory, paths, affineTransform); + if(null != shape) { + for(int i=0; i initializeTriangles(){ - ArrayList triangles = new ArrayList(); - for(GlyphShape glyph:glyphs){ - ArrayList tris = glyph.triangulate(); - triangles.addAll(tris); - } - return triangles; - } - /** Generate a OGL Region to represent this Object. * @param gl the current gl object * @param rs the current attached RenderState - * @param type either {@link com.jogamp.graph.curve.Region#SINGLE_PASS} - * or {@link com.jogamp.graph.curve.Region#TWO_PASS} + * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#TWO_PASS_RENDERING_BIT} */ - public void generateRegion(GL2ES2 gl, RenderState rs, int type){ - region = RegionFactory.create(rs, type); - region.setFlipped(true); - - ArrayList tris = initializeTriangles(); - region.addTriangles(tris); + public GLRegion createRegion(GL2ES2 gl, int renderModes){ + region = RegionFactory.create(renderModes); + // region.setFlipped(true); int numVertices = region.getNumVertices(); - for(GlyphShape glyph:glyphs){ + ArrayList tris = new ArrayList(); + + for(int i=0; i< glyphs.size(); i++) { + final GlyphShape glyph = glyphs.get(i); + ArrayList gtris = glyph.triangulate(); + tris.addAll(gtris); + ArrayList gVertices = glyph.getVertices(); - for(Vertex vert:gVertices){ - vert.setId(numVertices++); + for(int j=0; j