X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FGlyph.java;h=71cf19e629facbb1d94f8e4134770cd32cb85ee7;hb=6a96430e10e27fc1de5754cb5add705f929dd109;hp=e99884505e7b4f38158a989b67c5cbac0fdc09a2;hpb=a071a56b6d9c9d38b85d23cc3eb287435322d0cc;p=org.ibex.core.git
diff --git a/src/org/xwt/Glyph.java b/src/org/xwt/Glyph.java
index e998845..71cf19e 100644
--- a/src/org/xwt/Glyph.java
+++ b/src/org/xwt/Glyph.java
@@ -3,6 +3,7 @@ package org.xwt;
import org.xwt.translators.*;
import org.xwt.util.*;
import org.xwt.js.*;
+import java.util.*;
public class Glyph {
public char c;
@@ -10,21 +11,93 @@ public class Glyph {
public int max_descent; // same value for every glyph in font; the max descent of all chars
public int baseline; // within the picture, this is the y-coordinate of the baseline
public int advance; // amount to increment the x-coordinate
+ public int pointsize;
public Picture p;
+ public Res res;
+ public boolean rendered = false;
// k1=font.res k2=(c << 16 | pointsize)
private static Cache glyphCache = new Cache();
- public static Glyph getGlyph(Res res, int pointsize, char c) {
- Glyph ret = (Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize));
- if (ret != null) return ret;
+ private static Queue glyphsToBeRendered = new Queue(255);
+ private static Freetype freetype = new Freetype();
- // FEATURE: be smarter here
- if (c < 256) Freetype.renderGlyphs(res, pointsize, 0, 255, glyphCache);
- else Freetype.renderGlyphs(res, pointsize, (int)c, (int)c, glyphCache);
+ private static Scheduler.Task glyphRenderingTask = new Scheduler.Task() {
+ public Object call(Object arg) {
+ Glyph g = (Glyph)glyphsToBeRendered.remove(false);
+ if (g == null) return null;
+ if (g.p != null) return null;
+ Log.log(Glyph.class, "rendering glyph " + g.c);
+ freetype.renderGlyph(g.res, g);
+ g.rendered = true;
+ Scheduler.add(this);
+ return null;
+ }
+ };
- ret = (Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize));
- if (ret != null) return ret;
- throw new JS.Exn("error rendering glyph " + c);
+ /**
+
+ * If the glyphs of text
are not yet loaded, spawn a
+ * Task to load them and invoke callback.
+ *
+
+ * returns the width (in the high-order int) and height (in the
+ * low-order int) of the string's rasterization, or -1 if some
+ * glyphs are not loaded.
+
+ */
+ public static long rasterizeGlyphs(final Res res, final int pointsize, final String text, PixelBuffer pb, int textcolor,
+ int x, int y, int cx1, int cy1, int cx2, int cy2, final Callback callback) {
+ boolean ret = true;
+ int width = 0;
+ int height = 0;
+ for(int i=0; i