fix Font breakage resulting from careless removal of Queue
authoradam <adam@megacz.com>
Sun, 23 Jan 2005 21:14:43 +0000 (21:14 +0000)
committeradam <adam@megacz.com>
Sun, 23 Jan 2005 21:14:43 +0000 (21:14 +0000)
darcs-hash:20050123211443-5007d-f42ac8a99e8be40ab138a91a90014767e3292d2c.gz

src/org/ibex/graphics/Font.java

index 99c9bdc..9d012e4 100644 (file)
@@ -17,8 +17,6 @@ public class Font {
 
     private Font(JS stream, int pointsize) { this.stream = stream; this.pointsize = pointsize; }
 
-    private static boolean glyphRenderingTaskIsScheduled = false;
-
     public final int 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
@@ -46,9 +44,8 @@ public class Font {
 
     // Statics //////////////////////////////////////////////////////////////////////
 
-    static final Hashtable glyphsToBeCached = new Hashtable();
-    static final Hashtable glyphsToBeDisplayed = new Hashtable();
-    // HACK: replace with Cache<JS, int>
+    static final Queue toBeRasterized = new Queue(300);
+    static final Queue toBeDisplayed = new Queue(300);
     private static Basket.Map fonts = new Basket.Hash();
     public static Font getFont(JS stream, int pointsize) {
         Basket.Map m = (Basket.Map)fonts.get(stream);
@@ -72,13 +69,9 @@ public class Font {
                                 int cx1, int cy1, int cx2, int cy2, int bg) {
         int width = 0, height = 0;
         if (!latinCharsPreloaded) {       // preload the Latin-1 charset with low priority (we'll probably want it)
-            for(int i=48; i<57; i++) if (glyphs[i]==null) glyphsToBeCached.put(glyphs[i]=Platform.createGlyph(this, (char)i),"");
-            for(int i=32; i<47; i++) if (glyphs[i]==null) glyphsToBeCached.put(glyphs[i]=Platform.createGlyph(this, (char)i),"");
-            for(int i=57; i<128; i++) if (glyphs[i]==null) glyphsToBeCached.put(glyphs[i]=Platform.createGlyph(this, (char)i),"");
-            if (!glyphRenderingTaskIsScheduled) {
-                Platform.Scheduler.add(glyphRenderingTask);
-                glyphRenderingTaskIsScheduled = true;
-            }
+            for(int i=48; i<57; i++) if(glyphs[i]==null) toBeRasterized.append(glyphs[i]=Platform.createGlyph(this, (char)i));
+            for(int i=32; i<47; i++) if(glyphs[i]==null) toBeRasterized.append(glyphs[i]=Platform.createGlyph(this, (char)i));
+            for(int i=57; i<128; i++) if(glyphs[i]==null) toBeRasterized.append(glyphs[i]=Platform.createGlyph(this, (char)i));
             latinCharsPreloaded = true;
         }
         for(int i=0; i<text.length(); i++) {
@@ -119,20 +112,15 @@ public class Font {
         return g;
     }
 
-    static final Callable glyphRenderingTask = new Callable() { public Object run(Object o) {
-        // FIXME: this should be a low-priority task
-        glyphRenderingTaskIsScheduled = false;
-        if (glyphsToBeCached.isEmpty()) return null;
-        Glyph g = (Glyph)glyphsToBeCached.keys().nextElement();
-        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;
-        Platform.Scheduler.add(this);
-        return null;
-    } };
+    static { new Thread() { public void run() {
+        while(true) {
+            Glyph g = (Glyph)toBeRasterized.remove(true);
+            if (g == null) continue;
+            Log.debug(Font.class, "glyphRenderingTask rendering " + g.c + " of " + g.font);
+            g.render();
+            Log.debug(Glyph.class, "   done rendering glyph " + g.c);
+        }
+    } }.start(); }
 
 
     // FreeType Interface //////////////////////////////////////////////////////////////////////////////