Bug 866 : bad text character spacing when using createFont (native fonts)
Last modified: 2009-09-07 14:22




Status:
ASSIGNED
Resolution:
-
Priority:
P4
Severity:
normal

 

Reporter:
fjen
Assigned To:
fry

Attachment Type Created Size Actions
example application/zip 2008-08-05 11:50 9.72 KB
Fix 866... the Wordle Way patch 2009-09-05 10:55 974 bytes
More succinct patch patch 2009-09-05 20:03 887 bytes

Description:   Opened: 2008-08-05 11:49
text lines seem not to rotate correctly (rounding error?) when the current font is created with
createFont.
Additional Comment #1 From fjen 2008-08-05 11:50
edit]
example
Additional Comment #2 From fry 2008-08-06 12:44
That's pretty ugly, though I'm not sure if there's much we can do about it.
I looked into setting the Java2D RenderingHint to enable fractional
metrics, but that didn't help. Nor did switching to drawGlyphVector() or
drawString() instead of drawChars().
Additional Comment #3 From MrFeinberg 2009-09-05 10:53
### Eclipse Workspace Patch 1.0
#P processing-head
Index: core/src/processing/core/PGraphicsJava2D.java
============================================================
=======
--- core/src/processing/core/PGraphicsJava2D.java (revision 5676)
+++ core/src/processing/core/PGraphicsJava2D.java (working copy)
@@ -1111,7 +1111,18 @@

g2.setColor(fillColorObject);
int length = stop - start;
- g2.drawChars(buffer, start, length, (int) (x + 0.5f), (int) (y + 0.5f));
+
+ // Silly rabbit! ints are for kids.
+ // g2.drawChars(buffer, start, length, (int) (x + 0.5f), (int) (y + 0.5f));
+ // jdf sez:
+ g2.translate(x,y);
+ try {
+ g2.fill(font.createGlyphVector(g2.getFontRenderContext(), new
String(buffer,start,length)).getOutline());
+ } finally {
+ g2.translate(-x, -y);
+ }
+
+
// better to use drawString() with floats? (nope, draws the same)
//g2.drawString(new String(buffer, start, length), x, y);

Additional Comment #4 From MrFeinberg 2009-09-05 10:55
edit]
Fix 866... the Wordle Way

The pasted patch lost all its formatting, so here's the real deal, Neil.
Additional Comment #5 From fry 2009-09-05 18:59
how expensive is:

g2.fill(font.createGlyphVector(g2.getFontRenderContext(), new
String(buffer,start,length)).getOutline());

for computation time / temp object creation etc? (i'd been avoiding using
these Java 2D methods because they tend to be accurate but slow as all hell)
Additional Comment #6 From MrFeinberg 2009-09-05 20:03
edit]
More succinct patch

I guess one line is better than six.
Additional Comment #7 From MrFeinberg 2009-09-06 17:48
Ugh, you're right; it's way too slow. The Sun graphics stuff has completely different
pipelines for drawing text.
Additional Comment #8 From fry 2009-09-07 14:22
bummer.. hopefully we can find something that works w/o having to go too
far into the Java 2D mess.
This bug is now being tracked here.