mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
completing implementation of native font smoothing and new field in .vlw
file to support it
This commit is contained in:
+17
-5
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+4
-4
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user