diff options
Diffstat (limited to 'src/jogl/classes/com/jogamp/graph/curve')
-rw-r--r-- | src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java | 69 |
1 files changed, 48 insertions, 21 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java index 714be1998..fb77775ad 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java @@ -37,8 +37,7 @@ import com.jogamp.opengl.math.geom.AABBox; import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.curve.Region; import com.jogamp.graph.font.Font; -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.Vertex.Factory; +import com.jogamp.graph.font.Font.Glyph; import com.jogamp.graph.geom.plane.AffineTransform; /** @@ -67,28 +66,53 @@ public class TextRegionUtil { } /** - * Add the string in 3D space w.r.t. the font in font em-size [0..1] at the end of the {@link GLRegion}. + * Add the string in 3D space w.r.t. the font in font em-size [0..1] at the end of the {@link GLRegion} + * while passing the progressed {@link AffineTransform}. * <p> - * The shapes added to the GLRegion are in font em-size [0..1]. + * The shapes added to the GLRegion are in font em-size [0..1], but can be adjusted with the given transform, progressed and passed to the visitor. + * </p> + * <p> + * Origin of rendered text is 0/0 at bottom left. + * </p> + * @param region the {@link GLRegion} sink + * @param font the target {@link Font} + * @param transform optional given transform + * @param str string text + * @param rgbaColor if {@link Region#hasColorChannel()} RGBA color must be passed, otherwise value is ignored. + * @return the bounding box of the given string by taking each glyph's font em-sized [0..1] OutlineShape into account. + */ + public static AABBox addStringToRegion(final Region region, final Font font, final AffineTransform transform, + final CharSequence str, final float[] rgbaColor) { + return addStringToRegion(region, font, transform, str, rgbaColor, new AffineTransform(), new AffineTransform()); + } + + /** + * Add the string in 3D space w.r.t. the font in font em-size [0..1] at the end of the {@link GLRegion} + * while passing the progressed {@link AffineTransform}. + * <p> + * The shapes added to the GLRegion are in font em-size [0..1], but can be adjusted with the given transform, progressed and passed to the visitor. + * </p> + * <p> + * Origin of rendered text is 0/0 at bottom left. * </p> * @param region the {@link GLRegion} sink - * @param vertexFactory vertex impl factory {@link Factory} * @param font the target {@link Font} + * @param transform optional given transform * @param str string text * @param rgbaColor if {@link Region#hasColorChannel()} RGBA color must be passed, otherwise value is ignored. * @param temp1 temporary AffineTransform storage, mandatory * @param temp2 temporary AffineTransform storage, mandatory * @return the bounding box of the given string by taking each glyph's font em-sized [0..1] OutlineShape into account. */ - public static AABBox addStringToRegion(final GLRegion region, final Factory<? extends Vertex> vertexFactory, - final Font font, final CharSequence str, final float[] rgbaColor, + public static AABBox addStringToRegion(final Region region, final Font font, final AffineTransform transform, + final CharSequence str, final float[] rgbaColor, final AffineTransform temp1, final AffineTransform temp2) { final OutlineShape.Visitor visitor = new OutlineShape.Visitor() { @Override public final void visit(final OutlineShape shape, final AffineTransform t) { region.addOutlineShape(shape, t, region.hasColorChannel() ? rgbaColor : null); } }; - return font.processString(visitor, null, str, temp1, temp2); + return font.processString(visitor, transform, str, temp1, temp2); } /** @@ -97,6 +121,9 @@ public class TextRegionUtil { * The shapes added to the GLRegion are in font em-size [0..1]. * </p> * <p> + * Origin of rendered text is 0/0 at bottom left. + * </p> + * <p> * Cached {@link GLRegion}s will be destroyed w/ {@link #clear(GL2ES2)} or to free memory. * </p> * @param gl the current GL state @@ -117,13 +144,15 @@ public class TextRegionUtil { } final int special = 0; GLRegion region = getCachedRegion(font, str, special); + AABBox res; if(null == region) { region = GLRegion.create(renderModes, null); - addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, str, rgbaColor, tempT1, tempT2); + res = addStringToRegion(region, font, null, str, rgbaColor, tempT1, tempT2); addCachedRegion(gl, font, str, special, region); + } else { + res = new AABBox(); + res.copy(region.getBounds()); } - final AABBox res = new AABBox(); - res.copy(region.getBounds()); region.draw(gl, renderer, sampleCount); return res; } @@ -134,6 +163,9 @@ public class TextRegionUtil { * The shapes added to the GLRegion are in font em-size [0..1]. * </p> * <p> + * Origin of rendered text is 0/0 at bottom left. + * </p> + * <p> * In case of a multisampling region renderer, i.e. {@link Region#VBAA_RENDERING_BIT}, recreating the {@link GLRegion} * is a huge performance impact. * In such case better use {@link #drawString3D(GL2ES2, GLRegion, RegionRenderer, Font, CharSequence, float[], int[])} @@ -155,12 +187,8 @@ public class TextRegionUtil { if(!renderer.isInitialized()){ throw new GLException("TextRendererImpl01: not initialized!"); } - final AffineTransform temp1 = new AffineTransform(); - final AffineTransform temp2 = new AffineTransform(); final GLRegion region = GLRegion.create(renderModes, null); - addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, str, rgbaColor, temp1, temp2); - final AABBox res = new AABBox(); - res.copy(region.getBounds()); + final AABBox res = addStringToRegion(region, font, null, str, rgbaColor); region.draw(gl, renderer, sampleCount); region.destroy(gl); return res; @@ -172,6 +200,9 @@ public class TextRegionUtil { * <p> * The shapes added to the GLRegion are in font em-size [0..1]. * </p> + * <p> + * Origin of rendered text is 0/0 at bottom left. + * </p> * @param gl the current GL state * @param font {@link Font} to be used * @param str text to be rendered @@ -187,12 +218,8 @@ public class TextRegionUtil { if(!renderer.isInitialized()){ throw new GLException("TextRendererImpl01: not initialized!"); } - final AffineTransform temp1 = new AffineTransform(); - final AffineTransform temp2 = new AffineTransform(); region.clear(gl); - addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, str, rgbaColor, temp1, temp2); - final AABBox res = new AABBox(); - res.copy(region.getBounds()); + final AABBox res = addStringToRegion(region, font, null, str, rgbaColor); region.draw(gl, renderer, sampleCount); return res; } |