+ if (callback != null) Scheduler.add(new Scheduler.Task() {
+ public void perform() throws Exception {
+ // FEATURE this isn't terribly efficient... perhaps the task should go on the last glyph?
+ for(int i=0; i<text.length(); i++) {
+ Glyph g = glyphs[text.charAt(i)];
+ if (g == null || !g.isLoaded) { Scheduler.add(this); return; }
+ }
+ callback.perform();
+ }});
+
+ // preload the Latin-1 charset with low priority (we'll probably want it)
+ if (!latinCharsPreloaded) {
+ for(int i=48; i<57; i++) glyphsToBeRendered.append(glyphs[i] = Platform.createGlyph(this, (char)i));
+ for(int i=32; i<47; i++) glyphsToBeRendered.append(glyphs[i] = Platform.createGlyph(this, (char)i));
+ for(int i=57; i<128; i++) glyphsToBeRendered.append(glyphs[i] = Platform.createGlyph(this, (char)i));
+ latinCharsPreloaded = true;
+ }
+ if (!glyphRenderingTaskIsScheduled) {
+ Scheduler.add(glyphRenderingTask);
+ glyphRenderingTaskIsScheduled = true;
+ }
+ return -1;
+ }
+
+ // FEATURE do we really need to be caching sizes?
+ private static Cache sizeCache = new Cache(1000);
+ public int textwidth(String s) { return (int)((textsize(s) >>> 32) & 0xffffffff); }
+ public int textheight(String s) { return (int)(textsize(s) & 0xffffffffL); }
+ public long textsize(String s) {
+ Long l = (Long)sizeCache.get(s);
+ if (l != null) return ((Long)l).longValue();
+ long ret = rasterizeGlyphs(s, null, 0, 0, 0, 0, 0, 0, 0, null);
+ if (ret != -1) sizeCache.put(s, new Long(ret));
+ return ret == -1 ? 0 : ret;