2003/09/23 08:24:59
[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         // FEATURE: be smarter here
23         if (c < 256) Font.renderGlyphs(res, pointsize, 0, 255, glyphCache);
24         else Font.renderGlyphs(res, pointsize, (int)c, (int)c, glyphCache);
25
26         ret = (Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize));
27         if (ret != null) return ret;
28         throw new JS.Exn("error rendering glyph " + c);
29     }
30 }