Revision: 3141
http://vexi.svn.sourceforge.net/vexi/?rev=3141&view=rev
Author: mkpg2
Date: 2008-10-26 07:54:30 +0000 (Sun, 26 Oct 2008)
Log Message:
-----------
Fix. Font caching was broken.
Modified Paths:
--------------
trunk/core/org.vexi.core/src/org/vexi/graphics/Font.java
Modified: trunk/core/org.vexi.core/src/org/vexi/graphics/Font.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/graphics/Font.java 2008-10-26
02:17:26 UTC (rev 3140)
+++ trunk/core/org.vexi.core/src/org/vexi/graphics/Font.java 2008-10-26
07:54:30 UTC (rev 3141)
@@ -6,8 +6,8 @@
import java.io.IOException;
import java.io.InputStream;
-import java.util.LinkedList;
-import java.util.WeakHashMap;
+import java.lang.ref.WeakReference;
+import java.util.*;
import org.ibex.js.JS;
import org.ibex.js.JSU;
@@ -23,11 +23,11 @@
/** encapsulates a single font (a set of Glyphs) */
public class Font {
- private Font(JS stream, int pointsize) { this.stream = stream;
this.pointsize = pointsize; }
+ private Font(JS stream, int pointsize) { this.stream = stream;
this.pointsize = new Integer(pointsize); }
private static boolean glyphRenderingTaskIsScheduled = false;
- public final int pointsize; ///< the size of the font
+ public final Integer pointsize; ///< the size of the font
public final JS stream; ///< the stream from which
this font was loaded
public int max_ascent; ///< the maximum ascent, in
pixels
public int max_descent; ///< the maximum descent, in
pixels
@@ -57,14 +57,26 @@
// REMARK - Basket.Array is an inefficient queue(see dequeue). Using
java.util
static final LinkedList glyphsToBeCached = new LinkedList();
// FIXME - have this as a priority task
- //static final Queue glyphsToBeDisplayed = new LinkedList();
- private static WeakHashMap fonts = new WeakHashMap();
+ static final Queue glyphsToBeDisplayed = new LinkedList();
+
+ // REMARK - to keep things simple we have the weak reference
+ // only in one place, pointing to the font. We can guarantee
+ // that this won't get collected if we still refer to the font
+ // somewhere.
+ private static Map fonts = new HashMap(); // new WeakHashMap();
public static Font getFont(JS stream, int pointsize) {
- WeakHashMap m = (WeakHashMap)fonts.get(stream);
+
+ Map m = (Map)fonts.get(stream);
Font ret = null;
- if (m != null) ret = (Font)m.get(new Integer(pointsize));
- else fonts.put(stream, m = new WeakHashMap());
- if (ret == null) m.put(new Integer(pointsize), ret = new Font(stream,
pointsize));
+ if (m != null){
+ WeakReference wr = (WeakReference)m.get(new Integer(pointsize));
+ if(wr!=null) ret = (Font)wr.get();
+ }
+ else fonts.put(stream, m = new HashMap());
+ if (ret == null){
+ ret = new Font(stream, pointsize);
+ m.put(ret.pointsize, new WeakReference(ret));
+ }
return ret;
}
@@ -176,11 +188,14 @@
private synchronized void renderGlyph(Font.Glyph glyph) throws IOException
{
try {
Log.debug(Font.class, "rasterizing glyph " + glyph.c + " of font "
+ glyph.font);
- if (Font.loadedStream != glyph.font.stream)
loadFontByteStream(glyph.font.stream);
+ if (Font.loadedStream != glyph.font.stream) {
+ Log.info(Font.class, "loading font stream " +
glyph.font.stream);
+ loadFontByteStream(glyph.font.stream);
+ }
//long start = System.currentTimeMillis();
- rt.call("render",glyph.c,glyph.font.pointsize);
+ rt.call("render",glyph.c,glyph.font.pointsize.intValue());
rtCheck();
@@ -200,7 +215,7 @@
glyph.isLoaded = true;
} catch (Exception e) {
// FEATURE: Better error reporting (throw an exception?)
- Log.info(Font.class, e);
+ Log.error(Font.class, e);
}
}
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn