0a75b0b8bf67236f9e1f6cdb74f9f7ccc13d7018
[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
5 public class Glyph {
6     char c;
7     int line_height;    // same value for every glyph in font; the max height of all chars
8     int baseline;       // within the picture, this is the y-coordinate of the baseline
9     int advance;        // amount to increment the x-coordinate
10     Picture p;
11
12     // k1=font.res k2=(c << 16 | pointsize)
13     private static Cache glyphCache = new Cache();
14
15     public static Glyph getGlyph(Res res, int pointsize, char c) {
16         Glyph ret = (Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize));
17         if (ret != null) return ret;
18
19         // FEATURE: be smarter here
20         if (c < 256)
21             org.xwt.translators.Font.renderGlyphs(res, pointsize, 0, 255, glyphCache);
22         else
23             org.xwt.translators.Font.renderGlyphs(res, pointsize, (int)c, (int)c, glyphCache);
24
25         ret = (Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize));
26         if (ret != null) return ret;
27         throw new RuntimeException("renderGlyphs didn't create the glyph we wanted");
28     }
29 }