From f426aa04121df1e28b1d7e8c31ca69b4e781dea0 Mon Sep 17 00:00:00 2001 From: benfry Date: Mon, 13 Jun 2005 18:54:29 +0000 Subject: [PATCH] completing implementation of native font smoothing and new field in .vlw file to support it --- core/PFont.java | 22 +++++++++++++++++----- core/PGraphics2.java | 22 ++++++++++++++++++++++ core/todo.txt | 8 ++++---- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/core/PFont.java b/core/PFont.java index b3a7dd8b8..6117ec8af 100644 --- a/core/PFont.java +++ b/core/PFont.java @@ -78,6 +78,9 @@ public class PFont implements PConstants { /** "natural" size of the font (most often 48) */ public int size; + /** true if smoothing was enabled for this font, used for native impl */ + public boolean smooth; + /** next power of 2 over the max image size (usually 64) */ public int mbox2; @@ -239,6 +242,9 @@ public class PFont implements PConstants { font = null; } } + if (version == 11) { + smooth = is.readBoolean(); + } } @@ -256,8 +262,13 @@ public class PFont implements PConstants { os.writeInt(charCount); + if ((name == null) || (psname == null)) { + name = ""; + psname = ""; + } // formerly numBits, now used for version number - os.writeInt((name != null) ? 10 : 8); + //os.writeInt((name != null) ? 11 : 8); + os.writeInt(11); os.writeInt(size); // formerly mboxX (was 64, now 48) os.writeInt(mbox2); // formerly mboxY (was 64, still 64) @@ -282,10 +293,11 @@ public class PFont implements PConstants { } } - if (name != null) { // version 10 - os.writeUTF(name); - os.writeUTF(psname); - } + //if (name != null) { // version 11 + os.writeUTF(name); + os.writeUTF(psname); + os.writeBoolean(smooth); + //} os.flush(); } diff --git a/core/PGraphics2.java b/core/PGraphics2.java index 36c288cfe..6b8a6a4f7 100644 --- a/core/PGraphics2.java +++ b/core/PGraphics2.java @@ -685,6 +685,8 @@ public class PGraphics2 extends PGraphics { } textFontNative = textFontNative.deriveFont(size); g2.setFont(textFontNative); + + // get the metrics info textFontNativeMetrics = g2.getFontMetrics(textFontNative); } @@ -704,9 +706,29 @@ public class PGraphics2 extends PGraphics { super.textLinePlacedImpl(buffer, start, stop, x, y); return; } + + // check to see if this font wants to be smoothed but smoothing + // is currently shut off for the graphics context overall + boolean savedSmooth = smooth; + if (textFont.smooth != savedSmooth) { + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + textFont.smooth ? + RenderingHints.VALUE_ANTIALIAS_ON : + RenderingHints.VALUE_ANTIALIAS_OFF); + } + g2.setColor(fillColorObject); // better to use drawString(float, float)? g2.drawChars(buffer, start, stop, (int) (x + 0.5f), (int) (y + 0.5f)); + + // return to previous smoothing state if it was changed + if (textFont.smooth != savedSmooth) { + if (savedSmooth) { + smooth(); + } else { + noSmooth(); + } + } } diff --git a/core/todo.txt b/core/todo.txt index abcf53b83..d9259e815 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -27,10 +27,9 @@ X in java2d, can quickly blit the image itself X this way, can isolate it for gl too, which will use glBitmap X danger of this setup is that it may run much nicer for the author X i.e. with the font installed, and then super slow for their users - -_ add "smooth" as a field inside the font file -_ and when smooth field is set, make sure JAVA2D enables smoothing -_ since otherwise smooth() has to be called for the whole g2 +X add "smooth" as a field inside the font file +X and when smooth field is set, make sure JAVA2D enables smoothing +X since otherwise smooth() has to be called for the whole g2 _ how to deal with triangles/lines and triangleCount and lineCount _ maybe just need a triangleImpl and lineImpl @@ -62,6 +61,7 @@ _ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action _ P3D not doing bilinear interpolation in text and images _ because smooth() has to be set (and smooth throws an error in P3D) _ how should this be handled? a hint? allowing smooth()? +_ probably just allow smooth() but don't smooth anything