-// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
+// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
package org.xwt;
import org.xwt.translators.*;
import org.xwt.util.*;
/** encapsulates a single font (a set of Glyphs) */
public class Font {
- private Font(Res res, int pointsize) { this.res = res; this.pointsize = pointsize; }
+ private Font(Stream res, int pointsize) { this.res = res; this.pointsize = pointsize; }
private static boolean glyphRenderingTaskIsScheduled = false;
public final int pointsize; ///< the size of the font
- public final Res res; ///< the resource from which this font was loaded
+ public final Stream res; ///< the resource 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
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(Res res, int pointsize) {
+ 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));
return ret;
for(int i=0; i<text.length(); i++) {
final char c = text.charAt(i);
Glyph g = glyphs[c];
- if (g == null) glyphs[c] = g = Platform.createGlyph(this, c); // prepend so they are high priority
+ if (g == null) {
+ g = Platform.createGlyph(this, c); // prepend so they are high priority
+ glyphs[c] = g;
+ }
if (!g.isLoaded) {
glyphsToBeRendered.prepend(g); // even if it's already in the queue, boost its priority
encounteredUnrenderedGlyph = true;
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.info(Glyph.class, "rendering glyph " + g.c);
try { freetype.renderGlyph(g); } catch (IOException e) { Log.info(Freetype.class, e); }
- g.isLoaded = true;
Scheduler.add(this); // keep ourselves in the queue until there are no glyphs to render
glyphRenderingTaskIsScheduled = true;
} };