added missing patches to move to fillTriangle() and Mesh
authoradam <adam@megacz.com>
Mon, 14 Feb 2005 08:40:51 +0000 (08:40 +0000)
committeradam <adam@megacz.com>
Mon, 14 Feb 2005 08:40:51 +0000 (08:40 +0000)
darcs-hash:20050214084051-5007d-3e597228379af524f580f4c60c1f830038d2f2ef.gz

src/org/ibex/graphics/Font.java
src/org/ibex/graphics/PixelBuffer.java
src/org/ibex/graphics/Surface.java
src/org/ibex/plat/AWT.java
src/org/ibex/plat/Java2.java
src/org/ibex/plat/OpenGL.java
src/org/ibex/plat/Win32.java
src/org/ibex/plat/X11.java

index 9d012e4..b2c30ca 100644 (file)
@@ -63,10 +63,18 @@ public class Font {
      *  Rasterize the glyphs of <code>text</code>.
      *  @returns <code>(width&lt;&lt;32)|height</code>
      */
      *  Rasterize the glyphs of <code>text</code>.
      *  @returns <code>(width&lt;&lt;32)|height</code>
      */
-    public long rasterizeGlyphs(String text, PixelBuffer pb, int textcolor, int x, int y, int cx1, int cy1, int cx2, int cy2) {
-        return rasterizeGlyphs(text, pb, textcolor, x, y, cx1, cy1, cx2, cy2, 0); }
-    public long rasterizeGlyphs(String text, PixelBuffer pb, int textcolor, int x, int y,
-                                int cx1, int cy1, int cx2, int cy2, int bg) {
+    public String rasterizeGlyphs(String text) {
+        StringBuffer path = new StringBuffer(text.length() * 50);
+        for(int i=0; i<text.length(); i++) {
+            final char c = text.charAt(i);
+            Glyph g = glyphs[c];
+            if (g == null) glyphs[c] = g = Platform.createGlyph(this, c);
+            g.render();
+            path.append(g.path);
+        }
+        return path.toString();
+    }
+    public long rasterizeGlyphs(String text, PixelBuffer pb, Affine a, Mesh h, 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));
         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));
@@ -74,20 +82,17 @@ public class Font {
             for(int i=57; i<128; i++) if(glyphs[i]==null) toBeRasterized.append(glyphs[i]=Platform.createGlyph(this, (char)i));
             latinCharsPreloaded = true;
         }
             for(int i=57; i<128; i++) if(glyphs[i]==null) toBeRasterized.append(glyphs[i]=Platform.createGlyph(this, (char)i));
             latinCharsPreloaded = true;
         }
+        a = a==null ? null : a.copy();
         for(int i=0; i<text.length(); i++) {
             final char c = text.charAt(i);
             Glyph g = glyphs[c];
             if (g == null) glyphs[c] = g = Platform.createGlyph(this, c);
             g.render();
         for(int i=0; i<text.length(); i++) {
             final char c = text.charAt(i);
             Glyph g = glyphs[c];
             if (g == null) glyphs[c] = g = Platform.createGlyph(this, c);
             g.render();
-            if (pb != null) pb.drawGlyph(g,
-                                         x + width,
-                                         y + g.font.max_ascent - g.baseline,
-                                         x+width,
-                                         cy1,
-                                         x+width+g.advance,
-                                         cy2,
-                                         textcolor, bg);
+            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)));
             width += g.advance;
             width += g.advance;
+            if (a!=null) a.premultiply(Affine.translate(g.advance, 0));
             height = java.lang.Math.max(height, max_ascent + max_descent);
         }
         return ((((long)width) << 32) | (long)(height & 0xffffffffL));
             height = java.lang.Math.max(height, max_ascent + max_descent);
         }
         return ((((long)width) << 32) | (long)(height & 0xffffffffL));
