Stream->Fountain, move Scheduler to Platform, HashMap->Hash
[org.ibex.core.git] / src / org / ibex / graphics / Font.java
index 6f1e69a..99c9bdc 100644 (file)
@@ -7,7 +7,6 @@ import org.ibex.util.*;
 import java.io.*;
 import java.util.Hashtable;
 import org.ibex.js.*;
-import org.ibex.core.*;
 import org.ibex.nestedvm.*;
 import org.ibex.plat.*;
 import org.ibex.nestedvm.Runtime;
@@ -50,12 +49,12 @@ public class Font {
     static final Hashtable glyphsToBeCached = new Hashtable();
     static final Hashtable glyphsToBeDisplayed = new Hashtable();
     // HACK: replace with Cache<JS, int>
-    private static Basket.Map fonts = new Basket.HashMap();
+    private static Basket.Map fonts = new Basket.Hash();
     public static Font getFont(JS stream, int 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());
+        else fonts.put(stream, m = new Basket.Hash());
         if (ret == null) m.put(new Integer(pointsize), ret = new Font(stream, pointsize));
         return ret;
     }
@@ -68,13 +67,16 @@ public class Font {
      *  @returns <code>(width&lt;&lt;32)|height</code>
      */
     public long rasterizeGlyphs(String text, PixelBuffer pb, int textcolor, int x, int y, int cx1, int cy1, int cx2, int cy2) {
+        return rasterizeGlyphs(text, pb, textcolor, x, y, cx1, cy1, cx2, cy2, 0); }
+    public long rasterizeGlyphs(String text, PixelBuffer pb, int textcolor, int x, int y,
+                                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) {
-                Scheduler.add(glyphRenderingTask);
+                Platform.Scheduler.add(glyphRenderingTask);
                 glyphRenderingTaskIsScheduled = true;
             }
             latinCharsPreloaded = true;
@@ -84,7 +86,14 @@ public class Font {
             Glyph g = glyphs[c];
             if (g == null) glyphs[c] = g = Platform.createGlyph(this, c);
             g.render();
-            if (pb != null) pb.drawGlyph(g, x + width, y + g.font.max_ascent - g.baseline, cx1, cy1, cx2, cy2, textcolor);
+            if (pb != null) pb.drawGlyph(g,
+                                         x + width,
+                                         y + g.font.max_ascent - g.baseline,
+                                         x+width,
+                                         cy1,
+                                         x+width+g.advance,
+                                         cy2,
+                                         textcolor, bg);
             width += g.advance;
             height = java.lang.Math.max(height, max_ascent + max_descent);
         }
@@ -103,6 +112,13 @@ public class Font {
         return ret;
     }
 
+    public Glyph getGlyph(char c) {
+        rasterizeGlyphs(c+"", null, 0, 0, 0, 0, 0, 0, 0);
+        Glyph g = glyphs[c];
+        g.render();
+        return g;
+    }
+
     static final Callable glyphRenderingTask = new Callable() { public Object run(Object o) {
         // FIXME: this should be a low-priority task
         glyphRenderingTaskIsScheduled = false;
@@ -114,7 +130,7 @@ public class Font {
         g.render();
         Log.debug(Glyph.class, "   done rendering glyph " + g.c);
         glyphRenderingTaskIsScheduled = true;
-        Scheduler.add(this);
+        Platform.Scheduler.add(this);
         return null;
     } };
 
@@ -145,7 +161,7 @@ public class Font {
         
         try {
             Log.info(Font.class, "loading font " + JSU.str(res));
-            InputStream is = res.getInputStream();
+            InputStream is = JSU.getInputStream(res);
             byte[] fontstream = InputStreamToByteArray.convert(is);
             rt.free(loadedStreamAddr);
             loadedStreamAddr = rt.xmalloc(fontstream.length);