X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fgraphics%2FFont.java;h=96c65c4d03d567f8a83a4b7ae6a82001c02ce71b;hb=2d6763644359578428d56d004b998edd10463a84;hp=6df989986ff6e6d7e2f212026f7ccbb5152cdb05;hpb=91c9edbb2d4feafa859aa6becdb0793fbbc9852f;p=org.ibex.core.git diff --git a/src/org/ibex/graphics/Font.java b/src/org/ibex/graphics/Font.java index 6df9899..96c65c4 100644 --- a/src/org/ibex/graphics/Font.java +++ b/src/org/ibex/graphics/Font.java @@ -4,24 +4,24 @@ import org.ibex.util.*; import java.io.*; import java.util.Hashtable; import org.ibex.js.*; -import org.xwt.mips.*; +import org.ibex.nestedvm.*; import org.ibex.plat.*; -import org.xwt.mips.Runtime; +import org.ibex.nestedvm.Runtime; // FEATURE: this could be cleaner /** encapsulates a single font (a set of Glyphs) */ public class Font { - private Font(Stream stream, int pointsize) { this.stream = stream; this.pointsize = pointsize; } + private Font(JS stream, int pointsize) { this.stream = stream; this.pointsize = pointsize; } private static boolean glyphRenderingTaskIsScheduled = false; public final int pointsize; ///< the size of the font - public final Stream stream; ///< the stream from which this font was loaded + public final JS stream; ///< the stream from which this font was loaded public int max_ascent; ///< the maximum ascent, in pixels public int max_descent; ///< the maximum descent, in pixels boolean latinCharsPreloaded = false; ///< true if a request to preload ASCII 32-127 has begun - Glyph[] glyphs = new Glyph[65535]; ///< the glyphs that comprise this font + public Glyph[] glyphs = new Glyph[65535]; ///< the glyphs that comprise this font public abstract static class Glyph { protected Glyph(Font font, char c) { this.font = font; this.c = c; } @@ -33,6 +33,7 @@ public class Font { public int width = -1; ///< the width of the glyph public int height = -1; ///< the height of the glyph public byte[] data = null; ///< the alpha channel samples for this font + public String path = null; // FIXME this should be shared across point sizes void render() { if (!isLoaded) try { renderGlyph(this); } catch (IOException e) { Log.info(Font.class, e); } isLoaded = true; @@ -45,7 +46,7 @@ public class Font { static final Hashtable glyphsToBeCached = new Hashtable(); static final Hashtable glyphsToBeDisplayed = new Hashtable(); private static Cache fontCache = new Cache(100); - public static Font getFont(Stream stream, int pointsize) { + public static Font getFont(JS stream, int pointsize) { Font ret = (Font)fontCache.get(stream, new Integer(pointsize)); if (ret == null) fontCache.put(stream, new Integer(pointsize), ret = new Font(stream, pointsize)); return ret; @@ -114,14 +115,14 @@ public class Font { // FEATURE: use streams, not memoryfont's // FEATURE: kerning pairs private static final Runtime rt; - private static Stream loadedStream; + private static JS loadedStream; private static int loadedStreamAddr; static { try { rt = (Runtime)Class.forName("org.ibex.util.MIPSApps").newInstance(); } catch(Exception e) { - throw new Error("Error instansiating freetype"); + throw new Error("Error instantiating freetype: " + e); } rt.start(new String[]{"freetype"}); rt.execute(); @@ -130,12 +131,12 @@ public class Font { private static void rtCheck() { if(rt.getState() != Runtime.PAUSED) throw new Error("Freetype exited " + rt.exitStatus()); } - private static void loadFontByteStream(Stream res) { + private static void loadFontByteStream(JS res) { if(loadedStream == res) return; try { - Log.info(Font.class, "loading font " + res); - InputStream is = Stream.getInputStream(res); + Log.info(Font.class, "loading font " + JS.debugToString(res)); + InputStream is = res.getInputStream(); byte[] fontstream = InputStreamToByteArray.convert(is); rt.free(loadedStreamAddr); loadedStreamAddr = rt.xmalloc(fontstream.length); @@ -167,11 +168,16 @@ public class Font { glyph.width = rt.getUserInfo(1); glyph.height = rt.getUserInfo(2); - + glyph.data = new byte[glyph.width * glyph.height]; int addr = rt.getUserInfo(0); rt.copyin(addr, glyph.data, glyph.width * glyph.height); + byte[] path = new byte[rt.getUserInfo(8)]; + rt.copyin(rt.getUserInfo(7), path, rt.getUserInfo(8)); + glyph.path = new String(path); + glyph.path += " m " + (64 * glyph.advance) + " 0 "; + glyph.isLoaded = true; } catch (Exception e) { // FEATURE: Better error reporting (thow an exception?)