From 662fec53e6fa364db913666ced3c2cdb0e5127e7 Mon Sep 17 00:00:00 2001 From: benfry Date: Sun, 2 Sep 2012 20:07:26 +0000 Subject: [PATCH] moving font cache inside PGraphicsOpenGL --- android/core/src/processing/core/PApplet.java | 6 +- android/core/src/processing/core/PFont.java | 62 +++++++++---------- .../processing/core/PGraphicsAndroid2D.java | 8 +-- android/core/src/processing/core/PImage.java | 24 +++---- .../{PFontTexture.java => FontTexture.java} | 4 +- .../processing/opengl/PGraphicsOpenGL.java | 42 ++++++++++--- android/todo.txt | 2 + core/src/processing/core/PApplet.java | 10 +-- core/src/processing/core/PFont.java | 54 +++------------- core/src/processing/core/PGraphics.java | 2 +- core/src/processing/core/PGraphicsJava2D.java | 16 ++--- core/src/processing/core/PImage.java | 5 +- .../{PFontTexture.java => FontTexture.java} | 4 +- .../processing/opengl/PGraphicsOpenGL.java | 38 +++++++++--- core/todo.txt | 21 +++++-- .../pdf/src/processing/pdf/PGraphicsPDF.java | 2 +- 16 files changed, 157 insertions(+), 143 deletions(-) rename android/core/src/processing/opengl/{PFontTexture.java => FontTexture.java} (99%) rename core/src/processing/opengl/{PFontTexture.java => FontTexture.java} (99%) diff --git a/android/core/src/processing/core/PApplet.java b/android/core/src/processing/core/PApplet.java index a4ec0866e..d4a7d3cac 100644 --- a/android/core/src/processing/core/PApplet.java +++ b/android/core/src/processing/core/PApplet.java @@ -3848,7 +3848,7 @@ public class PApplet extends Activity implements PConstants, Runnable { AssetManager assets = getBaseContext().getAssets(); baseFont = Typeface.createFromAsset(assets, name); } else { - baseFont = PFont.findTypeface(name); + baseFont = (Typeface) PFont.findNative(name); } return new PFont(baseFont, round(size), smooth, charset); } @@ -8976,8 +8976,8 @@ public class PApplet extends Activity implements PConstants, Runnable { } - public Bitmap getBitmap() { - return g.getBitmap(); + public Object getNative() { + return g.getNative(); } diff --git a/android/core/src/processing/core/PFont.java b/android/core/src/processing/core/PFont.java index 0b54778b5..df263f683 100644 --- a/android/core/src/processing/core/PFont.java +++ b/android/core/src/processing/core/PFont.java @@ -118,10 +118,10 @@ public class PFont implements PConstants { /** * True if this font should return 'null' for getFont(), so that the native * font will be used to create a subset, but the native version of the font - * will not be used. + * will not be used. */ - protected boolean subsetting; - + protected boolean subsetting; + /** * True if we've already tried to find the native version of this font. */ @@ -133,18 +133,18 @@ public class PFont implements PConstants { * bug that they can't be bothered to fix. */ static protected Typeface[] typefaces; - + // objects to handle creation of font characters only as they're needed Bitmap lazyBitmap; Canvas lazyCanvas; Paint lazyPaint; // FontMetrics lazyMetrics; int[] lazySamples; - + /** for subclasses that need to store metadata about the font */ - protected HashMap cacheMap; - - + protected HashMap cacheMap; + + public PFont() { } // for subclasses @@ -212,7 +212,7 @@ public class PFont implements PConstants { if (charset == null) { lazy = true; - + } else { // charset needs to be sorted to make index lookup run more quickly // http://dev.processing.org/bugs/show_bug.cgi?id=494 @@ -317,7 +317,7 @@ public class PFont implements PConstants { } } - + /** * Write this PFont to an OutputStream. *

@@ -408,20 +408,20 @@ public class PFont implements PConstants { return name; } - + /** * Return size of this font. */ public int getSize() { return size; } - + public void setSubsetting() { subsetting = true; } - + public String getPostScriptName() { return psname; } @@ -430,15 +430,15 @@ public class PFont implements PConstants { /** * Set the native complement of this font. */ - public void setTypeface(Typeface typeface) { - this.typeface = typeface; + public void setNative(Object typeface) { + this.typeface = (Typeface) typeface; } /** * Return the native Typeface object associated with this PFont (if any). */ - public Typeface getTypeface() { + public Typeface getNative() { if (subsetting) { return null; } @@ -450,7 +450,7 @@ public class PFont implements PConstants { * Attempt to find the native version of this font. * (Public so that it can be used by OpenGL or other renderers.) */ - static public Typeface findTypeface(String name) { + static public Object findNative(String name) { loadTypefaces(); return typefaceMap.get(name); } @@ -564,14 +564,14 @@ public class PFont implements PConstants { ////////////////////////////////////////////////////////////// // METADATA REQUIRED BY THE RENDERERS - + /** * Store data of some kind for a renderer that requires extra metadata of * some kind. Usually this is a renderer-specific representation of the * font data, for instance a custom OpenGL texture for PGraphicsOpenGL2. * @param renderer The PGraphics renderer associated to the font - * @param storage The metadata required by the renderer + * @param storage The metadata required by the renderer */ public void setCache(PGraphics renderer, Object storage) { if (cacheMap == null) cacheMap = new HashMap(); @@ -601,22 +601,22 @@ public class PFont implements PConstants { if (cacheMap != null) { cacheMap.remove(renderer); } - } - - - ////////////////////////////////////////////////////////////// - + } + + + ////////////////////////////////////////////////////////////// + public int getGlyphCount() { return glyphCount; } - + public Glyph getGlyph(int i) { - return glyphs[i]; - } - + return glyphs[i]; + } + ////////////////////////////////////////////////////////////// - + static final char[] EXTRA_CHARS = { 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, @@ -725,7 +725,7 @@ public class PFont implements PConstants { } } - + ///////////////////////////////////////////////////////////// /** @@ -736,7 +736,7 @@ public class PFont implements PConstants { public int value; public int height; public int width; - public int index; + public int index; public int setWidth; public int topExtent; public int leftExtent; diff --git a/android/core/src/processing/core/PGraphicsAndroid2D.java b/android/core/src/processing/core/PGraphicsAndroid2D.java index c2810d72a..d8b63f747 100644 --- a/android/core/src/processing/core/PGraphicsAndroid2D.java +++ b/android/core/src/processing/core/PGraphicsAndroid2D.java @@ -1120,7 +1120,7 @@ public class PGraphicsAndroid2D extends PGraphics { @Override public void textFont(PFont which) { super.textFont(which); - fillPaint.setTypeface(which.getTypeface()); + fillPaint.setTypeface(which.getNative()); } @@ -1151,7 +1151,7 @@ public class PGraphicsAndroid2D extends PGraphics { defaultFontOrDeath("textSize", size); } - Typeface font = textFont.getTypeface(); + Typeface font = textFont.getNative(); if (font != null) { fillPaint.setTextSize(size); } @@ -1184,7 +1184,7 @@ public class PGraphicsAndroid2D extends PGraphics { @Override protected float textWidthImpl(char buffer[], int start, int stop) { // Font font = textFont.getFont(); - Typeface font = textFont.getTypeface(); + Typeface font = textFont.getNative(); if (font == null) { return super.textWidthImpl(buffer, start, stop); } @@ -1217,7 +1217,7 @@ public class PGraphicsAndroid2D extends PGraphics { @Override protected void textLineImpl(char buffer[], int start, int stop, float x, float y) { - Typeface font = textFont.getTypeface(); + Typeface font = textFont.getNative(); if (font == null) { showWarning("Inefficient font rendering: use createFont() with a TTF/OTF instead of loadFont()."); //new Exception().printStackTrace(System.out); diff --git a/android/core/src/processing/core/PImage.java b/android/core/src/processing/core/PImage.java index b89aa698c..71ecf0dd2 100644 --- a/android/core/src/processing/core/PImage.java +++ b/android/core/src/processing/core/PImage.java @@ -168,28 +168,20 @@ public class PImage implements PConstants, Cloneable { * Construct a new PImage from an Android bitmap. The pixels[] array is not * initialized, nor is data copied to it, until loadPixels() is called. */ - public PImage(Bitmap image) { - this.bitmap = image; - this.width = image.getWidth(); - this.height = image.getHeight(); + public PImage(Object nativeObject) { + Bitmap bitmap = (Bitmap) nativeObject; + this.bitmap = bitmap; + this.width = bitmap.getWidth(); + this.height = bitmap.getHeight(); this.pixels = null; - this.format = image.hasAlpha() ? ARGB : RGB; + this.format = bitmap.hasAlpha() ? ARGB : RGB; } /** - * Returns a BufferedImage from this PImage. + * Returns the native Bitmap object for this PImage. */ -// public java.awt.Image getImage() { -// loadPixels(); -// int type = (format == RGB) ? -// BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB; -// BufferedImage image = new BufferedImage(width, height, type); -// WritableRaster wr = image.getRaster(); -// wr.setDataElements(0, 0, width, height, pixels); -// return image; -// } - public Bitmap getBitmap() { + public Object getNative() { return bitmap; } diff --git a/android/core/src/processing/opengl/PFontTexture.java b/android/core/src/processing/opengl/FontTexture.java similarity index 99% rename from android/core/src/processing/opengl/PFontTexture.java rename to android/core/src/processing/opengl/FontTexture.java index a59e4a9e1..df8115fc2 100644 --- a/android/core/src/processing/opengl/PFontTexture.java +++ b/android/core/src/processing/opengl/FontTexture.java @@ -46,7 +46,7 @@ import java.util.HashMap; * over several textures. * @author Andres Colubri */ -class PFontTexture implements PConstants { +class FontTexture implements PConstants { protected PApplet parent; protected PGraphicsOpenGL pg; protected PGL pgl; @@ -65,7 +65,7 @@ class PFontTexture implements PConstants { protected TextureInfo[] glyphTexinfos; protected HashMap texinfoMap; - public PFontTexture(PApplet parent, PFont font, int maxw, int maxh, + public FontTexture(PApplet parent, PFont font, int maxw, int maxh, boolean is3D) { this.parent = parent; this.font = font; diff --git a/android/core/src/processing/opengl/PGraphicsOpenGL.java b/android/core/src/processing/opengl/PGraphicsOpenGL.java index 3ae0d757a..b8795e2dc 100644 --- a/android/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/android/core/src/processing/opengl/PGraphicsOpenGL.java @@ -43,6 +43,10 @@ public class PGraphicsOpenGL extends PGraphics { /** The renderer currently in use. */ protected static PGraphicsOpenGL pgCurrent = null; + /** Font cache for texture objects. */ + protected WeakHashMap fontMap = + new WeakHashMap(); + /** Additional image parameters not covered by the cache. */ protected WeakHashMap paramMap = new WeakHashMap(); @@ -353,7 +357,7 @@ public class PGraphicsOpenGL extends PGraphics { // Text: /** Font texture of currently selected font. */ - PFontTexture textTex; + FontTexture textTex; // ....................................................... @@ -610,6 +614,24 @@ public class PGraphicsOpenGL extends PGraphics { } + ////////////////////////////////////////////////////////////// + + + protected void setFontTexture(PFont font, FontTexture fontTexture) { + fontMap.put(font, fontTexture); + } + + + protected FontTexture getFontTexture(PFont font) { + return fontMap.get(font); + } + + + protected void removeFontTexture(PFont font) { + fontMap.remove(font); + } + + ////////////////////////////////////////////////////////////// /** @@ -1654,8 +1676,8 @@ public class PGraphicsOpenGL extends PGraphics { if (texture != null) { // The screen texture should be deleted because it // corresponds to the old window size. - removeCache(pgPrimary); - removeParams(pgPrimary); + pgPrimary.removeCache(this); + pgPrimary.removeParams(this); texture = null; loadTexture(); } @@ -3507,17 +3529,17 @@ public class PGraphicsOpenGL extends PGraphics { @Override protected void textLineImpl(char buffer[], int start, int stop, float x, float y) { - textTex = (PFontTexture)textFont.getCache(pgPrimary); + textTex = pgPrimary.getFontTexture(textFont); if (textTex == null) { - textTex = new PFontTexture(parent, textFont, maxTextureSize, + textTex = new FontTexture(parent, textFont, maxTextureSize, maxTextureSize, is3D()); - textFont.setCache(pgPrimary, textTex); + pgPrimary.setFontTexture(textFont, textTex); } else { if (textTex.contextIsOutdated()) { - textTex = new PFontTexture(parent, textFont, + textTex = new FontTexture(parent, textFont, PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize), PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize), is3D()); - textFont.setCache(pgPrimary, textTex); + pgPrimary.setFontTexture(textFont, textTex); } } textTex.begin(); @@ -3569,7 +3591,7 @@ public class PGraphicsOpenGL extends PGraphics { PFont.Glyph glyph = textFont.getGlyph(ch); if (glyph != null) { - PFontTexture.TextureInfo tinfo = textTex.getTexInfo(glyph); + FontTexture.TextureInfo tinfo = textTex.getTexInfo(glyph); if (tinfo == null) { // Adding new glyph to the font texture. @@ -3593,7 +3615,7 @@ public class PGraphicsOpenGL extends PGraphics { } - protected void textCharModelImpl(PFontTexture.TextureInfo info, + protected void textCharModelImpl(FontTexture.TextureInfo info, float x0, float y0, float x1, float y1) { if (textTex.currentTex != info.texIndex) { diff --git a/android/todo.txt b/android/todo.txt index 4afb0be68..2619ae18f 100644 --- a/android/todo.txt +++ b/android/todo.txt @@ -1,4 +1,6 @@ 0209 android +A GL android sketch stops running after rotation +A http://code.google.com/p/processing/issues/detail?id=1146 _ inside AndroidPreprocessor diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 44388e1e7..53f8f26e8 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -4911,8 +4911,8 @@ public class PApplet extends Applet } // For jpeg, gif, and png, load them using createImage(), - // because the javax.imageio code was found to be much slower, see - // Bug 392. + // because the javax.imageio code was found to be much slower. + // http://dev.processing.org/bugs/show_bug.cgi?id=392 try { if (extension.equals("jpg") || extension.equals("jpeg") || extension.equals("gif") || extension.equals("png") || @@ -4949,12 +4949,12 @@ public class PApplet extends Applet if (loadImageFormats != null) { for (int i = 0; i < loadImageFormats.length; i++) { if (extension.equals(loadImageFormats[i])) { - PImage image; - image = loadImageIO(filename); + return loadImageIO(filename); +// PImage image = loadImageIO(filename); // if (params != null) { // image.setParams(g, params); // } - return image; +// return image; } } } diff --git a/core/src/processing/core/PFont.java b/core/src/processing/core/PFont.java index fd2dbf182..da55b23b6 100644 --- a/core/src/processing/core/PFont.java +++ b/core/src/processing/core/PFont.java @@ -390,7 +390,7 @@ public class PFont implements PConstants { } // See if there's a native version of this font that can be used, // in case that's of interest later. - findFont(); + findNative(); } @@ -495,15 +495,15 @@ public class PFont implements PConstants { * findFont() function, or externally by a deriveFont() call if the font * is resized by PGraphicsJava2D. */ - public void setFont(Font font) { - this.font = font; + public void setNative(Object font) { + this.font = (Font) font; } /** * Return the native java.awt.Font associated with this PFont (if any). */ - public Font getFont() { + public Object getNative() { if (subsetting) { return null; // don't return the font for use } @@ -533,7 +533,7 @@ public class PFont implements PConstants { * Attempt to find the native version of this font. * (Public so that it can be used by OpenGL or other renderers.) */ - public Font findFont() { + public Object findNative() { if (font == null) { if (!fontSearched) { // this font may or may not be installed @@ -664,57 +664,17 @@ public class PFont implements PConstants { ////////////////////////////////////////////////////////////// - // METADATA REQUIRED BY THE RENDERERS - - - /** - * Store data of some kind for a renderer that requires extra metadata of - * some kind. Usually this is a renderer-specific representation of the - * font data, for instance a custom OpenGL texture for PGraphicsOpenGL2. - * @param renderer The PGraphics renderer associated to the font - * @param storage The metadata required by the renderer - */ - public void setCache(PGraphics renderer, Object storage) { - if (cacheMap == null) cacheMap = new HashMap(); - cacheMap.put(renderer, storage); - } - - - /** - * Get cache storage data for the specified renderer. Because each renderer - * will cache data in different formats, it's necessary to store cache data - * keyed by the renderer object. Otherwise, attempting to draw the same - * image to both a PGraphicsJava2D and a PGraphicsOpenGL2 will cause errors. - * @param renderer The PGraphics renderer associated to the font - * @return metadata stored for the specified renderer - */ - public Object getCache(PGraphics renderer) { - if (cacheMap == null) return null; - return cacheMap.get(renderer); - } - - - /** - * Remove information associated with this renderer from the cache, if any. - * @param parent The PGraphics renderer whose cache data should be removed - */ - public void removeCache(PGraphics renderer) { - if (cacheMap != null) { - cacheMap.remove(renderer); - } - } - - - ////////////////////////////////////////////////////////////// public int getGlyphCount() { return glyphCount; } + public Glyph getGlyph(int i) { return glyphs[i]; } + ////////////////////////////////////////////////////////////// diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index e3324f325..e87f355bc 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -3785,7 +3785,7 @@ public class PGraphics extends PImage implements PConstants { textFont = which; if (hints[ENABLE_NATIVE_FONTS]) { //if (which.font == null) { - which.findFont(); + which.findNative(); //} } /* diff --git a/core/src/processing/core/PGraphicsJava2D.java b/core/src/processing/core/PGraphicsJava2D.java index b46d635b4..45e15d8c0 100644 --- a/core/src/processing/core/PGraphicsJava2D.java +++ b/core/src/processing/core/PGraphicsJava2D.java @@ -1191,7 +1191,7 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { defaultFontOrDeath("textAscent"); } - Font font = textFont.getFont(); + Font font = (Font) textFont.getNative(); //if (font != null && (textFont.isStream() || hints[ENABLE_NATIVE_FONTS])) { if (font != null) { FontMetrics metrics = parent.getFontMetrics(font); @@ -1206,7 +1206,7 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { if (textFont == null) { defaultFontOrDeath("textAscent"); } - Font font = textFont.getFont(); + Font font = (Font) textFont.getNative(); //if (font != null && (textFont.isStream() || hints[ENABLE_NATIVE_FONTS])) { if (font != null) { FontMetrics metrics = parent.getFontMetrics(font); @@ -1252,12 +1252,12 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { // g2.setFont(textFontNative); // textFontNativeMetrics = g2.getFontMetrics(textFontNative); // } - Font font = textFont.getFont(); + Font font = (Font) textFont.getNative(); //if (font != null && (textFont.isStream() || hints[ENABLE_NATIVE_FONTS])) { if (font != null) { Font dfont = font.deriveFont(size); g2.setFont(dfont); - textFont.setFont(dfont); + textFont.setNative(dfont); } // take care of setting the textSize and textLeading vars @@ -1275,7 +1275,7 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { @Override protected float textWidthImpl(char buffer[], int start, int stop) { - Font font = textFont.getFont(); + Font font = (Font) textFont.getNative(); //if (font != null && (textFont.isStream() || hints[ENABLE_NATIVE_FONTS])) { if (font != null) { // maybe should use one of the newer/fancier functions for this? @@ -1328,7 +1328,7 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { @Override protected void textLineImpl(char buffer[], int start, int stop, float x, float y) { - Font font = textFont.getFont(); + Font font = (Font) textFont.getNative(); // if (font != null && (textFont.isStream() || hints[ENABLE_NATIVE_FONTS])) { if (font != null) { /* @@ -2125,7 +2125,9 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { public void copy(PImage src, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh) { - g2.drawImage(src.getImage(), dx, dy, dx + dw, dy + dh, sx, sy, sx + sw, sy + sh, null); + g2.drawImage((Image) src.getNative(), + dx, dy, dx + dw, dy + dh, + sx, sy, sx + sw, sy + sh, null); } diff --git a/core/src/processing/core/PImage.java b/core/src/processing/core/PImage.java index 4e536e7c1..759a3fed1 100644 --- a/core/src/processing/core/PImage.java +++ b/core/src/processing/core/PImage.java @@ -292,9 +292,10 @@ public class PImage implements PConstants, Cloneable { /** - * Returns a BufferedImage from this PImage. + * Returns a native BufferedImage from this PImage. */ - public java.awt.Image getImage() { +// public java.awt.Image getImage() { + public Object getNative() { loadPixels(); int type = (format == RGB) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; diff --git a/core/src/processing/opengl/PFontTexture.java b/core/src/processing/opengl/FontTexture.java similarity index 99% rename from core/src/processing/opengl/PFontTexture.java rename to core/src/processing/opengl/FontTexture.java index a59e4a9e1..df8115fc2 100644 --- a/core/src/processing/opengl/PFontTexture.java +++ b/core/src/processing/opengl/FontTexture.java @@ -46,7 +46,7 @@ import java.util.HashMap; * over several textures. * @author Andres Colubri */ -class PFontTexture implements PConstants { +class FontTexture implements PConstants { protected PApplet parent; protected PGraphicsOpenGL pg; protected PGL pgl; @@ -65,7 +65,7 @@ class PFontTexture implements PConstants { protected TextureInfo[] glyphTexinfos; protected HashMap texinfoMap; - public PFontTexture(PApplet parent, PFont font, int maxw, int maxh, + public FontTexture(PApplet parent, PFont font, int maxw, int maxh, boolean is3D) { this.parent = parent; this.font = font; diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 8731ec8ea..74d49e12e 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -43,6 +43,10 @@ public class PGraphicsOpenGL extends PGraphics { /** The renderer currently in use. */ protected static PGraphicsOpenGL pgCurrent = null; + /** Font cache for texture objects. */ + protected WeakHashMap fontMap = + new WeakHashMap(); + /** Additional image parameters not covered by the cache. */ protected WeakHashMap paramMap = new WeakHashMap(); @@ -353,7 +357,7 @@ public class PGraphicsOpenGL extends PGraphics { // Text: /** Font texture of currently selected font. */ - PFontTexture textTex; + FontTexture textTex; // ....................................................... @@ -610,6 +614,24 @@ public class PGraphicsOpenGL extends PGraphics { } + ////////////////////////////////////////////////////////////// + + + protected void setFontTexture(PFont font, FontTexture fontTexture) { + fontMap.put(font, fontTexture); + } + + + protected FontTexture getFontTexture(PFont font) { + return fontMap.get(font); + } + + + protected void removeFontTexture(PFont font) { + fontMap.remove(font); + } + + ////////////////////////////////////////////////////////////// /** @@ -3508,17 +3530,17 @@ public class PGraphicsOpenGL extends PGraphics { @Override protected void textLineImpl(char buffer[], int start, int stop, float x, float y) { - textTex = (PFontTexture)textFont.getCache(pgPrimary); + textTex = pgPrimary.getFontTexture(textFont); if (textTex == null) { - textTex = new PFontTexture(parent, textFont, maxTextureSize, + textTex = new FontTexture(parent, textFont, maxTextureSize, maxTextureSize, is3D()); - textFont.setCache(pgPrimary, textTex); + pgPrimary.setFontTexture(textFont, textTex); } else { if (textTex.contextIsOutdated()) { - textTex = new PFontTexture(parent, textFont, + textTex = new FontTexture(parent, textFont, PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize), PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize), is3D()); - textFont.setCache(pgPrimary, textTex); + pgPrimary.setFontTexture(textFont, textTex); } } textTex.begin(); @@ -3570,7 +3592,7 @@ public class PGraphicsOpenGL extends PGraphics { PFont.Glyph glyph = textFont.getGlyph(ch); if (glyph != null) { - PFontTexture.TextureInfo tinfo = textTex.getTexInfo(glyph); + FontTexture.TextureInfo tinfo = textTex.getTexInfo(glyph); if (tinfo == null) { // Adding new glyph to the font texture. @@ -3594,7 +3616,7 @@ public class PGraphicsOpenGL extends PGraphics { } - protected void textCharModelImpl(PFontTexture.TextureInfo info, + protected void textCharModelImpl(FontTexture.TextureInfo info, float x0, float y0, float x1, float y1) { if (textTex.currentTex != info.texIndex) { diff --git a/core/todo.txt b/core/todo.txt index 2ccb168dd..526593c51 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -5,6 +5,18 @@ X maybe getResource() fails because spaces are not encoded? X PVector limit() is inefficient X http://code.google.com/p/processing/issues/detail?id=1122 +X work on making API more generic and consistent +X PFont.getFont() changed to PFont.getNative() (returns an Object) +X PFont.getTypeface() changed to PFont.getNative() + +earlier +X add breakShape to the public API -> begin/endContour +x or handle differently in general.. nested beginPath() calls? + + +_ beginning slash in getChild() threw an NPE +_ do we need a trim() method for XML? or enableWhiteSpace()? or? + _ memory leak when many createGraphics(..., JAVA2D) calls are used _ http://code.google.com/p/processing/issues/detail?id=507 _ need to add clear() method so clear out ARGB surfaces @@ -15,6 +27,9 @@ o or background(r, g, b, a) would be the thing _ clear() with a color doesn't make (verbal) sense _ provide a way to clear the PGraphics with plain alpha +_ use getNative() to return the native object for +_ PImage (BufferedImage and Bitmap), PFont (Typeface or awt.Font) + api to be fixed/removed _ remove PImage.delete() and friends from PImage, Movie, etc. _ delete()/dispose() being used in the movie @@ -36,6 +51,7 @@ _ http://code.google.com/p/processing/issues/detail?id=1068 docs _ textureWrap() CLAMP and REPEAT now added +_ begin/endContour() _ implement callbacks for images and other loadXxxx() functions _ remove requestImage() and friends @@ -43,8 +59,6 @@ _ callback for requestImage() _ http://code.google.com/p/processing/issues/detail?id=641 _ remove/update requestImage example -_ do we need a trim() method for XML? or enableWhiteSpace()? or? - PImage icon; void setup() { @@ -266,8 +280,7 @@ _ http://code.google.com/p/processing/issues/detail?id=135 _ make determination on shape(x,y,z,w,h,d) or no _ new PGraphics(... OutputStream) _ http://code.google.com/p/processing/issues/detail?id=246 -_ add breakShape to the public API -_ or handle differently in general.. nested beginPath() calls? +_ already added for PDF, just need to work out the API looping/events _ key and mouse events delivered out of order diff --git a/java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java b/java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java index c2e0dce7e..01b83bd1c 100644 --- a/java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java +++ b/java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java @@ -604,7 +604,7 @@ public class PGraphicsPDF extends PGraphicsJava2D { * @return true if it's ok */ protected void checkFont() { - Font awtFont = textFont.getFont(); + Font awtFont = textFont.getNative(); if (awtFont == null) { // always need a native font or reference to it throw new RuntimeException("Use createFont() instead of loadFont() " + "when drawing text using the PDF library.");