1 // Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
3 import org.xwt.translators.*;
9 public int max_ascent; // same value for every glyph in font; the max ascent of all chars
10 public int max_descent; // same value for every glyph in font; the max descent of all chars
11 public int baseline; // within the picture, this is the y-coordinate of the baseline
12 public int advance; // amount to increment the x-coordinate
15 // k1=font.res k2=(c << 16 | pointsize)
16 private static Cache glyphCache = new Cache();
18 public static Glyph getCachedGlyph(Res res, int pointsize, char c) {
19 return (Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize));
21 public static void renderGlyph(Res res, int pointsize, char c) {
22 if (!ThreadMessage.suspendThread())
23 throw new RuntimeException("attempt to perform background-only operation in a foreground thread");
25 // FEATURE: be smarter here
26 if ((Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize)) != null) return;
27 Log.log(Freetype.class, "rendering glyphs for font " + res.getDescriptiveName());
28 if (c >= 32 && c < 127) Freetype.renderGlyphs(res, pointsize, 32, 126, glyphCache);
29 else Freetype.renderGlyphs(res, pointsize, (int)c, (int)c, glyphCache);
30 if ((Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize)) == null)
31 throw new JS.Exn("error rendering glyph " + c + "; glyph is null");
32 Log.log(Freetype.class, " done rendering glyphs for font " + res.getDescriptiveName());
34 ThreadMessage.resumeThread();