questionable patch: merge of a lot of stuff from the svg branch
[org.ibex.core.git] / src / org / ibex / graphics / Font.java
index b2c30ca..70451a3 100644 (file)
@@ -74,7 +74,7 @@ public class Font {
         }
         return path.toString();
     }
-    public long rasterizeGlyphs(String text, PixelBuffer pb, Affine a, Mesh h, int fg, int bg) {
+    public long rasterizeGlyphs(String text, PixelBuffer pb, Affine a, Mesh h, Affine ha, int fg, int bg) {
         int width = 0, height = 0;
         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) toBeRasterized.append(glyphs[i]=Platform.createGlyph(this, (char)i));
@@ -88,11 +88,17 @@ public class Font {
             Glyph g = glyphs[c];
             if (g == null) glyphs[c] = g = Platform.createGlyph(this, c);
             g.render();
-            if (a!=null) a.premultiply(Affine.translate(0, g.font.max_ascent - g.baseline));
-            if (pb != null) pb.drawGlyph(g, a, h, fg, bg);
-            if (a!=null) a.premultiply(Affine.translate(0, -1 * (g.font.max_ascent - g.baseline)));
+            if (a!=null) a.multiply(Affine.translate(0, g.font.max_ascent - g.baseline));
+            if (ha!=null) ha.multiply(Affine.translate(0, g.font.max_ascent - g.baseline));
+            if (pb != null) {
+                pb.drawGlyph(g, a, h, fg, bg);
+                if (h!=null) h.subtract(new Mesh().addRect(0, 0, g.width, g.height), ha);
+            }
+            if (a!=null) a.multiply(Affine.translate(0, -1 * (g.font.max_ascent - g.baseline)));
+            if (ha!=null) ha.multiply(Affine.translate(0, -1 * (g.font.max_ascent - g.baseline)));
             width += g.advance;
-            if (a!=null) a.premultiply(Affine.translate(g.advance, 0));
+            if (a!=null) a.multiply(Affine.translate(g.advance, 0));
+            if (ha!=null) ha.multiply(Affine.translate(g.advance, 0));
             height = java.lang.Math.max(height, max_ascent + max_descent);
         }
         return ((((long)width) << 32) | (long)(height & 0xffffffffL));
@@ -105,13 +111,13 @@ public class Font {
     public long textsize(String s) {
         Long l = (Long)sizeCache.get(s);
         if (l != null) return ((Long)l).longValue();
-        long ret = rasterizeGlyphs(s, null, null, null, 0, 0);
+        long ret = rasterizeGlyphs(s, null, null, null, null, 0, 0);
         sizeCache.put(s, new Long(ret));
         return ret;
     }
 
     public Glyph getGlyph(char c) {
-        rasterizeGlyphs(c+"", null, null, null, 0, 0);
+        rasterizeGlyphs(c+"", null, null, null, null, 0, 0);
         Glyph g = glyphs[c];
         g.render();
         return g;