// k1=font.res k2=(c << 16 | pointsize)
private static Cache glyphCache = new Cache();
- public static Glyph getGlyph(Res res, int pointsize, char c) {
- Glyph ret = (Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize));
- if (ret != null) return ret;
-
- ThreadMessage.fakeBackground = true;
- // FEATURE: be smarter here
- if (c >= 32 && c < 127) Freetype.renderGlyphs(res, pointsize, 32, 126, glyphCache);
- else Freetype.renderGlyphs(res, pointsize, (int)c, (int)c, glyphCache);
- ThreadMessage.fakeBackground = false;
-
- ret = (Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize));
- if (ret != null) return ret;
- throw new JS.Exn("error rendering glyph " + c + "; glyph is null");
+ public static Glyph getCachedGlyph(Res res, int pointsize, char c) {
+ return (Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize));
+ }
+ public static void renderGlyph(Res res, int pointsize, char c) {
+ if (!ThreadMessage.suspendThread())
+ throw new RuntimeException("attempt to perform background-only operation in a foreground thread");
+ synchronized(res) {
+ // FEATURE: be smarter here
+ if ((Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize)) != null) return;
+ Log.log(Freetype.class, "rendering glyphs for font " + res.getDescriptiveName());
+ if (c >= 32 && c < 127) Freetype.renderGlyphs(res, pointsize, 32, 126, glyphCache);
+ else Freetype.renderGlyphs(res, pointsize, (int)c, (int)c, glyphCache);
+ if ((Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize)) == null)
+ throw new JS.Exn("error rendering glyph " + c + "; glyph is null");
+ }
+ ThreadMessage.resumeThread();
}
}