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
// 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);
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++) {
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 //////////////////////////////////////////////////////////////////////////////