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