From 6a7c53285fa0035b312fa0dcd785e360bd1a1ed3 Mon Sep 17 00:00:00 2001 From: benfry Date: Sat, 16 Apr 2005 02:46:56 +0000 Subject: [PATCH] complete OBJECT/MODEL, and PFont.list() --- core/PFont.java | 40 +++++++++++++++++++++++++++++++++++++++- core/PGraphics.java | 4 ++-- core/todo.txt | 7 +++---- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/core/PFont.java b/core/PFont.java index 7ddbefe0d..06e5e4b51 100644 --- a/core/PFont.java +++ b/core/PFont.java @@ -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. + *

+ * 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()"); + } + } } diff --git a/core/PGraphics.java b/core/PGraphics.java index cea8b7445..545f6c3f7 100644 --- a/core/PGraphics.java +++ b/core/PGraphics.java @@ -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; diff --git a/core/todo.txt b/core/todo.txt index edc056b3a..66152d365 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -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() ?