From cf39815ab165607c698a3a2e11be357ebb786876 Mon Sep 17 00:00:00 2001 From: benfry Date: Sat, 16 Apr 2005 02:24:19 +0000 Subject: [PATCH] implemented createFont, and changed objectXYZ to modelXYZ --- core/PApplet.java | 79 ++++++++++++++++++++++++++++++++++++++++---- core/PFont.java | 2 +- core/PGraphics.java | 12 +++---- core/PGraphics3.java | 6 ++-- core/todo.txt | 25 +++++++++----- todo.txt | 10 +++--- 6 files changed, 104 insertions(+), 30 deletions(-) diff --git a/core/PApplet.java b/core/PApplet.java index 6c55990bf..7ea933fca 100644 --- a/core/PApplet.java +++ b/core/PApplet.java @@ -2609,6 +2609,73 @@ public class PApplet extends Applet } + public PFont createFont(String name, float size) { + return createFont(name, size, PFont.DEFAULT_CHARSET, true); + } + + + public PFont createFont(String name, float size, char charset[]) { + return createFont(name, size, charset, true); + } + + + public PFont createFont(String name, float size, boolean smooth) { + return createFont(name, size, PFont.DEFAULT_CHARSET, smooth); + } + + + /** + * Create a .vlw font on the fly from either a font name that's + * 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. + */ + public PFont createFont(String name, float size, + char charset[], boolean smooth) { + if (PApplet.javaVersion < 1.3f) { + throw new RuntimeException("Can only create fonts with " + + "Java 1.3 or higher"); + } + + String lowerName = name.toLowerCase(); + Font font = null; + + try { + Method deriveFontMethod = + Font.class.getMethod("deriveFont", + new Class[] { Float.TYPE }); + Float floatSize = new Float(size); + + if (lowerName.endsWith(".otf") || lowerName.endsWith(".ttf")) { + //font = Font.createFont(Font.TRUETYPE_FONT, openStream(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 { + Font baseFont = new Font(name, Font.PLAIN, 1); + font = (Font) + deriveFontMethod.invoke(font, new Object[] { floatSize }); + } + + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Problem using createFont() " + + "with the file " + name); + } + return new PFont(font, charset, smooth); + } + + ////////////////////////////////////////////////////////////// @@ -5845,18 +5912,18 @@ v PApplet.this.stop(); } - public float objectX(float x, float y, float z) { - return g.objectX(x, y, z); + public float modelX(float x, float y, float z) { + return g.modelX(x, y, z); } - public float objectY(float x, float y, float z) { - return g.objectY(x, y, z); + public float modelY(float x, float y, float z) { + return g.modelY(x, y, z); } - public float objectZ(float x, float y, float z) { - return g.objectZ(x, y, z); + public float modelZ(float x, float y, float z) { + return g.modelZ(x, y, z); } diff --git a/core/PFont.java b/core/PFont.java index ce825fffd..7ddbefe0d 100644 --- a/core/PFont.java +++ b/core/PFont.java @@ -764,7 +764,7 @@ public class PFont implements PConstants { * @param smooth true to enable smoothing/anti-aliasing */ public PFont(Font font, char charset[], boolean smooth) { - if (PApplet.javaVersion < 1.3) { + if (PApplet.javaVersion < 1.3f) { throw new RuntimeException("Can only create fonts with " + "Java 1.3 or higher"); } diff --git a/core/PGraphics.java b/core/PGraphics.java index f40958f83..cea8b7445 100644 --- a/core/PGraphics.java +++ b/core/PGraphics.java @@ -2130,18 +2130,18 @@ public class PGraphics extends PImage implements PConstants { return 0; } - public float objectX(float x, float y, float z) { - depthErrorXYZ("objectX"); + public float modelX(float x, float y, float z) { + depthErrorXYZ("modelX"); return 0; } - public float objectY(float x, float y, float z) { - depthErrorXYZ("objectY"); + public float modelY(float x, float y, float z) { + depthErrorXYZ("modelY"); return 0; } - public float objectZ(float x, float y, float z) { - depthErrorXYZ("objectZ"); + public float modelZ(float x, float y, float z) { + depthErrorXYZ("modelZ"); return 0; } diff --git a/core/PGraphics3.java b/core/PGraphics3.java index d81077a0f..ff68aab80 100644 --- a/core/PGraphics3.java +++ b/core/PGraphics3.java @@ -2716,21 +2716,21 @@ public class PGraphics3 extends PGraphics { } - public float objectX(float x, float y, float z) { + public float modelX(float x, float y, float z) { float ax = modelview.m00*x + modelview.m01*y + modelview.m02*z + modelview.m03; float aw = modelview.m30*x + modelview.m31*y + modelview.m32*z + modelview.m33; return (aw != 0) ? ax / aw : ax; } - public float objectY(float x, float y, float z) { + public float modelY(float x, float y, float z) { float ay = modelview.m10*x + modelview.m11*y + modelview.m12*z + modelview.m13; float aw = modelview.m30*x + modelview.m31*y + modelview.m32*z + modelview.m33; return (aw != 0) ? ay / aw : ay; } - public float objectZ(float x, float y, float z) { + public float modelZ(float x, float y, float z) { float az = modelview.m20*x + modelview.m21*y + modelview.m22*z + modelview.m23; float aw = modelview.m30*x + modelview.m31*y + modelview.m32*z + modelview.m33; return (aw != 0) ? az / aw : az; diff --git a/core/todo.txt b/core/todo.txt index 5d774de23..edc056b3a 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -102,8 +102,6 @@ o can this be auto-detected with noDepth()? o how does rotated text work? o PFont.rotate(180) rotate(PI) o or can this be detected from the matrix? -o PFont.list() to return string list of all the available fonts -X probably not a mode of use that we really want to encourage X don't use pixels to do screen space text inside PFont X add a function in PGraphics for direct pixel image impl X store the font name in the vlw font file (at the end) @@ -112,13 +110,22 @@ X get text impl stuff working properly o look into fixing the texture mapping to not squash fonts o NEW_GRAPHICS totally smashes everything -_ implement createFont() -_ with a .ttf does a create font internally (1.3+ only) -_ although the images aren't populated -_ until a P2D/P3D/OPENGL tries to draw them, which triggers it -_ but if PGraphics2, just uses the built-in font -_ also works for font names and just creating them -_ if font name doesn't end with otf or ttf, then tries to create it +friday postgame +X implement createFont() +X with a .ttf does a create font internally (1.3+ only) +X although the images aren't populated +X until a P2D/P3D/OPENGL tries to draw them, which triggers it +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 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 + +_ implement printarr() as println() ? _ rename video.Camera to video.Video ? _ VideoInput VideoOutput, SoundInput, SoundOutput or AudioInput/AudioOutput diff --git a/todo.txt b/todo.txt index 3a93d89f2..18b84f0a3 100644 --- a/todo.txt +++ b/todo.txt @@ -25,11 +25,6 @@ _ update linux build and shell scripts for new package _ make a linux version _ need to fix up the make/dist scripts for linux -_ if in full java mode -_ if extends PApplet.. or rather, put PApplet cast into a -_ try/catch block.. if it doesn't work, try applet. if that -_ doesn't work, try using the class' main() to run it - fixed in 82 X border weirdness in PdeEditor panels on windows @@ -98,6 +93,11 @@ saving a project over an already existing project does not get rid of the .pde f NOT NECESSARY BEFORE BETA +_ if in full java mode +_ if extends PApplet.. or rather, put PApplet cast into a +_ try/catch block.. if it doesn't work, try applet. if that +_ doesn't work, try using the class' main() to run it + _ println() can hose the app for the first 20-30 frames _ need to figure out threading etc