From 61962236ac093574f267d55ea2a580861578a4b7 Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Sun, 8 Apr 2007 16:12:27 +0000 Subject: More fully debugged tokenized rendering of strings and turned it on by default. Can be disabled by specifying -Djogl.TextRenderer.nosplit. Exposed getSpaceWidth() on request of emzic on javagaming.org forums. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1195 232f8b59-042b-4e1e-8c03-345bb8c30851 --- .../com/sun/opengl/util/j2d/TextRenderer.java | 32 +++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'src/classes/com/sun/opengl/util/j2d') diff --git a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java index 468590b7d..ca4617abb 100755 --- a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java +++ b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java @@ -129,7 +129,7 @@ public class TextRenderer { // producing identical (or even vaguely similar) rendering results; // may ultimately yield more efficient use of the backing store, but // also seems to have performance issues due to rendering more quads - private boolean splitAtSpaces; + private boolean splitAtSpaces = !Debug.isPropertyDefined("jogl.TextRenderer.nosplit"); private int spaceWidth = -1; private List/**/ tokenizationResults = new ArrayList/**/(); @@ -545,7 +545,7 @@ public class TextRenderer { data.markUsed(); // Align the leftmost point of the baseline to the (x, y, z) coordinate requested - renderer.draw3DRect(x - scaleFactor * (data.origin().x + xOffset), + renderer.draw3DRect(x + xOffset - scaleFactor * data.origin().x, y - scaleFactor * ((rect.h() - data.origin().y)), z, rect.x(), @@ -569,6 +569,23 @@ public class TextRenderer { endRendering(true); } + /** Returns the width of the ASCII space character, in pixels, drawn + in this TextRenderer's font when no scaling or rotation has been + applied. This is the horizontal advance of the space character. + + @return the width of the space character in the TextRenderer's font + */ + public int getSpaceWidth() { + if (spaceWidth < 0) { + Graphics2D g = getGraphics2D(); + FontRenderContext frc = getFontRenderContext(); + GlyphVector gv = font.createGlyphVector(frc, " "); + GlyphMetrics metrics = gv.getGlyphMetrics(0); + spaceWidth = (int) metrics.getAdvanceX(); + } + return spaceWidth; + } + /** Ends a 3D render cycle with this {@link TextRenderer TextRenderer}. Restores several OpenGL state bits. Should be paired with {@link #begin3DRendering begin3DRendering}. @@ -702,17 +719,6 @@ public class TextRenderer { } } - private int getSpaceWidth() { - if (spaceWidth < 0) { - Graphics2D g = getGraphics2D(); - FontRenderContext frc = getFontRenderContext(); - GlyphVector gv = font.createGlyphVector(frc, " "); - Rectangle2D bbox = gv.getLogicalBounds(); - spaceWidth = (int) bbox.getWidth(); - } - return spaceWidth; - } - private void tokenize(String str) { // Avoid lots of little allocations per render tokenizationResults.clear(); -- cgit v1.2.3