2003/10/28 10:10:17
[org.ibex.core.git] / src / org / xwt / Glyph.java
1 // Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
2 package org.xwt;
3 import org.xwt.translators.*;
4 import org.xwt.util.*;
5 import org.xwt.js.*;
6
7 public class Glyph {
8     public char c;
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
13     public Picture p;
14
15     // k1=font.res k2=(c << 16 | pointsize)
16     private static Cache glyphCache = new Cache();
17
18     public static Glyph getGlyph(Res res, int pointsize, char c) {
19         Glyph ret = (Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize));
20         if (ret != null) return ret;
21
22         ThreadMessage.fakeBackground = true;
23         // FEATURE: be smarter here
24         if (c >= 32 && c < 127) Freetype.renderGlyphs(res, pointsize, 32, 126, glyphCache);
25         else Freetype.renderGlyphs(res, pointsize, (int)c, (int)c, glyphCache);
26         ThreadMessage.fakeBackground = false;
27
28         ret = (Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize));
29         if (ret != null) return ret;
30         throw new JS.Exn("error rendering glyph " + c + "; glyph is null");
31     }
32 }