X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FGlyph.java;h=71cf19e629facbb1d94f8e4134770cd32cb85ee7;hb=6a96430e10e27fc1de5754cb5add705f929dd109;hp=efe2ad0ef1ce933a8b07a1115ae1cad9d6ba5ff8;hpb=16ea48d834626fb9815da2f7632c3633838fb790;p=org.ibex.core.git
diff --git a/src/org/xwt/Glyph.java b/src/org/xwt/Glyph.java
index efe2ad0..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,27 +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 getCachedGlyph(Res res, int pointsize, char c) {
- return (Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize));
- }
- public static void renderGlyph(Res res, int pointsize, char c) {
- if (!ThreadMessage.suspendThread())
- throw new RuntimeException("attempt to perform background-only operation in a foreground thread");
- synchronized(res) {
- // FEATURE: be smarter here
- if ((Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize)) != null) return;
- Log.log(Freetype.class, "rendering glyphs for font " + res.getDescriptiveName());
- if (c >= 32 && c < 127) Freetype.renderGlyphs(res, pointsize, 32, 126, glyphCache);
- else Freetype.renderGlyphs(res, pointsize, (int)c, (int)c, glyphCache);
- if ((Glyph)glyphCache.get(res, new Integer((((int)c) << 16) | pointsize)) == null)
- throw new JS.Exn("error rendering glyph " + c + "; glyph is null");
- Log.log(Freetype.class, " done rendering glyphs for font " + res.getDescriptiveName());
- }
- ThreadMessage.resumeThread();
+ private static Queue glyphsToBeRendered = new Queue(255);
+ private static Freetype freetype = new Freetype();
+
+ 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;
+ }
+ };
+
+ /**
+
+ * 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