aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/classes/com/sun/opengl/util/j2d/TextRenderer.java25
-rwxr-xr-xtest/Issue326Test1.java91
-rwxr-xr-xtest/Issue326Test2.java66
3 files changed, 176 insertions, 6 deletions
diff --git a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java
index d11d928a9..dad518ea0 100755
--- a/src/classes/com/sun/opengl/util/j2d/TextRenderer.java
+++ b/src/classes/com/sun/opengl/util/j2d/TextRenderer.java
@@ -850,6 +850,10 @@ public class TextRenderer {
}
TextureRenderer renderer = getBackingStore();
+ // Handles case where NPOT texture is used for backing store
+ TextureCoords wholeImageTexCoords = renderer.getTexture().getImageTexCoords();
+ float xScale = wholeImageTexCoords.right();
+ float yScale = wholeImageTexCoords.bottom();
for (int i = 0; i < inGlyphs.length; i++) {
Rect rect = inGlyphs.textureSourceRect[i];
@@ -864,12 +868,12 @@ public class TextRenderer {
int width = rect.w();
int height = rect.h();
- float tx1 = (float) texturex / (float) renderer.getWidth();
- float ty1 = 1.0f -
- ((float) texturey / (float) renderer.getHeight());
- float tx2 = (float) (texturex + width) / (float) renderer.getWidth();
- float ty2 = 1.0f -
- ((float) (texturey + height) / (float) renderer.getHeight());
+ float tx1 = xScale * (float) texturex / (float) renderer.getWidth();
+ float ty1 = yScale * (1.0f -
+ ((float) texturey / (float) renderer.getHeight()));
+ float tx2 = xScale * (float) (texturex + width) / (float) renderer.getWidth();
+ float ty2 = yScale * (1.0f -
+ ((float) (texturey + height) / (float) renderer.getHeight()));
mPipelinedQuadRenderer.glTexCoord2f(tx1, ty1);
mPipelinedQuadRenderer.glVertex3f(x, y, z);
@@ -1571,6 +1575,11 @@ public class TextRenderer {
GlyphsList puntToRobust(CharSequence inString) {
glyphsOutput.nextState = DrawingState.robust;
glyphsOutput.remaining = inString;
+ // Reset the glyph uploader
+ glyphsToUpload.numberOfNewGlyphs = 0;
+ // Reset the glyph list
+ glyphsOutput.length = 0;
+ glyphsOutput.totalAdvance = 0;
return glyphsOutput;
}
@@ -1620,6 +1629,10 @@ public class TextRenderer {
GlyphVector gv = font.createGlyphVector(fontRenderContext,
singleUnicode); // need this to get single bitmaps
glyphID = gv.getGlyphCode(0);
+ // Have seen huge glyph codes (65536) coming out of some fonts in some Unicode situations
+ if (glyphID >= advances.length) {
+ return puntToRobust(inString);
+ }
advance = metrics.getAdvance();
advances[glyphID] = advance;
diff --git a/test/Issue326Test1.java b/test/Issue326Test1.java
new file mode 100755
index 000000000..42b6ec0c7
--- /dev/null
+++ b/test/Issue326Test1.java
@@ -0,0 +1,91 @@
+import java.awt.Frame;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.Random;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLCanvas;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.glu.GLU;
+
+import com.sun.opengl.util.Animator;
+import com.sun.opengl.util.j2d.TextRenderer;
+
+/**
+ * Demonstrates corruption with older versions of TextRenderer. Two
+ * problems: errors when punting from glyph-based renderer to
+ * string-by-string renderer, and failure of glyph-based renderer when
+ * backing store was NPOT using GL_ARB_texture_rectangle.
+ *
+ * @author emzic
+ */
+
+public class Issue326Test1 extends Frame implements GLEventListener {
+
+ int width, height;
+
+ public static void main(String[] args) {
+ new Issue326Test1();
+ }
+
+ GLCanvas canvas;
+ TextRenderer tr ;
+
+ public Issue326Test1() {
+ super("TextTest");
+ this.setSize(800, 800);
+ canvas = new GLCanvas();
+ canvas.addGLEventListener(this);
+ add(canvas);
+
+ setVisible(true);
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ GL gl = drawable.getGL();
+ gl.glClearColor(0, 0, 0, 0);
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT);
+
+
+ gl.glMatrixMode(GL.GL_PROJECTION);
+ gl.glLoadIdentity();
+ //new GLU().gluPerspective(45f, (float)width/(float)height, 0.1f, 1000f);
+ gl.glOrtho(0.0, 800, 0.0, 800, -100.0, 100.0);
+ gl.glMatrixMode(GL.GL_MODELVIEW);
+ gl.glLoadIdentity();
+
+ tr.beginRendering(800,800);
+ tr.draw( "die Marktwirtschaft. Da regelt sich � angeblich", 16, 32);
+ tr.draw( "Hello World! This text is scrambled", 16, 16);
+ tr.endRendering();
+
+ }
+
+ public void init(GLAutoDrawable arg0) {
+ tr = new TextRenderer(new java.awt.Font("Verdana", java.awt.Font.PLAIN, 12), true, false, null, false);
+ tr.setColor(1, 1, 1 ,1);
+ }
+
+ public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
+ width = arg3;
+ height = arg4;
+ GL gl = arg0.getGL();
+ gl.glViewport(0, 0, width, height);
+ gl.glMatrixMode(GL.GL_PROJECTION);
+ gl.glLoadIdentity();
+ gl.glOrtho(0.0, 800, 0.0, 200, -100.0, 100.0);
+ gl.glMatrixMode(GL.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ }
+ public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {}
+}
diff --git a/test/Issue326Test2.java b/test/Issue326Test2.java
new file mode 100755
index 000000000..f2258c858
--- /dev/null
+++ b/test/Issue326Test2.java
@@ -0,0 +1,66 @@
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.event.*;
+import javax.media.opengl.*;
+import com.sun.opengl.util.j2d.*;
+
+/**
+ * Another test case demonstrating corruption with older version of
+ * TextRenderer when glyphs were too big for backing store. Font and
+ * text courtesy of Patrick Murris. Adapted from Issue326Test1.
+ */
+
+public class Issue326Test2 extends Frame implements GLEventListener {
+
+ int width, height;
+
+ public static void main(String[] args) {
+ new Issue326Test2();
+ }
+
+ GLCanvas canvas;
+ TextRenderer tr;
+
+ public Issue326Test2() {
+ super("");
+ this.setSize(800, 800);
+ canvas = new GLCanvas();
+ canvas.addGLEventListener(this);
+ add(canvas);
+
+ setVisible(true);
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ GL gl = drawable.getGL();
+ gl.glClearColor(0, 0, 0, 0);
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT);
+
+ tr.beginRendering(drawable.getWidth(), drawable.getHeight());
+ tr.draw("LA CLAPI\u00c8RE \nAlt: 1100-1700m \nGlissement de terrain majeur", 16, 80);
+ tr.draw("dans la haute Tin\u00e9e, sur un flanc du Parc du Mercantour.", 16, 16);
+ tr.endRendering();
+
+ }
+
+ public void init(GLAutoDrawable arg0) {
+ tr = new TextRenderer(Font.decode("Arial-BOLD-64"));
+ tr.setColor(1, 1, 1 ,1);
+ }
+
+ public void reshape(GLAutoDrawable arg0, int x, int y, int w, int h) {
+ GL gl = arg0.getGL();
+ gl.glMatrixMode(GL.GL_PROJECTION);
+ gl.glLoadIdentity();
+ gl.glOrtho(0.0, w, 0.0, h, -1, 1);
+ gl.glMatrixMode(GL.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ }
+ public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {}
+}
+