diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java
index 54a96f124..365307bc3 100644
--- a/core/src/processing/core/PApplet.java
+++ b/core/src/processing/core/PApplet.java
@@ -4083,8 +4083,8 @@ public class PApplet extends Applet
* installed on the system, or from a .ttf or .otf that's inside
* the data folder of this sketch.
*
- * Only works with Java 1.3 or later. Many .otf fonts don't seem
- * to be supported by Java, perhaps because they're CFF based?
+ * Many .otf fonts don't seem to be supported by Java, perhaps because
+ * they're CFF based?
*
* Font names are inconsistent across platforms and Java versions.
* On Mac OS X, Java 1.3 uses the font menu name of the font,
@@ -4103,8 +4103,9 @@ public class PApplet extends Applet
Font baseFont = null;
try {
+ InputStream stream = null;
if (lowerName.endsWith(".otf") || lowerName.endsWith(".ttf")) {
- InputStream stream = createInput(name);
+ stream = createInput(name);
if (stream == null) {
System.err.println("The font \"" + name + "\" " +
"is missing or inaccessible, make sure " +
@@ -4115,17 +4116,15 @@ public class PApplet extends Applet
baseFont = Font.createFont(Font.TRUETYPE_FONT, createInput(name));
} else {
- //baseFont = new Font(name, Font.PLAIN, 1);
baseFont = PFont.findFont(name);
}
+ return new PFont(baseFont.deriveFont(size), smooth, charset,
+ stream != null);
+
} catch (Exception e) {
- System.err.println("Problem using createFont() with " + name);
+ System.err.println("Problem createFont(" + name + ")");
e.printStackTrace();
- }
- if (charset == null) {
- return new PFont(baseFont.deriveFont(size), smooth);
- } else {
- return new PFont(baseFont.deriveFont(size), smooth, charset);
+ return null;
}
}
diff --git a/core/src/processing/core/PFont.java b/core/src/processing/core/PFont.java
index 3ea666b84..9905f7de0 100644
--- a/core/src/processing/core/PFont.java
+++ b/core/src/processing/core/PFont.java
@@ -27,6 +27,7 @@ import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.util.Arrays;
+import java.util.HashMap;
/**
@@ -115,6 +116,9 @@ public class PFont implements PConstants {
*/
protected Font font;
+ /** True if this font was loaded from a stream, rather than from the OS. */
+ protected boolean stream;
+
/**
* True if we've already tried to find the native AWT version of this font.
*/
@@ -126,6 +130,7 @@ public class PFont implements PConstants {
* bug that they can't be bothered to fix.
*/
static protected Font[] fonts;
+ static protected HashMap fontDifferent;
// objects to handle creation of font characters only as they're needed
@@ -265,7 +270,17 @@ public class PFont implements PConstants {
}
}
}
+
+ /**
+ * Adds an additional parameter that indicates the font came from a file,
+ * not a built-in OS font.
+ */
+ public PFont(Font font, boolean smooth, char charset[], boolean stream) {
+ this(font, smooth, charset);
+ this.stream = stream;
+ }
+
public PFont(InputStream input) throws IOException {
DataInputStream is = new DataInputStream(input);
@@ -437,6 +452,11 @@ public class PFont implements PConstants {
// }
return font;
}
+
+
+ public boolean isStream() {
+ return stream;
+ }
/**
@@ -663,23 +683,35 @@ public class PFont implements PConstants {
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
fonts = ge.getAllFonts();
+ if (PApplet.platform == PConstants.MACOSX) {
+ fontDifferent = new HashMap();
+ for (Font font : fonts) {
+ // getName() returns the PostScript name on OS X 10.6 w/ Java 6.
+ fontDifferent.put(font.getName(), font);
+ //fontDifferent.put(font.getPSName(), font);
+ }
+ }
}
}
- /**
+ /**
* Starting with Java 1.5, Apple broke the ability to specify most fonts.
- * This has been filed as bug #4769141 at bugreporter.apple.com. More info at
+ * This bug was filed years ago as #4769141 at bugreporter.apple.com. More:
* Bug 407.
- */
+ */
static public Font findFont(String name) {
loadFonts();
if (PApplet.platform == PConstants.MACOSX) {
- for (int i = 0; i < fonts.length; i++) {
- if (name.equals(fonts[i].getName())) {
- return fonts[i];
- }
+ Font maybe = fontDifferent.get(name);
+ if (maybe != null) {
+ return maybe;
}
+// for (int i = 0; i < fonts.length; i++) {
+// if (name.equals(fonts[i].getName())) {
+// return fonts[i];
+// }
+// }
}
return new Font(name, Font.PLAIN, 1);
}
diff --git a/core/todo.txt b/core/todo.txt
index 3f53511f5..aa49cd972 100644
--- a/core/todo.txt
+++ b/core/todo.txt
@@ -1,5 +1,8 @@
0179 core
X screenWidth/Height instead of screenW/H
+X open up the pdf library more (philho)
+X http://dev.processing.org/bugs/show_bug.cgi?id=1343
+X cache font information for the PDF library to improve setup time
big ones
@@ -38,6 +41,8 @@ _ consider adding skewX/Y
_ do them as shearX/Y
_ http://dev.processing.org/bugs/show_bug.cgi?id=1448
+_ add setOutput() method across other renderers?
+
_ opengl applet problems
_ http://dev.processing.org/bugs/show_bug.cgi?id=1364
@@ -57,8 +62,6 @@ _ add java.io.Reader (and Writer?) to imports
_ consider bringing back text/image using cache/names
_ fonts might not be as bad
-_ open up the pdf library more (philho)
-_ http://dev.processing.org/bugs/show_bug.cgi?id=1343
_ changing vertex alpha in P3D in a QUAD_STRIP is ignored
_ with smoothing, it works fine, but with PTriangle, it's not
_ smooth() not working with applets an createGraphics(JAVA2D)