diff options
author | Sven Gothel <sgothel@jausoft.com> | 2011-05-08 05:36:01 +0200 |
---|---|---|
committer | Sven Gothel <sgothel@jausoft.com> | 2011-05-08 05:36:01 +0200 |
commit | fc5b810cb210f22572815642cdc810c7dc472319 (patch) | |
tree | fc6f02d3652d7fe75b4018c8739728bf9fef6d7d /src/jogl/classes | |
parent | 624a52690b429c486bb8946d58f77936ead41785 (diff) |
Graph/GLyph*: Add static factory method for non Renderer creation,
separating text->OutlineShape and OutlineShape->Region step.
Diffstat (limited to 'src/jogl/classes')
-rw-r--r-- | src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java | 10 | ||||
-rw-r--r-- | src/jogl/classes/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<? extends Vertex> 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)}. + * <p>The actual font size shall be accomplished by the GL PMV matrix.</p> + */ + public static final int STATIC_FONT_SIZE = 10; + private ArrayList<GlyphShape> glyphs = new ArrayList<GlyphShape>(); private CharSequence str; private String fontname; - private Region region; + private GLRegion region; private SVertex origin = new SVertex(); + /** + * <p>Uses {@link #STATIC_FONT_SIZE}.</p> + * <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 + * @return the created {@link GlyphString} instance + */ + public static GlyphString createString(OutlineShape shape, Factory<? extends Vertex> vertexFactory, Font font, String str) { + return createString(shape, vertexFactory, font, STATIC_FONT_SIZE, str); + } + + /** + * <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 + * @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); + + GlyphString glyphString = new GlyphString(font.getName(Font.NAME_UNIQUNAME), str); + glyphString.createfromFontPath(vertexFactory, paths, affineTransform); + if(null != shape) { + for(int i=0; i<glyphString.glyphs.size(); i++) { + shape.addOutlineShape(glyphString.glyphs.get(i).getShape()); + } + } + return glyphString; + } + /** Create a new GlyphString object * @param fontname the name of the font that this String is * associated with @@ -93,39 +142,31 @@ public class GlyphString { } } - private ArrayList<Triangle> initializeTriangles(){ - ArrayList<Triangle> triangles = new ArrayList<Triangle>(); - for(GlyphShape glyph:glyphs){ - ArrayList<Triangle> 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<Triangle> 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<Triangle> tris = new ArrayList<Triangle>(); + + for(int i=0; i< glyphs.size(); i++) { + final GlyphShape glyph = glyphs.get(i); + ArrayList<Triangle> gtris = glyph.triangulate(); + tris.addAll(gtris); + ArrayList<Vertex> gVertices = glyph.getVertices(); - for(Vertex vert:gVertices){ - vert.setId(numVertices++); + for(int j=0; j<gVertices.size(); j++) { + gVertices.get(j).setId(numVertices++); } - region.addVertices(gVertices); + region.addVertices(gVertices); } - - /** initialize the region */ - region.update(gl); + region.addTriangles(tris); + return region; } /** Generate a Hashcode for this object @@ -139,13 +180,13 @@ public class GlyphString { * previously generated. */ public void renderString3D(GL2ES2 gl) { - region.render(gl, null, 0, 0, 0); + region.draw(gl, null, 0, 0, 0); } /** Render the Object based using the associated Region * previously generated. */ public void renderString3D(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int size) { - region.render(gl, rs, vp_width, vp_height, size); + region.draw(gl, rs, vp_width, vp_height, size); } /** Get the Origin of this GlyphString @@ -158,8 +199,14 @@ public class GlyphString { /** Destroy the associated OGL objects * @param rs the current attached RenderState */ - public void destroy(GL2ES2 gl, RenderState rs){ - region.destroy(gl, rs); + public void destroy(GL2ES2 gl, RenderState rs) { + if(null != gl && null != rs) { + region.destroy(gl, rs); + region = null; + } else if(null != region) { + throw new InternalError("destroy called w/o GL context, but has a region"); + } + glyphs.clear(); } public AABBox getBounds(){ |