fixes for font code, implement matching of font names on osx

This commit is contained in:
benfry
2008-06-24 20:31:30 +00:00
parent 081eec0878
commit a02f86ce2f
3 changed files with 57 additions and 79 deletions
+3 -26
View File
@@ -4069,20 +4069,10 @@ in */
*/
public PFont createFont(String name, float size,
boolean smooth, char charset[]) {
// if (PApplet.javaVersion < 1.3f) {
// throw new RuntimeException("Can only create fonts with " +
// "Java 1.3 or higher");
// }
String lowerName = name.toLowerCase();
Font baseFont = null;
try {
// Method deriveFontMethod =
// Font.class.getMethod("deriveFont",
// new Class[] { Float.TYPE });
// Float floatSize = new Float(size);
if (lowerName.endsWith(".otf") || lowerName.endsWith(".ttf")) {
InputStream stream = createInput(name);
if (stream == null) {
@@ -4092,25 +4082,12 @@ in */
"added to your sketch and is readable.");
return null;
}
baseFont = Font.createFont(Font.TRUETYPE_FONT, createInput(name));
// Method createFontMethod =
// Font.class.getMethod("createFont",
// new Class[] { Integer.TYPE,
// InputStream.class });
// Field ttf = Font.class.getField("TRUETYPE_FONT");
// Integer ttfInteger = new Integer(ttf.getInt(ttf));
// Font baseFont = (Font)
// createFontMethod.invoke(name,
// new Object[] { ttfInteger,
// openStream(name) });
// font = (Font) deriveFontMethod.invoke(baseFont,
// new Object[] { floatSize });
} else {
baseFont = new Font(name, Font.PLAIN, 1);
//baseFont = new Font(name, Font.PLAIN, 1);
baseFont = PFont.findFont(name);
}
//return baseFont.deriveFont(size);
} catch (Exception e) {
System.err.println("Problem using createFont() with " + name);
e.printStackTrace();
+30 -32
View File
@@ -113,6 +113,8 @@ public class PFont implements PConstants {
// shared by the text() functions to avoid incessant allocation of memory
//protected char textBuffer[] = new char[8 * 1024];
//protected char widthBuffer[] = new char[8 * 1024];
static public Font[] fonts;
public PFont() { } // for subclasses
@@ -968,42 +970,38 @@ public class PFont implements PConstants {
* that the seems to have made its way into the Java API after 1.1.
*/
static public String[] list() {
// if (PApplet.javaVersion < 1.3f) {
// // make this reflection too, since compilers complain about the
// // deprecation, and it's bound to stop working in 1.6 or something
// //return Toolkit.getDefaultToolkit().getFontList();
// try {
// Toolkit tk = Toolkit.getDefaultToolkit();
// Method getFontListMethod =
// tk.getClass().getMethod("getFontList", (Class[]) null);
// return (String[]) getFontListMethod.invoke(tk, (Object[]) null);
// } catch (Exception e) {
// e.printStackTrace();
// return new String[] { };
// }
// }
loadFonts();
String list[] = new String[fonts.length];
for (int i = 0; i < list.length; i++) {
list[i] = fonts[i].getName();
}
return list;
}
// getFontList is deprecated in 1.4, so this has to be used
//try {
static public void loadFonts() {
if (fonts == null) {
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
// Class geClass = Class.forName("java.awt.GraphicsEnvironment");
// Method glgeMethod =
// geClass.getMethod("getLocalGraphicsEnvironment", (Class[]) null);
// Object ge = glgeMethod.invoke((Class[]) null, (Object[]) null);
fonts = ge.getAllFonts();
}
}
Font fonts[] = ge.getAllFonts();
// Method gafMethod = geClass.getMethod("getAllFonts", (Class[]) null);
// Font fonts[] = (Font[]) gafMethod.invoke(ge, (Object[]) null);
String list[] = new String[fonts.length];
for (int i = 0; i < list.length; i++) {
list[i] = fonts[i].getName();
/**
* 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 information at <a href="http://dev.processing.org/bugs/show_bug.cgi?id=407">Bug 407</a>
*/
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];
}
}
return list;
// } catch (Exception e) {
// e.printStackTrace();
// throw new RuntimeException("Error inside PFont.list()");
// }
}
return new Font(name, Font.PLAIN, 1);
}
}
+24 -21
View File
@@ -1,5 +1,23 @@
0143 core
X some fonts broken in java 1.5 on osx have changed again
X http://dev.processing.org/bugs/show_bug.cgi?id=407
X filed as bug #4769141 with apple http://bugreport.apple.com/
X appears that asking for the postscript name no longer works
o fix "create font" and associated font stuff to straighten it out
X was grabbing the wrong native font with ico sketch
X seems that the psname is no longer a good way to grab the font? related?
X available font issues
X is getFontList returning a different set of fonts from device2d?
X try it out on java 1.3 versus 1.4
X getAllFonts() not quite working for many fonts
X i.e. Orator Std on windows.. macosx seems to be ok
X is getFamilyNames() any different/better?
X when did this break? 1.4.1? 1.4.x vs 1.3?
X may be that cff fonts won't work?
X or is it only those with ps names?
X http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1117445969
o leading looks too big, at least in PGraphics2 with news gothic
X though prolly the converted version of the .ttf?
_ option to have renderer errors show up
_ 1) as text warnings 2) as runtime exceptions 3) never
@@ -63,6 +81,11 @@ _ in fact, this maybe should be a library that does it
_ so that the file size can be much smaller
_ remove saveFile() methods?
_ ENABLE_DEPTH_SORT no really working for GL
_ because the zbuffer is still there, it's still calculating
_ actually, this is probably because it happens after the frame
_ so really, flush is required whenever the depth sort is called
_ ENABLE_DEPTH_SORT causing trouble with MovieMaker
_ need to make the flush() api accessible
_ http://dev.processing.org/bugs/show_bug.cgi?id=692
@@ -425,26 +448,6 @@ _ http://dev.processing.org/bugs/show_bug.cgi?id=531
CORE / PFont and text()
_ some fonts broken in java 1.5 on osx have changed again
_ http://dev.processing.org/bugs/show_bug.cgi?id=407
_ filed as bug #4769141 with apple
_ http://bugreport.apple.com/
_ appears that asking for the postscript name no longer works
o fix "create font" and associated font stuff to straighten it out
X was grabbing the wrong native font with ico sketch
X seems that the psname is no longer a good way to grab the font? related?
_ available font issues
_ is getFontList returning a different set of fonts from device2d?
_ try it out on java 1.3 versus 1.4
_ getAllFonts() not quite working for many fonts
_ i.e. Orator Std on windows.. macosx seems to be ok
_ is getFamilyNames() any different/better?
_ when did this break? 1.4.1? 1.4.x vs 1.3?
_ may be that cff fonts won't work?
_ or is it only those with ps names?
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1117445969
_ leading looks too big, at least in PGraphics2 with news gothic
_ though it may be the converted version of the .ttf?
_ font encoding issues
_ java seems to force straight windows encoding.. (problem for pi fonts)
_ opentype/cff fonts don't work with live loading from the app