complete OBJECT/MODEL, and PFont.list()

This commit is contained in:
benfry
2005-04-16 02:46:56 +00:00
parent 9d904c601d
commit 6a7c53285f
3 changed files with 44 additions and 7 deletions
+39 -1
View File
@@ -411,7 +411,7 @@ public class PFont implements PConstants {
int glyph = index(c);
if (glyph == -1) return;
if (parent.textMode == OBJECT) {
if (parent.textMode == MODEL) {
float high = (float) height[glyph] / fheight;
float bwidth = (float) width[glyph] / fwidth;
float lextent = (float) leftExtent[glyph] / fwidth;
@@ -1041,4 +1041,42 @@ public class PFont implements PConstants {
throw new RuntimeException(e.getMessage());
}
}
/**
* Get a list of the fonts installed on the system.
* <P>
* Not recommended for use in applets, but this is implemented
* in PFont because the Java methods to access this information
* have changed between 1.1 and 1.4, and the 1.4 method is
* typical of the sort of undergraduate-level over-abstraction
* that the seems to have made its way into the Java API after 1.1.
*/
static public String[] list() {
if (PApplet.javaVersion < 1.3f) {
return Toolkit.getDefaultToolkit().getFontList();
}
// getFontList is deprecated in 1.4, so this has to be used
try {
//GraphicsEnvironment ge =
// GraphicsEnvironment.getLocalGraphicsEnvironment();
Class geClass = Class.forName("java.awt.GraphicsEnvironment");
Method glgeMethod =
geClass.getMethod("getLocalGraphicsEnvironment", null);
Object ge = glgeMethod.invoke(null, null);
Method gafMethod = geClass.getMethod("getAllFonts", null);
Font fonts[] = (Font[]) gafMethod.invoke(ge, null); //ge.getAllFonts();
String list[] = new String[fonts.length];
for (int i = 0; i < list.length; i++) {
list[i] = fonts[i].getName();
}
return list;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Error inside PFont.list()");
}
}
}
+2 -2
View File
@@ -441,7 +441,7 @@ public class PGraphics extends PImage implements PConstants {
textSize = 12;
textLeading = 14;
textAlign = LEFT;
textMode = OBJECT;
textMode = MODEL;
}
@@ -1752,7 +1752,7 @@ public class PGraphics extends PImage implements PConstants {
PImage glyph = textFont.images[index];
if (textMode == OBJECT) {
if (textMode == MODEL) {
float high = (float) textFont.height[index] / textFont.fheight;
float bwidth = (float) textFont.width[index] / textFont.fwidth;
float lextent = (float) textFont.leftExtent[index] / textFont.fwidth;
+3 -4
View File
@@ -119,11 +119,10 @@ X but if PGraphics2, just uses the built-in font
X also works for font names and just creating them
X if font name doesn't end with otf or ttf, then tries to create it
X change objectX/Y/Z to modelX/Y/Z
_ PFont.list() to return string list of all the available fonts
X PFont.list() to return string list of all the available fonts
X probably not a mode of use that we really want to encourage
_ actually important because the whole graphicsdevice crap is silly
_ and we need a 1.1 versus 1.3/1.4 version
X actually important because the whole graphicsdevice crap is silly
X and we need a 1.1 versus 1.3/1.4 version
_ implement printarr() as println() ?