@@ -100,13 +105,13 @@ public class Font {
     public long textsize(String s) {
         Long l = (Long)sizeCache.get(s);
         if (l != null) return ((Long)l).longValue();
     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;
     }
 
     public Glyph getGlyph(char c) {
         sizeCache.put(s, new Long(ret));
         return ret;
     }
 
     public Glyph getGlyph(char c) {
-        rasterizeGlyphs(c+"", null, 0, 0, 0, 0, 0, 0, 0);
+        rasterizeGlyphs(c+"", null, null, null, 0, 0);
         Glyph g = glyphs[c];
         g.render();
         return g;
         Glyph g = glyphs[c];
         g.render();
         return g;
index 24c4b01..fb61837 100644 (file)
@@ -20,8 +20,9 @@ import org.ibex.util.*;
 public interface PixelBuffer {
     public abstract void drawLine(int x1, int y1, int x2, int y2, int color);
     public abstract void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color);
 public interface PixelBuffer {
     public abstract void drawLine(int x1, int y1, int x2, int y2, int color);
     public abstract void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color);
-    public abstract void drawPicture(Picture p, int x, int y, int x1, int y1, int w, int h);  // names may be wrong
-    public abstract void drawGlyph(Font.Glyph source, int dx1, int dy1, int cx1, int cy1, int cx2, int cy2, int rgb, int bg);
+    public abstract void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int color);
+    public abstract void drawPicture(Picture p, Affine a, Mesh h);
+    public abstract void drawGlyph(Font.Glyph source, Affine a, Mesh h, int rgb, int bg);
     public abstract void stroke(Polygon p, int color);
     public abstract void fill(Polygon p, Paint paint);
 }
     public abstract void stroke(Polygon p, int color);
     public abstract void fill(Polygon p, Paint paint);
 }
