From: adam Date: Wed, 7 Apr 2004 20:47:51 +0000 (+0000) Subject: fonts now rendered immediately on-demand X-Git-Tag: RC4~31 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=580e7997d6f1e66c51114a050ff695bb15ed4e19;p=org.ibex.core.git fonts now rendered immediately on-demand darcs-hash:20040407204751-5007d-fc265cbebcb47b356cda0701859b0b16f0457e04.gz --- diff --git a/src/org/ibex/Box.java b/src/org/ibex/Box.java index bb57d5a..c2f16dc 100644 --- a/src/org/ibex/Box.java +++ b/src/org/ibex/Box.java @@ -537,8 +537,7 @@ public final class Box extends JSScope implements Scheduler.Task { int gap_y = height - font.textheight(text); int text_x = globalx + (test(ALIGN_RIGHT) ? gap_x : !test(ALIGN_LEFT) ? gap_x/2 : 0); int text_y = globaly + (test(ALIGN_BOTTOM) ? gap_y : !test(ALIGN_TOP) ? gap_y/2 : 0); - if (font.rasterizeGlyphs(text, buf, strokecolor, text_x, text_y, cx1, cy1, cx2, cy2, null) == -1) - font.rasterizeGlyphs(text, buf, strokecolor, text_x, text_y, cx1, cy1, cx2, cy2, this); + font.rasterizeGlyphs(text, buf, strokecolor, text_x, text_y, cx1, cy1, cx2, cy2); } for(Box b = getChild(0); b != null; b = b.nextSibling()) diff --git a/src/org/ibex/Font.java b/src/org/ibex/Font.java index 48fd0de..bbe0ac2 100644 --- a/src/org/ibex/Font.java +++ b/src/org/ibex/Font.java @@ -32,12 +32,13 @@ 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 + void render() { if (!isLoaded) try { freetype.renderGlyph(this); } catch (IOException e) { Log.info(Freetype.class, e); } } } // Statics ////////////////////////////////////////////////////////////////////// - private static final Freetype freetype = new Freetype(); + static final Freetype freetype = new Freetype(); static final Hashtable glyphsToBeCached = new Hashtable(); static final Hashtable glyphsToBeDisplayed = new Hashtable(); private static Cache fontCache = new Cache(100); @@ -52,65 +53,30 @@ public class Font { /** * Rasterize the glyphs of text. - * - * If all the glyphs of text are not yet loaded, - * spawn a Task to load them and then invoke callback. If all - * the glyphs are loaded, rasterize them to the - * PixelBuffer (if non-null). - * - * @returns (width<<32)|height if all glyphs are loaded; else -1 + * @returns (width<<32)|height */ - public long rasterizeGlyphs(final String text, PixelBuffer pb, int textcolor, - int x, int y, int cx1, int cy1, int cx2, int cy2, - final Scheduler.Task callback) { - boolean encounteredUnrenderedGlyph = false; + public long rasterizeGlyphs(String text, PixelBuffer pb, int textcolor, int x, int y, int cx1, int cy1, int cx2, int cy2) { int width = 0, height = 0; - - // preload the Latin-1 charset with low priority (we'll probably want it) - if (!latinCharsPreloaded) { - for(int i=48; i<57; i++) glyphsToBeCached.put(glyphs[i] = Platform.createGlyph(this, (char)i),""); - for(int i=32; i<47; i++) glyphsToBeCached.put(glyphs[i] = Platform.createGlyph(this, (char)i),""); - for(int i=57; i<128; i++) glyphsToBeCached.put(glyphs[i] = Platform.createGlyph(this, (char)i),""); + if (!latinCharsPreloaded) { // preload the Latin-1 charset with low priority (we'll probably want it) + for(int i=48; i<57; i++) if (glyphs[i]==null) glyphsToBeCached.put(glyphs[i]=Platform.createGlyph(this, (char)i),""); + for(int i=32; i<47; i++) if (glyphs[i]==null) glyphsToBeCached.put(glyphs[i]=Platform.createGlyph(this, (char)i),""); + for(int i=57; i<128; i++) if (glyphs[i]==null) glyphsToBeCached.put(glyphs[i]=Platform.createGlyph(this, (char)i),""); + if (!glyphRenderingTaskIsScheduled) { + Scheduler.add(glyphRenderingTask); + glyphRenderingTaskIsScheduled = true; } - latinCharsPreloaded = true; - - if (!glyphRenderingTaskIsScheduled) { - Scheduler.add(glyphRenderingTask); - glyphRenderingTaskIsScheduled = true; + latinCharsPreloaded = true; } - for(int i=0; i