X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fgraphics%2FFont.java;h=b2c30caf71570e59313bb2a31032ba68a083ecb3;hp=8d525fb7c99f6768ad13df0657097568d776274f;hb=098f2fd17df6500e8dad466c162c2e0589cc7df5;hpb=76b21655a0710caf4f972c107a3ab991032d7e10
diff --git a/src/org/ibex/graphics/Font.java b/src/org/ibex/graphics/Font.java
index 8d525fb..b2c30ca 100644
--- a/src/org/ibex/graphics/Font.java
+++ b/src/org/ibex/graphics/Font.java
@@ -7,7 +7,6 @@ import org.ibex.util.*;
import java.io.*;
import java.util.Hashtable;
import org.ibex.js.*;
-import org.ibex.core.*;
import org.ibex.nestedvm.*;
import org.ibex.plat.*;
import org.ibex.nestedvm.Runtime;
@@ -18,8 +17,6 @@ public class Font {
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 JS stream; ///< the stream from which this font was loaded
public int max_ascent; ///< the maximum ascent, in pixels
@@ -47,12 +44,15 @@ public class Font {
// Statics //////////////////////////////////////////////////////////////////////
- static final Hashtable glyphsToBeCached = new Hashtable();
- static final Hashtable glyphsToBeDisplayed = new Hashtable();
- private static Cache fontCache = new Cache(100);
+ static final Queue toBeRasterized = new Queue(300);
+ static final Queue toBeDisplayed = new Queue(300);
+ private static Basket.Map fonts = new Basket.Hash();
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));
+ Basket.Map m = (Basket.Map)fonts.get(stream);
+ Font ret = null;
+ if (m != null) ret = (Font)m.get(new Integer(pointsize));
+ else fonts.put(stream, m = new Basket.Hash());
+ if (ret == null) m.put(new Integer(pointsize), ret = new Font(stream, pointsize));
return ret;
}
@@ -63,55 +63,69 @@ public class Font {
* Rasterize the glyphs of text
.
* @returns (width<<32)|height
*/
- public long rasterizeGlyphs(String text, PixelBuffer pb, int textcolor, int x, int y, int cx1, int cy1, int cx2, int cy2) {
+ public String rasterizeGlyphs(String text) {
+ StringBuffer path = new StringBuffer(text.length() * 50);
+ for(int i=0; i>> 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);
+ long ret = rasterizeGlyphs(s, null, null, null, 0, 0);
sizeCache.put(s, new Long(ret));
return ret;
}
- static final Task glyphRenderingTask = new Task() { public void perform() {
- // FIXME: this should be a low-priority task
- glyphRenderingTaskIsScheduled = false;
- if (glyphsToBeCached.isEmpty()) return;
- Glyph g = (Glyph)glyphsToBeCached.keys().nextElement();
- if (g == null) return;
- glyphsToBeCached.remove(g);
- Log.debug(Font.class, "glyphRenderingTask rendering " + g.c + " of " + g.font);
+ public Glyph getGlyph(char c) {
+ rasterizeGlyphs(c+"", null, null, null, 0, 0);
+ Glyph g = glyphs[c];
g.render();
- Log.debug(Glyph.class, " done rendering glyph " + g.c);
- glyphRenderingTaskIsScheduled = true;
- Scheduler.add(this);
- } };
+ return g;
+ }
+
+ static { new Thread() { public void run() {
+ while(true) {
+ Glyph g = (Glyph)toBeRasterized.remove(true);
+ if (g == null) continue;
+ Log.debug(Font.class, "glyphRenderingTask rendering " + g.c + " of " + g.font);
+ g.render();
+ Log.debug(Glyph.class, " done rendering glyph " + g.c);
+ }
+ } }.start(); }
// FreeType Interface //////////////////////////////////////////////////////////////////////////////
@@ -139,8 +153,8 @@ public class Font {
if(loadedStream == res) return;
try {
- Log.info(Font.class, "loading font " + JS.debugToString(res));
- InputStream is = res.getInputStream();
+ Log.info(Font.class, "loading font " + JSU.str(res));
+ InputStream is = JSU.getInputStream(res);
byte[] fontstream = InputStreamToByteArray.convert(is);
rt.free(loadedStreamAddr);
loadedStreamAddr = rt.xmalloc(fontstream.length);