2004/01/19 00:16:54
[org.ibex.core.git] / src / org / xwt / Font.java
index 2d9fcd7..ed979b7 100644 (file)
@@ -6,15 +6,16 @@ import org.xwt.js.*;
 import java.util.*;
 import java.io.*;
 
+// FEATURE: this could be cleaner
 /** encapsulates a single font (a set of Glyphs) */
 public class Font {
 
-    private Font(Stream res, int pointsize) { this.res = res; this.pointsize = pointsize; }
+    private Font(Stream 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 Stream res;                       ///< the resource from which this font was loaded
+    public final Stream 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
     boolean latinCharsPreloaded = false;        ///< true if a request to preload ASCII 32-127 has begun
@@ -27,10 +28,9 @@ public class Font {
         public int baseline;                    ///< within the alphamask, this is the y-coordinate of the baseline
         public int advance;                     ///< amount to increment the x-coordinate
         public boolean isLoaded = false;        ///< true iff the glyph is loaded
-        public byte[] alphaChannel = null;
         public int width = -1;                  ///< the width of the glyph
         public int height = -1;                 ///< the height of the glyph
-        public byte[] data = null;
+        public byte[] data = null;              ///< the alpha channel samples for this font
     }
 
 
@@ -39,9 +39,9 @@ public class Font {
     private static final Freetype freetype = new Freetype();
     static final Queue glyphsToBeRendered = new Queue(255);
     private static Cache fontCache = new Cache(100);
-    public static Font getFont(Stream res, int pointsize) {
-        Font ret = (Font)fontCache.get(res, new Integer(pointsize));
-        if (ret == null) fontCache.put(res, new Integer(pointsize), ret = new Font(res, pointsize));
+    public static Font getFont(Stream 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));
         return ret;
     }
 
@@ -67,15 +67,14 @@ public class Font {
             final char c = text.charAt(i);
             Glyph g = glyphs[c];
             if (g == null) {
-                g = Platform.createGlyph(this, c);    // prepend so they are high priority
+                g = Platform.createGlyph(this, c);
                 glyphs[c] = g;
             }
             if (!g.isLoaded) {
                 glyphsToBeRendered.prepend(g);              // even if it's already in the queue, boost its priority
                 encounteredUnrenderedGlyph = true;
             } else if (!encounteredUnrenderedGlyph) {
-                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, cx1, cy1, cx2, cy2, textcolor);
                 width += g.advance;
                 height = java.lang.Math.max(height, max_ascent + max_descent);
             }
@@ -123,7 +122,7 @@ public class Font {
         Glyph g = (Glyph)glyphsToBeRendered.remove(false);
         if (g == null) { glyphRenderingTaskIsScheduled = false; return; }
         if (g.isLoaded) { perform(); /* tailcall to the next glyph */ return; }
-        //Log.info(Glyph.class, "rendering glyph " + g.c);
+        Log.debug(Glyph.class, "rendering glyph " + g.c);
         try { freetype.renderGlyph(g); } catch (IOException e) { Log.info(Freetype.class, e); }
         Scheduler.add(this);          // keep ourselves in the queue until there are no glyphs to render
         glyphRenderingTaskIsScheduled = true;