index 165207f..f891b29 100644 (file)
@@ -290,8 +290,9 @@ public abstract class Surface implements Callable {
             if (y+h > root.height) h = root.height - y;
             if (w <= 0 || h <= 0) continue;
 
             if (y+h > root.height) h = root.height - y;
             if (w <= 0 || h <= 0) continue;
 
-            root.render(x, y, x + w, y + h, this.getPixelBuffer(), identity);
-            getPixelBuffer().drawPicture(scarImage, 0, root.height - scarImage.height, x, y, x+w, y+h);
+            // FIXME: set clip to -- x, y, x + w, y + h, 
+            root.render(this.getPixelBuffer(), identity);
+            //getPixelBuffer().drawPicture(scarImage, 0, root.height - scarImage.height, x, y, x+w, y+h);
             
             if (abort) {
                 // x,y,w,h is only partially reconstructed, so we must be careful not to re-blit it
             
             if (abort) {
                 // x,y,w,h is only partially reconstructed, so we must be careful not to re-blit it
@@ -360,16 +361,25 @@ public abstract class Surface implements Callable {
         DirtyList screenDirtyRegions = new DirtyList();
 
         public PixelBuffer getPixelBuffer() { return this; }
         DirtyList screenDirtyRegions = new DirtyList();
 
         public PixelBuffer getPixelBuffer() { return this; }
+        public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int argb) {
+            backbuffer.fillTriangle(x1, y1, x2, y2, x3, y3, argb);
+        }
+        public void drawPicture(Picture p, Affine a, Mesh h) {
+            throw new Error("drawPicture() not implemented");
+        }
+        public void drawGlyph(Font.Glyph source,Affine a,Mesh h,int rgb,int bg) {
+            //screenDirtyRegions.dirty(cx1, cy1, cx2 - cx1, cy2 - cy1);
+            backbuffer.drawGlyph(source, a, h, rgb, bg);
+        }
+        /*
         public void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) {
             screenDirtyRegions.dirty(cx1, cy1, cx2 - cx1, cy2 - cy1);
             backbuffer.drawPicture(source, dx, dy, cx1, cy1, cx2, cy2);
         }
 
         public void drawGlyph(Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int argb, int bc) {
         public void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) {
             screenDirtyRegions.dirty(cx1, cy1, cx2 - cx1, cy2 - cy1);
             backbuffer.drawPicture(source, dx, dy, cx1, cy1, cx2, cy2);
         }
 
         public void drawGlyph(Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int argb, int bc) {
-            screenDirtyRegions.dirty(cx1, cy1, cx2 - cx1, cy2 - cy1);
-            backbuffer.drawGlyph(source, dx, dy, cx1, cy1, cx2, cy2, argb, bc);
         }
         }
-
+        */
         public void stroke(Polygon p, int color) {
             // FIXME
         }
         public void stroke(Polygon p, int color) {
             // FIXME
         }
index 9ca0366..113ca78 100644 (file)
@@ -27,8 +27,7 @@ public class AWT extends JVM {
 
     protected void postInit() {
         if (Log.on) Log.diag(Platform.class, "               color depth = " +
 
     protected void postInit() {
         if (Log.on) Log.diag(Platform.class, "               color depth = " +
-                            Toolkit.getDefaultToolkit().getColorModel().getPixelSize() + "bpp");
-    }
+                            Toolkit.getDefaultToolkit().getColorModel().getPixelSize() + "bpp"); }
 
     protected void _criticalAbort(String message) {
         if (Log.on) Log.info(this, message);
 
     protected void _criticalAbort(String message) {
         if (Log.on) Log.info(this, message);
@@ -189,6 +188,24 @@ public class AWT extends JVM {
     
     protected static class AWTPixelBuffer implements PixelBuffer {
         
     
     protected static class AWTPixelBuffer implements PixelBuffer {
         
+        private int[] xpoints = new int[3];
+        private int[] ypoints = new int[3];
+        public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int argb) {
+            xpoints[0] = x1;
+            xpoints[1] = x2;
+            xpoints[2] = x3;
+            ypoints[0] = y1;
+            ypoints[1] = y2;
+            ypoints[2] = y3;
+            Graphics g = getGraphics();
+            g.setColor(new java.awt.Color((argb & 0x00ff0000) >> 16,
+                                          (argb & 0x0000ff00) >> 8,
+                                          argb & 0x000000ff/*,
+                                                             (argb & 0xff000000) >> 24*/));
+            g.fillPolygon(xpoints, ypoints, 3);
+        }
+
+        public void drawPicture(Picture p, Affine a, Mesh h) { throw new Error("drawPicture() not implemented"); }
         protected Image i = null;
         protected Graphics g = null;
         protected AWTSurface surface = null;
         protected Image i = null;
         protected Graphics g = null;
         protected AWTSurface surface = null;
@@ -251,8 +268,9 @@ public class AWT extends JVM {
         }
 
         // this doens't seem to work on Windows
         }
 
         // this doens't seem to work on Windows
-        public void drawGlyph(org.ibex.graphics.Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2,
-                              int rgb, int argb) {
+        public void drawGlyph(org.ibex.graphics.Font.Glyph source,Affine a,Mesh h,int rgb,int bg) {
+            //throw new Error("drawGlyph() not implemented");
+            /*
             Image i = ((AWTGlyph)source).getImage();
             if (((AWTGlyph)source).i2 == null)
                 ((AWTGlyph)source).i2 = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB);
             Image i = ((AWTGlyph)source).getImage();
             if (((AWTGlyph)source).i2 == null)
                 ((AWTGlyph)source).i2 = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB);
@@ -270,6 +288,7 @@ public class AWT extends JVM {
             g.fillRect(dx+i2.getWidth(null), cy1, cx2 - (dx+i2.getWidth(null)), cy2 - cy1);
             g.fillRect(cx1, dy+i2.getHeight(null), cx2 - cx1, cy2 - (dy+i2.getHeight(null)));
             g.setClip(0, 0, 1000, 1000);
             g.fillRect(dx+i2.getWidth(null), cy1, cx2 - (dx+i2.getWidth(null)), cy2 - cy1);
             g.fillRect(cx1, dy+i2.getHeight(null), cx2 - cx1, cy2 - (dy+i2.getHeight(null)));
             g.setClip(0, 0, 1000, 1000);
+            */
         }
     }
     
         }
     }
     
index 0efff67..d1b646c 100644 (file)
@@ -117,7 +117,7 @@ public class Java2 extends AWT {
         private static GeneralPath gp = new GeneralPath();
 
         // this doens't seem to work on Windows
         private static GeneralPath gp = new GeneralPath();
 
         // this doens't seem to work on Windows
-        public void drawGlyph(org.ibex.graphics.Font.Glyph source, Affine a, Hull h, int rgb, int bg) {
+        public void drawGlyph(org.ibex.graphics.Font.Glyph source, Affine a, Mesh h, int rgb, int bg) {
             Image i = ((AWTGlyph)source).getImage();
             Image i2 = ((AWTGlyph)source).i2;
             if (((AWTGlyph)source).i2 == null) {
             Image i = ((AWTGlyph)source).getImage();
             Image i2 = ((AWTGlyph)source).i2;
             if (((AWTGlyph)source).i2 == null) {
index b852437..a7aa726 100644 (file)
@@ -58,6 +58,9 @@ abstract class OpenGL {
     public static abstract class GLPixelBuffer implements PixelBuffer {
         protected int width;
         protected int height;
     public static abstract class GLPixelBuffer implements PixelBuffer {
         protected int width;
         protected int height;
+        public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int argb) { throw new Error("not implemented"); }
+        public void drawPicture(Picture p, Affine a, Mesh h) { throw new Error("drawPicture() not implemented"); }
+        public void drawGlyph(Font.Glyph source,Affine a,Mesh h,int rgb,int bg) { throw new Error("drawGlyph() not implemented"); }
         public int getWidth() { return width; }
         public int getHeight() { return height; }
         
         public int getWidth() { return width; }
         public int getHeight() { return height; }
         
index 86f79a3..9700d1e 100644 (file)
@@ -236,6 +236,10 @@ public class Win32 extends GCJ {
     // Win32PixelBuffer //////////////////////////////////////////////////////////////////////////
 
     public static class Win32PixelBuffer implements PixelBuffer {
     // Win32PixelBuffer //////////////////////////////////////////////////////////////////////////
 
     public static class Win32PixelBuffer implements PixelBuffer {
+        public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int argb) { throw new Error("not implemented"); }
+
+        public void drawPicture(Picture p, Affine a, Mesh h) { throw new Error("drawPicture() not implemented"); }
+        public void drawGlyph(Font.Glyph source,Affine a,Mesh h,int rgb,int bg) { throw new Error("drawGlyph() not implemented"); }
 
     public void drawLine(int x1, int y1, int x2, int y2, int color) { }
     public void drawGlyph(Font.Glyph source, int dx1, int dy1, int cx1, int cy1, int cx2, int cy2, int rgb, int pc){}
 
     public void drawLine(int x1, int y1, int x2, int y2, int color) { }
     public void drawGlyph(Font.Glyph source, int dx1, int dy1, int cx1, int cy1, int cx2, int cy2, int rgb, int pc){}
index cc1bea6..ffb11fb 100644 (file)
@@ -142,6 +142,10 @@ public class X11 extends POSIX {
      *  (since they are only written to once.
      */
     public static class X11PixelBuffer implements PixelBuffer {
      *  (since they are only written to once.
      */
     public static class X11PixelBuffer implements PixelBuffer {
+        public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int argb) { throw new Error("not implemented"); }
+
+        public void drawPicture(Picture p, Affine a, Mesh h) { throw new Error("drawPicture() not implemented"); }
+        public void drawGlyph(Font.Glyph source,Affine a,Mesh h,int rgb,int bg) { throw new Error("drawGlyph() not implemented"); }
 
     public void drawLine(int x1, int y1, int x2, int y2, int color) { }
     public void drawGlyph(Font.Glyph source, int dx1, int dy1, int cx1, int cy1, int cx2, int cy2, int rgb, int pc){}
 
     public void drawLine(int x1, int y1, int x2, int y2, int color) { }
     public void drawGlyph(Font.Glyph source, int dx1, int dy1, int cx1, int cy1, int cx2, int cy2, int rgb, int pc){}