make core compile with new js stuff and Task replacement class
[org.ibex.core.git] / src / org / ibex / graphics / Font.java
index 8d525fb..6f1e69a 100644 (file)
@@ -49,10 +49,14 @@ public class Font {
 
     static final Hashtable glyphsToBeCached = new Hashtable();
     static final Hashtable glyphsToBeDisplayed = new Hashtable();
 
     static final Hashtable glyphsToBeCached = new Hashtable();
     static final Hashtable glyphsToBeDisplayed = new Hashtable();
-    private static Cache fontCache = new Cache(100);
+    // HACK: replace with Cache<JS, int>
+    private static Basket.Map fonts = new Basket.HashMap();
     public static Font getFont(JS stream, int pointsize) {
     public static Font getFont(JS stream, int pointsize) {
-        Font ret = (Font)fontCache.get(stream, new Integer(pointsize));
-        if (ret == null) fontCache.put(stream, new Integer(pointsize), ret = new Font(stream, pointsize));
+        Basket.Map m = (Basket.Map)fonts.get(stream);
+        Font ret = null;
+        if (m != null) ret = (Font)m.get(new Integer(pointsize));
+        else fonts.put(stream, m = new Basket.HashMap());
+        if (ret == null) m.put(new Integer(pointsize), ret = new Font(stream, pointsize));
         return ret;
     }
 
         return ret;
     }
 
@@ -88,7 +92,7 @@ public class Font {
     }
 
     // FEATURE do we really need to be caching sizes?
     }
 
     // FEATURE do we really need to be caching sizes?
-    private static Cache sizeCache = new Cache(1000);
+    private static Cache sizeCache = new Cache(1000, true);
     public int textwidth(String s) { return (int)((textsize(s) >>> 32) & 0xffffffff); }
     public int textheight(String s) { return (int)(textsize(s) & 0xffffffffL); }
     public long textsize(String s) {
     public int textwidth(String s) { return (int)((textsize(s) >>> 32) & 0xffffffff); }
     public int textheight(String s) { return (int)(textsize(s) & 0xffffffffL); }
     public long textsize(String s) {
@@ -99,18 +103,19 @@ public class Font {
         return ret;
     }
 
         return ret;
     }
 
-    static final Task glyphRenderingTask = new Task() { public void perform() {
+    static final Callable glyphRenderingTask = new Callable() { public Object run(Object o) {
         // FIXME: this should be a low-priority task
         glyphRenderingTaskIsScheduled = false;
         // FIXME: this should be a low-priority task
         glyphRenderingTaskIsScheduled = false;
-        if (glyphsToBeCached.isEmpty()) return;
+        if (glyphsToBeCached.isEmpty()) return null;
         Glyph g = (Glyph)glyphsToBeCached.keys().nextElement();
         Glyph g = (Glyph)glyphsToBeCached.keys().nextElement();
-        if (g == null) return;
+        if (g == null) return null;
         glyphsToBeCached.remove(g);
         Log.debug(Font.class, "glyphRenderingTask rendering " + g.c + " of " + g.font);
         g.render();
         Log.debug(Glyph.class, "   done rendering glyph " + g.c);
         glyphRenderingTaskIsScheduled = true;
         Scheduler.add(this);
         glyphsToBeCached.remove(g);
         Log.debug(Font.class, "glyphRenderingTask rendering " + g.c + " of " + g.font);
         g.render();
         Log.debug(Glyph.class, "   done rendering glyph " + g.c);
         glyphRenderingTaskIsScheduled = true;
         Scheduler.add(this);
+        return null;
     } };
 
 
     } };
 
 
@@ -139,7 +144,7 @@ public class Font {
         if(loadedStream == res) return;
         
         try {
         if(loadedStream == res) return;
         
         try {
-            Log.info(Font.class, "loading font " + JS.debugToString(res));
+            Log.info(Font.class, "loading font " + JSU.str(res));
             InputStream is = res.getInputStream();
             byte[] fontstream = InputStreamToByteArray.convert(is);
             rt.free(loadedStreamAddr);
             InputStream is = res.getInputStream();
             byte[] fontstream = InputStreamToByteArray.convert(is);
             rt.free(loadedStreamAddr);