2003/09/27 06:42:26
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:38:19 +0000 (07:38 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:38:19 +0000 (07:38 +0000)
darcs-hash:20040130073819-2ba56-68023fd33311bc6619d2217c2132e2db10dbc001.gz

src/org/xwt/Box.java.pp
src/org/xwt/PixelBuffer.java
src/org/xwt/Res.java
src/org/xwt/Surface.java
src/org/xwt/VectorGraphics.java
src/org/xwt/plat/AWT.java

index f2c45a0..71da82f 100644 (file)
@@ -92,6 +92,7 @@ public final class Box extends JS.Scope {
     static int TILE_FLAG         = 0x00000020;
     static int FONT_CHANGED_FLAG = 0x00000040;  // set when font changes, cleared during repack
     static int ISROOT_FLAG       = 0x00000080;
     static int TILE_FLAG         = 0x00000020;
     static int FONT_CHANGED_FLAG = 0x00000040;  // set when font changes, cleared during repack
     static int ISROOT_FLAG       = 0x00000080;
+    static int NOCLIP_FLAG       = 0x00000100;
 
 
     // Geometry ////////////////////////////////////////////////////////////////////////////
 
 
     // Geometry ////////////////////////////////////////////////////////////////////////////
@@ -150,10 +151,12 @@ public final class Box extends JS.Scope {
     public final void dirty() { dirty(0, 0, width, height); }
     public final void dirty(int x, int y, int w, int h) {
         for(Box cur = this; cur != null; cur = cur.parent) {
     public final void dirty() { dirty(0, 0, width, height); }
     public final void dirty(int x, int y, int w, int h) {
         for(Box cur = this; cur != null; cur = cur.parent) {
-            w = min(x + w, cur.width) - max(x, 0);
-            h = min(y + h, cur.height) - max(y, 0);
-            x = max(x, 0);
-            y = max(y, 0);
+            if ((flags & NOCLIP_FLAG) == 0) {
+                w = min(x + w, cur.width) - max(x, 0);
+                h = min(y + h, cur.height) - max(y, 0);
+                x = max(x, 0);
+                y = max(y, 0);
+            }
             if (w <= 0 || h <= 0) return;
             if (cur.parent == null && cur.surface != null) cur.surface.dirty(x, y, w, h);
             x += cur.x;
             if (w <= 0 || h <= 0) return;
             if (cur.parent == null && cur.surface != null) cur.surface.dirty(x, y, w, h);
             x += cur.x;
@@ -391,14 +394,16 @@ public final class Box extends JS.Scope {
         int globaly = parenty + (parent == null ? 0 : y);
 
         // intersect the x,y,w,h rendering window with ourselves; quit if it's empty
         int globaly = parenty + (parent == null ? 0 : y);
 
         // intersect the x,y,w,h rendering window with ourselves; quit if it's empty
-        clipw = min(max(clipx, parent == null ? 0 : globalx) + clipw, (parent == null ? 0 : globalx) + width) - globalx;
-        cliph = min(max(clipy, parent == null ? 0 : globaly) + cliph, (parent == null ? 0 : globaly) + height) - globaly;
-        clipx = max(clipx, parent == null ? 0 : globalx);
-        clipy = max(clipy, parent == null ? 0 : globaly);
+        if ((flags & NOCLIP_FLAG) == 0) {
+            clipw = min(max(clipx, parent == null ? 0 : globalx) + clipw, (parent == null ? 0 : globalx) + width) - globalx;
+            cliph = min(max(clipy, parent == null ? 0 : globaly) + cliph, (parent == null ? 0 : globaly) + height) - globaly;
+            clipx = max(clipx, parent == null ? 0 : globalx);
+            clipy = max(clipy, parent == null ? 0 : globaly);
+        }
         if (clipw <= 0 || cliph <= 0) return;
 
         if ((fillcolor & 0xFF000000) != 0x00000000)
         if (clipw <= 0 || cliph <= 0) return;
 
         if ((fillcolor & 0xFF000000) != 0x00000000)
-            buf.fillRect(clipx, clipy, clipx + clipw, clipy + cliph, fillcolor);
+            buf.fillTrapezoid(clipx, clipx + clipw, clipy, clipx, clipx + clipw, clipy + cliph, fillcolor);
 
         if (image != null)
             if ((flags & TILE_FLAG) != 0) renderTiledImage(globalx, globaly, clipx, clipy, clipw, cliph, buf);
 
         if (image != null)
             if ((flags & TILE_FLAG) != 0) renderTiledImage(globalx, globaly, clipx, clipy, clipw, cliph, buf);
@@ -408,10 +413,12 @@ public final class Box extends JS.Scope {
             renderText(globalx, globaly, clipx, clipy, clipw, cliph, buf);
 
         // now subtract the pad region from the clip region before proceeding
             renderText(globalx, globaly, clipx, clipy, clipw, cliph, buf);
 
         // now subtract the pad region from the clip region before proceeding
-        clipw = min(max(clipx, globalx + hpad) + clipw, globalx + width - hpad) - clipx;
-        cliph = min(max(clipy, globaly + vpad) + cliph, globaly + height - vpad) - clipy;
-        clipx = max(clipx, globalx + hpad);
-        clipy = max(clipy, globaly + vpad);
+        if ((flags & NOCLIP_FLAG) == 0) {
+            clipw = min(max(clipx, globalx + hpad) + clipw, globalx + width - hpad) - clipx;
+            cliph = min(max(clipy, globaly + vpad) + cliph, globaly + height - vpad) - clipy;
+            clipx = max(clipx, globalx + hpad);
+            clipy = max(clipy, globaly + vpad);
+        }
 
         for(Box b = getChild(0); b != null; b = b.nextSibling())
             b.render(globalx, globaly, clipx, clipy, clipw, cliph, buf);   
 
         for(Box b = getChild(0); b != null; b = b.nextSibling())
             b.render(globalx, globaly, clipx, clipy, clipw, cliph, buf);   
@@ -1056,6 +1063,15 @@ public final class Box extends JS.Scope {
                         b.dirty();
                     } });
         
                         b.dirty();
                     } });
         
+            specialBoxProperties.put("noclip", new SpecialBoxProperty() {
+                    public Object get(Box b) { return ((b.flags & NOCLIP_FLAG) != 0) ? Boolean.TRUE : Boolean.FALSE; }
+                    public void put(Box b, Object value) {
+                        if (((b.flags & NOCLIP_FLAG) != 0) == stob(value)) return;
+                        if (stob(value)) b.flags |= NOCLIP_FLAG; else b.flags &= ~NOCLIP_FLAG;
+                        MARK_FOR_REFLOW_b;
+                        b.dirty();
+                    } });
+        
             specialBoxProperties.put("invisible", new SpecialBoxProperty() {
                     public Object get(Box b) {
                         for (Box cur = b; cur != null; cur = cur.parent) {
             specialBoxProperties.put("invisible", new SpecialBoxProperty() {
                     public Object get(Box b) {
                         for (Box cur = b; cur != null; cur = cur.parent) {
index 3d6e09a..065b027 100644 (file)
@@ -3,8 +3,7 @@ package org.xwt;
 
 /**
  *  <p>
 
 /**
  *  <p>
- *  A block of pixels which can be drawn on and rapidly copied to the
- *  screen.
+ *  A block of pixels which can be drawn on.
  *  </p>
  *
  *  <p>
  *  </p>
  *
  *  <p>
@@ -13,19 +12,80 @@ package org.xwt;
  *  method. These implementations may choose to use off-screen video
  *  ram for this purpose (for example, a Pixmap on X11).
  *  </p>
  *  method. These implementations may choose to use off-screen video
  *  ram for this purpose (for example, a Pixmap on X11).
  *  </p>
+ *
+ *  <p>
+ *  Many of these functions come in pairs, one that uses ints and one
+ *  that uses floats.  The int functions are intended for situations
+ *  in which the CTM is the identity transform.
+ *  </p>
  */
 public abstract class PixelBuffer {
 
  */
 public abstract class PixelBuffer {
 
-    /** Draw the region of source within s onto the region d on this PixelBuffer, scaling as needed */
-    public abstract void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2);
-
-    /** Fill the region (x1, y1, x2, y2) with <tt>color</tt> (AARRGGBB format); the alpha channel component is ignored */
-    public abstract void fillRect(int x1, int y1, int x2, int y2, int color);
-
+    // FIXME: try to remove
     /** returns the height of the PixelBuffer */
     public abstract int getHeight();
 
     /** returns the height of the PixelBuffer */
     public abstract int getHeight();
 
+    // FIXME: try to remove
     /** returns the width of the PixelBuffer */
     public abstract int getWidth();
 
     /** returns the width of the PixelBuffer */
     public abstract int getWidth();
 
+
+
+    /** Draw the region of source within s onto the region d on this PixelBuffer, scaling as needed */
+    public abstract void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2);
+
+    /** fill a trapezoid whose top and bottom edges are horizontal */
+    public abstract void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color);
+
+    // FIXME: we want floats (inter-pixel spacing) for antialiasing, but this hoses the fastpath line drawing... argh!
+    /** draws a line of width <tt>w</tt>; note that the coordinates here are <i>post-transform</i> */
+    public void drawLine(int x1, int y1, int x2, int y2, int w, int color, boolean capped) {
+
+       if (y1 > y2) { int t = x1; x1 = x2; x2 = t; t = y1; y1 = y2; y2 = t; }
+
+       if (x1 == x2) {
+            fillTrapezoid(x1 - w / 2, x2 + w / 2, y1 - (capped ? w / 2 : 0), x1 - w / 2, x2 + w / 2, y2 + (capped ? w / 2 : 0), color);
+            return;
+        }
+
+        // fastpath for single-pixel width lines
+        if (w == 1) {
+            float slope = (float)(y2 - y1) / (float)(x2 - x1);
+            int last_x = x1;
+            for(int y=y1; y<=y2; y++) {
+                int new_x = (int)((float)(y - y1) / slope) + x1;
+                if (slope >= 0) fillTrapezoid(last_x + 1, y != y2 ? new_x + 1 : new_x, y,
+                                              last_x + 1, y != y2 ? new_x + 1 : new_x, y + 1, color);
+                else fillTrapezoid(y != y2 ? new_x : new_x + 1, last_x, y,
+                                   y != y2 ? new_x : new_x + 1, last_x, y + 1, color);
+                last_x = new_x;
+            }
+            return;
+        }
+
+        // actually half-width
+       float width = (float)w / 2;
+       float phi = (float)Math.atan((y2 - y1) / (x2 - x1));
+       if (phi < 0.0) phi += (float)Math.PI * 2;
+       float theta = (float)Math.PI / 2 - phi;
+
+       // dx and dy are the x and y distance between each endpoint and the corner of the stroke
+       int dx = (int)(width * Math.cos(theta));
+       int dy = (int)(width * Math.sin(theta));
+
+       // slice is the longest possible length of a horizontal line across the stroke
+       int slice = (int)(2 * width / Math.cos(theta));
+
+       if (capped) {
+           x1 -= width * Math.cos(phi);
+           x2 += width * Math.cos(phi);
+           y1 -= width * Math.sin(phi);
+           y2 += width * Math.sin(phi);
+       }
+
+       fillTrapezoid(x1 + dx, x1 + dx, y1 - dy, x1 - dx, x1 - dx + slice, y1 + dy, color);           // top corner
+       fillTrapezoid(x2 + dx - slice, x2 + dx, y2 - dy, x2 - dx, x2 - dx, y2 + dy, color);           // bottom corner
+       fillTrapezoid(x1 - dx, x1 - dx + slice, y1 + dy, x2 + dx - slice, x2 + dx, y2 - dy, color);   // middle
+    }
+
 }
 }
index 37cdc29..1f1a927 100644 (file)
@@ -6,6 +6,7 @@ import java.util.*;
 import java.util.zip.*;
 import org.xwt.js.*;
 import org.xwt.util.*;
 import java.util.zip.*;
 import org.xwt.js.*;
 import org.xwt.util.*;
+import org.bouncycastle.util.encoders.Base64;
 
 /** base class for XWT resources */
 public abstract class Res extends JS {
 
 /** base class for XWT resources */
 public abstract class Res extends JS {
@@ -52,6 +53,7 @@ public abstract class Res extends JS {
         if (url.startsWith("https://")) return new HTTP(url);
         if (url.startsWith("file:") && permitLocalFilesystem) return new File(url.substring(5));
         if (url.startsWith("cab:")) return new CAB(stringToRes(url.substring(4)));
         if (url.startsWith("https://")) return new HTTP(url);
         if (url.startsWith("file:") && permitLocalFilesystem) return new File(url.substring(5));
         if (url.startsWith("cab:")) return new CAB(stringToRes(url.substring(4)));
+        if (url.startsWith("data:")) return new ByteArray(Base64.decode(url.substring(5)));
         throw new JS.Exn("invalid resource specifier " + url);
     }
 
         throw new JS.Exn("invalid resource specifier " + url);
     }
 
index 8b888e7..6ed2377 100644 (file)
@@ -361,14 +361,15 @@ public abstract class Surface extends PixelBuffer {
             screenDirtyRegions.dirty(dx1, dy1, dx2 - dx1, dy2 - dy1);
             backbuffer.drawPicture(source, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2); }
 
             screenDirtyRegions.dirty(dx1, dy1, dx2 - dx1, dy2 - dy1);
             backbuffer.drawPicture(source, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2); }
 
-        public void fillRect(int x1, int y1, int x2, int y2, int color) {
-            screenDirtyRegions.dirty(x1, y1, x2 - x1, y2 - y1);
-            backbuffer.fillRect(x1, y1, x2, y2, color); }
+        public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color) {
+            screenDirtyRegions.dirty(Math.min(x1, x3), y1, Math.max(x2, x4) - Math.min(x1, x3), y2 - y1);
+            backbuffer.fillTrapezoid(x1, x2, y1, x3, x4, y2, color); }
 
         public void render() {
             super.render();
             render_();
         }
 
         public void render() {
             super.render();
             render_();
         }
+
         public void render_() {
             int[][] dirt = screenDirtyRegions.flush();
             for(int i = 0; dirt != null && i < dirt.length; i++) {
         public void render_() {
             int[][] dirt = screenDirtyRegions.flush();
             for(int i = 0; dirt != null && i < dirt.length; i++) {
index cd62d89..fc19ba4 100644 (file)
@@ -3,23 +3,18 @@ package org.xwt;
 import org.xwt.util.*;
 import java.util.*;
 
 import org.xwt.util.*;
 import java.util.*;
 
-// NOTE: we have to make sure that a box is never smaller than the
-//       bounding box of its path unless the user specifically forced
-//       it to be so.
-
+// FIXME: offer a "subpixel" mode where we pass floats to the Platform and don't do any snapping
 // FIXME: fracture when realizing instead of when parsing?
 // FIXME: fracture when realizing instead of when parsing?
+
 /*
     v1.0
 /*
     v1.0
-    - Base64 "data:" URL support
     - textpath
     - gradients
     - patterns
     - clipping/masking
     - filters (filtering of a group must be performed AFTER the group is assembled; sep. canvas)
     - textpath
     - gradients
     - patterns
     - clipping/masking
     - filters (filtering of a group must be performed AFTER the group is assembled; sep. canvas)
-    - style sheets
 
     v1.1
 
     v1.1
-    - markers (do this in the parser; remember the order: fill, stroke, marker)
     - bump caps [requires Paint that can fill circles...] [remember to distinguish between closed/unclosed]
     - line joins
         - mitre    (hard)
     - bump caps [requires Paint that can fill circles...] [remember to distinguish between closed/unclosed]
     - line joins
         - mitre    (hard)
@@ -31,16 +26,18 @@ import java.util.*;
         - clip on trapezoids, not pixels
     - faster gradients and patterns:
         - transform each corner of the trapezoid and then interpolate
         - clip on trapezoids, not pixels
     - faster gradients and patterns:
         - transform each corner of the trapezoid and then interpolate
-
- */
+*/
 
 /** XWT's fully conformant Static SVG Viewer; see SVG spec, section G.7 */
 public final class VectorGraphics {
 
 /** XWT's fully conformant Static SVG Viewer; see SVG spec, section G.7 */
 public final class VectorGraphics {
-    /*
-    // Public entry points /////////////////////////////////////////////////////////////////
 
 
-    // FIXME
-    public static SVG.Font currentFont = null;
+    // Private Constants ///////////////////////////////////////////////////////////////////
+
+    private static final int DEFAULT_PATHLEN = 1000;
+    private static final float PI = (float)Math.PI;
+
+
+    // Public entry points /////////////////////////////////////////////////////////////////
 
     public static VectorPath parseVectorPath(String s) {
         PathTokenizer t = new PathTokenizer(s);
 
     public static VectorPath parseVectorPath(String s) {
         PathTokenizer t = new PathTokenizer(s);
@@ -59,272 +56,10 @@ public final class VectorGraphics {
         return ret;
     }
 
         return ret;
     }
 
-    public static void parseNode(String name, String[] keys, Object[] vals, Template t) {
-        Hash h = new Hash();
-        for(int i=0; i<keys.length; i++) if (vals[i] != null) h.put(keys[i], vals[i]);
-
-        Hash props = new Hash();
-        props.put("transform", h.get("transform"));
-        props.put("fill", h.get("fill"));
-        props.put("stroke", h.get("stroke"));
-        if ("visible".equals(h.get("overflow")) || "auto".equals(h.get("overflow")))
-            Log.log(SVG.class, "warning: overflow={auto|visible} not supported; ignoring");
-        if (h.get("display") != null) props.put("invisible", new Boolean("none".equals(h.get("display"))));
-
-
-        // FIXME: "the automatic transformation that is created due to
-        // a viewBox does not affect the x, y, width and height
-        // attributes".  Also, transform+viewbox together?
-
-        if (h.get("preserveAspectRatio") != null) {
-            StringTokenizer st = new StringTokenizer((String)h.get("preserveAspectRatio"), " ");
-            String align = st.nextToken();
-            if ("defer".equals(align)) align = st.nextToken();
-            if (!align.equals("none")) {
-                // FIXME, need to beef up XWT's align property
-                align = "";
-                if (align.startsWith("yMin")) align = "top";
-                else if (align.startsWith("yMax")) align = "bottom";
-                if (align.startsWith("xMin")) align += "left";
-                else if (align.startsWith("xMax")) align += "right";
-                props.put("align", align);
-            }
-            // FIXME: need to implement scaling property on boxes, also size-to-viewbox
-            props.put("scaling", "uniform");
-            if (st.hasMoreTokens()) {
-                String meetOrSlice = st.nextToken();
-                if (meetOrSlice.equals("meet")) props.put("scaling", "meet");          // keep within viewport
-                else if (meetOrSlice.equals("slice")) props.put("scaling", "slice");   // expand beyond viewport
-            }
-        }
-
-        // FIXME: insert an extra layer of boxen and put this transform on the inner layer
-        if (h.get("viewBox") != null) {
-            PathTokenizer pt = new PathTokenizer(h.get("viewBox").toString());
-            String transform = (String)props.get("transform");
-            if (transform == null) transform = "";
-            transform = "translate(" + (-1 * pt.parseFloat()) + ", " + (-1 * pt.parseFloat()) + ") " + 
-                "scale(" + pt.parseFloat() + "%, " + pt.parseFloat() + "%) ";
-        }
-        
-        String path = (String)h.get("d");
-        if (name.equals("g")) {
-            path = null;
-
-        } else if (name.equals("font")) {
-            SVG.Font f = currentFont = new SVG.Font();
-            if (h.get("horiz-origin-x") != null) f.horiz_origin_x = Float.parseFloat(h.get("horiz-origin-x").toString());
-            if (h.get("horiz-origin-y") != null) f.horiz_origin_y = Float.parseFloat(h.get("horiz-origin-y").toString());
-            if (h.get("horiz-adv-x") != null) f.horiz_adv_x = Float.parseFloat(h.get("horiz-adv-x").toString());
-            if (h.get("vert-origin-x") != null) f.vert_origin_x = Float.parseFloat(h.get("vert-origin-x").toString());
-            if (h.get("vert-origin-y") != null) f.vert_origin_y = Float.parseFloat(h.get("vert-origin_y").toString());
-            if (h.get("vert-adv-y") != null) f.vert_adv_y = Float.parseFloat(h.get("vert-adv-y").toString());
-
-        } else if (name.equals("hkern")) {
-        //FIXME
-
-        } else if (name.equals("vkern")) {
-        //FIXME
-
-        } else if (name.equals("font-face")) {
-        //FIXME
-
-        } else if (name.equals("glyph") || name.equals("missing-glyph")) {
-            String glyphName = name.equals("missing-glyph") ? "missing-glyph" : (String)h.get("glyph-name");
-            SVG.Font.Glyph g = new SVG.Font.Glyph(glyphName, (String)h.get("unicode"), t, currentFont);
-            if (h.get("horiz-adv-x") != null) g.horiz_adv_x = Float.parseFloat(h.get("horiz-adv-x").toString());
-            if (h.get("vert-origin-x") != null) g.vert_origin_x = Float.parseFloat(h.get("vert-origin-x").toString());
-            if (h.get("vert-origin-y") != null) g.vert_origin_y = Float.parseFloat(h.get("vert-origin-y").toString());
-            if (h.get("vert-adv-y") != null) g.vert_adv_y = Float.parseFloat(h.get("vert-adv-y").toString());
-            if ("v".equals(h.get("orientation"))) g.isVerticallyOriented = true;
-
-        } else if (name.equals("svg")) {
-            // FIXME: handle percentages
-            // FIXME: what if these aren't provided?
-            // FIXME (in general)
-            float x = Float.parseFloat(h.get("x").toString());
-            float y = Float.parseFloat(h.get("y").toString());
-            float width = Float.parseFloat(h.get("width").toString());
-            float height = Float.parseFloat(h.get("height").toString());
-            h.put("viewBox", x + ", " + y + ", " + (x + width) + ", " + (y + height));
-            path = "";
-            
-        } else if (name.equals("path")) {
-            path = h.get("d").toString();
-           
-        } else if (name.equals("rect")) {
-            float x = Float.parseFloat(h.get("x").toString());
-            float y = Float.parseFloat(h.get("y").toString());
-            float width = Float.parseFloat(h.get("width").toString());
-            float height = Float.parseFloat(h.get("height").toString());
-            float rx = Float.parseFloat(h.get("rx").toString());
-            float ry = Float.parseFloat(h.get("ry").toString());
-            path =
-                "M" + (x + rx) + "," + y +
-                "H" + (x + width - rx) +
-                "A" + rx + "," + rx + ",0,0,1," + (x + width) + "," + (y + ry) +
-                "V" + (y + width - ry) +
-                "A" + rx + "," + rx + ",0,0,1," + (x + width - rx) + "," +
-                (y + height) +
-                "H" + (x + rx) +
-                "A" + rx + "," + rx + ",0,0,1," + x + "," + (y + height - ry) +
-                "V" + (y + ry) +
-                "A" + rx + "," + rx + ",0,0,1," + (x + rx) + "," + (y + ry) +
-                "Z";
-           
-        } else if (name.equals("circle")) {
-            float r = Float.parseFloat(h.get("r").toString());
-            float cx = Float.parseFloat(h.get("cx").toString());
-            float cy = Float.parseFloat(h.get("cy").toString());
-            path = "A " + r + " " + r + " 1 1 " + cx + " " + cy;
-           
-        } else if (name.equals("ellipse")) {
-            float rx = Float.parseFloat(h.get("rx").toString());
-            float ry = Float.parseFloat(h.get("ry").toString());
-            float cx = Float.parseFloat(h.get("cx").toString());
-            float cy = Float.parseFloat(h.get("cy").toString());
-            path = "A " + rx + " " + ry + " 1 1 " + cx + " " + cy;
-           
-        } else if (name.equals("line")) {
-            float x1 = Float.parseFloat(h.get("x1").toString());
-            float y1 = Float.parseFloat(h.get("y1").toString());
-            float x2 = Float.parseFloat(h.get("x2").toString());
-            float y2 = Float.parseFloat(h.get("y2").toString());
-            path = "M " + x1 + " " + y1 + " L " + x2 + " " + y2;
-                
-        } else if (name.equals("polyline") || name.equals("polygon")) {
-            StringTokenizer st = new StringTokenizer(h.get("points").toString(), ", ", false);
-            String s = "M ";
-            while(st.hasMoreTokens()) s += st.nextToken() + " " + st.nextToken() + " ";
-            path = s + (name.equals("polygon") ? "z" : "");
-
-        } else {
-            Log.log(SVG.class, "unknown element in SVG namespace: " + name);
-        }
-        props.put("path", path);
-        t.keys = new String[props.size()];
-        System.arraycopy(props.keys(), 0, t.keys, 0, t.keys.length);
-        t.vals = new String[props.size()];
-        for(int i=0; i<t.keys.length; i++) t.vals[i] = props.get(t.keys[i]);
-        
-
-        // FIXME!!!!
-        if (h.get("viewBox") != null) {
-        StringTokenizer st = new StringTokenizer(h.get("viewBox").toString(), ", ", false);
-        if (t.transform == null) t.transform = "";
-        Point p1, p2;
-        SVG.RasterPath.fromString(path).getBoundingBox(p1, p2);
-        
-        float minx = st.parseFloat();
-        float miny = st.parseFloat();
-        float width = st.parseFloat();
-        float height = st.parseFloat();
-        t.transform += "translate(" + (-1 * p1.x) + ", " + (-1 * p1.y) + ") " +
-        "scale(" + ((p2.x - p1.x) / width) + ", " + ((p2.y - p1.y) / height) + ") " + 
-        "translate(" + minx + ", " + miny + ") ";
-        
-        // FIXME: preserveAspectRatio
-        }
-
-    }
-    
-    
-    public static class Font {
-        Font() { }
-        float horiz_origin_x = 0,  horiz_origin_y = 0, horiz_adv_x = 0;
-        float vert_origin_x = 0, vert_origin_y = 0, vert_adv_y = 0;
-
-        // FIXME: avoid using substring() in here ore creating any objects
-        public void render(String text, DoubleBuffer buf, int x, int y, int fillcolor, int strokecolor, int size) {
-            // FIXME: points, not pixels
-            Affine a = buf.a;
-            float scaleFactor = (float)(1.0/1000.0) * (float)size;
-            for(int pos=0; pos<text.length(); pos++) { 
-                Glyph g;
-                for(g = (Glyph)glyphByUnicode.get(text.substring(pos, pos+1));
-                    g != null && !g.unicode.equals(text.substring(pos, pos + g.unicode.length()));
-                    g = g.next);
-                if (g == null) {
-                    g = (Glyph)glyphByName.get("missing-glyph");
-                } else {
-                    pos += g.unicode.length() - 1;
-                }
-                if (g != null) {
-                    System.out.println("  " + g.unicode);
-                    g.render(buf, x, y, fillcolor, strokecolor, scaleFactor);
-                    x += (int)(g.horiz_adv_x * size / 1000.0);
-                } else {
-                    x += (int)(horiz_adv_x * size / 1000.0);
-                }
-            }
-            buf.setTransform(a);
-        }
-
-        / ** all glyphs, keyed by their <tt>name</tt> property * /
-        Hashtable glyphByName = new Hashtable();
-
-        / ** linked list of glyphs, stored by the first character of their <tt>unicode</tt> property * /
-        Hashtable glyphByUnicode = new Hashtable();
-
-        / ** a Glyph in an SVG font * /
-        public static class Glyph {
-
-            // FIXME: lang attribute
-            boolean isVerticallyOriented = false;
-            Template t = null;
-            Box b = null;
-
-            float horiz_adv_x = 0;
-            float vert_origin_x = 0;
-            float vert_origin_y = 0;
-            float vert_adv_y = 0;
-
-            String unicode = null;
-
-            / ** forms the linked list in glyphByUnicode; glyphs appear in the order specified in the font * /
-            public Glyph next = null;
-
-            Glyph(String name, String unicode, Template t, SVG.Font f) {
-                if (unicode != null)
-                    if (f.glyphByUnicode.get(unicode.substring(0, 1)) == null) {
-                        f.glyphByUnicode.put(unicode.substring(0, 1), this);
-                    } else {
-                        Glyph g;
-                        for(g = (Glyph)f.glyphByUnicode.get(unicode.substring(0, 1)); g.next != null; g = g.next);
-                        g.next = this;
-                    }
-                if (name != null) f.glyphByUnicode.put(name, this);
-                this.unicode = unicode;
-                this.t = t;
-                horiz_adv_x = f.horiz_adv_x;
-                vert_origin_x = f.vert_origin_x;
-                vert_origin_y = f.vert_origin_y;
-                vert_adv_y = f.vert_adv_y;
-            }
-            public void render(DoubleBuffer buf, int x, int y, int fillcolor, int strokecolor, float scaleFactor) {
-                // FEATURE: make b double-buffered for increased performance
-                if (b == null) {
-                    b = new Box(t, new org.xwt.util.Vec(), new org.xwt.util.Vec(), null, 0, 0);
-                    b.put("absolute", Boolean.TRUE);
-                    b.prerender();
-                    t = null;
-                }
-                // FIXME
-                b.put("width", new Integer(1000));
-                b.put("height", new Integer(1000));
-                b.fillcolor = fillcolor;
-                b.strokecolor = strokecolor;
-
-                // we toss an extra flip on the ctm so that fonts stick "up" instead of down
-                b.render(0, 0, buf.getWidth(), buf.getHeight(), buf,
-                         Affine.flip(false, true).multiply(Affine.scale(scaleFactor, scaleFactor).multiply(Affine.translate(x, y))).multiply(buf.a));
-            }
-        }
-    }
 
     // Affine //////////////////////////////////////////////////////////////////////////////
 
 
     // Affine //////////////////////////////////////////////////////////////////////////////
 
-    / ** an affine transform; all operations are destructive * /
+    /** an affine transform; all operations are destructive */
     public static final class Affine {
 
        //  [ a b e ]
     public static final class Affine {
 
        //  [ a b e ]
@@ -350,7 +85,7 @@ public final class VectorGraphics {
            return new Affine(c, s, -s, c, 0, 0);
        }
 
            return new Affine(c, s, -s, c, 0, 0);
        }
 
-       / ** this = this * a * /
+       /** this = this * a */
         public Affine multiply(Affine A) {
            float _a = this.a * A.a + this.b * A.c;
            float _b = this.a * A.b + this.b * A.d;
         public Affine multiply(Affine A) {
            float _a = this.a * A.a + this.b * A.c;
            float _b = this.a * A.b + this.b * A.d;
@@ -408,7 +143,7 @@ public final class VectorGraphics {
                 char c = s.charAt(i);
                 if (Character.isWhitespace(c) || c == ',' || (c == '-' && i != start)) break;
                 if (!((c >= '0' && c <= '9') || c == '.' || c == 'e' || c == 'E' || c == '-')) {
                 char c = s.charAt(i);
                 if (Character.isWhitespace(c) || c == ',' || (c == '-' && i != start)) break;
                 if (!((c >= '0' && c <= '9') || c == '.' || c == 'e' || c == 'E' || c == '-')) {
-                    if (c == '%') {                             // FIXME
+                    if (c == '%') {                                // FIXME
                     } else if (s.regionMatches(i, "pt", 0, i+2)) { // FIXME
                     } else if (s.regionMatches(i, "em", 0, i+2)) { // FIXME
                     } else if (s.regionMatches(i, "pc", 0, i+2)) { // FIXME
                     } else if (s.regionMatches(i, "pt", 0, i+2)) { // FIXME
                     } else if (s.regionMatches(i, "em", 0, i+2)) { // FIXME
                     } else if (s.regionMatches(i, "pc", 0, i+2)) { // FIXME
@@ -429,7 +164,7 @@ public final class VectorGraphics {
 
     // Abstract Path //////////////////////////////////////////////////////////////////////////////
 
 
     // Abstract Path //////////////////////////////////////////////////////////////////////////////
 
-    / ** an abstract path; may contain splines and arcs * /
+    /** an abstract path; may contain splines and arcs */
     public static class VectorPath {
 
         // the number of vertices on this path
     public static class VectorPath {
 
         // the number of vertices on this path
@@ -456,7 +191,7 @@ public final class VectorGraphics {
        static final byte TYPE_CUBIC = 3;
        static final byte TYPE_QUADRADIC = 4;
 
        static final byte TYPE_CUBIC = 3;
        static final byte TYPE_QUADRADIC = 4;
 
-        / ** Creates a concrete vector path transformed through the given matrix. * /
+        /** Creates a concrete vector path transformed through the given matrix. */
        public RasterPath realize(Affine a) {
 
             RasterPath ret = new RasterPath();
        public RasterPath realize(Affine a) {
 
             RasterPath ret = new RasterPath();
@@ -678,7 +413,8 @@ public final class VectorGraphics {
             default:
                 // FIXME
            }
             default:
                 // FIXME
            }
-            / *
+
+            /*
             // invariant: after this loop, no two lines intersect other than at a vertex
             // FIXME: cleanup
             int index = numvertices - 2;
             // invariant: after this loop, no two lines intersect other than at a vertex
             // FIXME: cleanup
             int index = numvertices - 2;
@@ -709,7 +445,7 @@ public final class VectorGraphics {
                     }
                 }
             }
                     }
                 }
             }
-            * /
+            */
 
        }
     }
 
        }
     }
@@ -717,9 +453,9 @@ public final class VectorGraphics {
 
 
 
 
 
 
-    // Concrete Vector Path //////////////////////////////////////////////////////////////////////////////
+    // Rasterized Vector Path //////////////////////////////////////////////////////////////////////////////
     
     
-    / ** a vector path * /
+    /** a vector path */
     public static class RasterPath {
 
        // the vertices of this path
     public static class RasterPath {
 
        // the vertices of this path
@@ -727,18 +463,15 @@ public final class VectorGraphics {
        int[] y = new int[DEFAULT_PATHLEN];
        int numvertices = 0;
 
        int[] y = new int[DEFAULT_PATHLEN];
        int numvertices = 0;
 
-        / **
-         *  A list of the vertices on this path which *start* an edge (rather than a moveto), sorted by increasing y.
+        /**
+         *  A list of the vertices on this path which *start* an *edge* (rather than a moveto), sorted by increasing y.
          *  example: x[edges[1]],y[edges[1]] - x[edges[i]+1],y[edges[i]+1] is the second-topmost edge
          *  note that if x[i],y[i] - x[i+1],y[i+1] is a MOVETO, then no element in edges will be equal to i
          *  example: x[edges[1]],y[edges[1]] - x[edges[i]+1],y[edges[i]+1] is the second-topmost edge
          *  note that if x[i],y[i] - x[i+1],y[i+1] is a MOVETO, then no element in edges will be equal to i
-         * /
+         */
        int[] edges = new int[DEFAULT_PATHLEN];
         int numedges = 0;
 
        int[] edges = new int[DEFAULT_PATHLEN];
         int numedges = 0;
 
-        / ** FIXME: if a path is closed "manually" you get caps on the ends; otherwise you get a marker... * /
-       boolean closed = false;
-       
-        / ** simple quicksort, from http://sourceforge.net/snippet/detail.php?type=snippet&id=100240 * /
+        /** simple quicksort, from http://sourceforge.net/snippet/detail.php?type=snippet&id=100240 */
         int sort(int left, int right, boolean partition) {
            if (partition) {
                int i, j, middle;
         int sort(int left, int right, boolean partition) {
            if (partition) {
                int i, j, middle;
@@ -761,7 +494,7 @@ public final class VectorGraphics {
            }
         }
 
            }
         }
 
-        / ** finds the x value at which the line intercepts the line y=_y * /
+        /** finds the x value at which the line intercepts the line y=_y */
        private int intercept(int i, float _y, boolean includeTop, boolean includeBottom) {
             if (includeTop ? (_y < Math.min(y[i], y[i+1])) : (_y <= Math.min(y[i], y[i+1])))
                 return Integer.MIN_VALUE;
        private int intercept(int i, float _y, boolean includeTop, boolean includeBottom) {
             if (includeTop ? (_y < Math.min(y[i], y[i+1])) : (_y <= Math.min(y[i], y[i+1])))
                 return Integer.MIN_VALUE;
@@ -771,8 +504,8 @@ public final class VectorGraphics {
                                     ((float)(y[i + 1] - y[i])) ) * ((float)(_y - y[i])) + x[i]);
        }
 
                                     ((float)(y[i + 1] - y[i])) ) * ((float)(_y - y[i])) + x[i]);
        }
 
-        / ** fill the interior of the path * /
-       public void fill(DoubleBuffer buf, RasterPath pen, Paint paint) {
+        /** fill the interior of the path */
+       public void fill(PixelBuffer buf, Paint paint) {
             if (numedges == 0) return;
            int y0 = y[edges[0]], y1 = y0;
            boolean useEvenOdd = false;
             if (numedges == 0) return;
            int y0 = y[edges[0]], y1 = y0;
            boolean useEvenOdd = false;
@@ -822,79 +555,91 @@ public final class VectorGraphics {
             }
         }
         
             }
         }
         
-        / ** stroke the outline of the path * /
-        public void stroke(DoubleBuffer buf, int width, int color, boolean mitre,
-                           String dashArray, int dashOffset, float segLength) {
-            if (dashArray != null) {
-                float ratio = 1;
-                if (segLength > 0) {
-                    float actualLength = 0;
-                    for(int i=0; i<numvertices; i++) {
-                        // skip over MOVETOs -- they do not contribute to path length
-                        if (x[i] == x[i+1] && y[i] == y[i+1]) continue;
-                        if (x[i+1] == x[i+2] && y[i+1] == y[i+2]) continue;
-                        int x1 = x[i];
-                        int x2 = x[i + 1];
-                        int y1 = y[i];
-                        int y2 = y[i + 1];
-                        actualLength += java.lang.Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
-                    }
-                    ratio = actualLength / segLength;
-                }
-                PathTokenizer pt = new PathTokenizer(dashArray);
-                Vector v = new Vector();
-                while (pt.hasMoreTokens()) v.addElement(new Float(pt.parseFloat()));
-                float[] dashes = new float[v.size() % 2 == 0 ? v.size() : 2 * v.size()];
-                for(int i=0; i<dashes.length; i++) dashes[i] = ((Float)v.elementAt(i % v.size())).floatValue();
-                float length = 0;
-                int dashpos = dashOffset;
-                boolean on = dashpos % 2 == 0;
+        /** stroke the outline of the path */
+        public void stroke(PixelBuffer buf, int width, int color) { stroke(buf, width, color, null, 0, 0); }
+        public void stroke(PixelBuffer buf, int width, int color, String dashArray, int dashOffset, float segLength) {
+
+            if (dashArray == null) {
+                for(int i=0; i<numedges; i++)
+                    buf.drawLine((int)x[edges[i]],
+                                 (int)y[edges[i]], (int)x[edges[i]+1], (int)y[edges[i]+1], width, color, false);
+                return;
+            }
+
+            float ratio = 1;
+            if (segLength > 0) {
+                float actualLength = 0;
                 for(int i=0; i<numvertices; i++) {
                     // skip over MOVETOs -- they do not contribute to path length
                     if (x[i] == x[i+1] && y[i] == y[i+1]) continue;
                     if (x[i+1] == x[i+2] && y[i+1] == y[i+2]) continue;
                 for(int i=0; i<numvertices; i++) {
                     // skip over MOVETOs -- they do not contribute to path length
                     if (x[i] == x[i+1] && y[i] == y[i+1]) continue;
                     if (x[i+1] == x[i+2] && y[i+1] == y[i+2]) continue;
-                    int x1 = (int)x[i];
-                    int x2 = (int)x[i + 1];
-                    int y1 = (int)y[i];
-                    int y2 = (int)y[i + 1];
-                    float segmentLength = (float)java.lang.Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
-                    int _x1 = x1, _y1 = y1;
-                    float pos = 0;
-                    do {
-                        pos = Math.min(segmentLength, pos + dashes[dashpos] * ratio);
-                        if (pos != segmentLength) dashpos = (dashpos + 1) % dashes.length;
-                        int _x2 = (int)((x2 * pos + x1 * (segmentLength - pos)) / segmentLength);
-                        int _y2 = (int)((y2 * pos + y1 * (segmentLength - pos)) / segmentLength);
-                        if (on) buf.drawLine(_x1, _y1, _x2, _y2, width, color);
-                        on = !on;
-                        _x1 = _x2; _y1 = _y2;
-                    } while(pos < segmentLength);
+                    int x1 = x[i];
+                    int x2 = x[i + 1];
+                    int y1 = y[i];
+                    int y2 = y[i + 1];
+                    actualLength += java.lang.Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
                 }
                 }
-
-            } else {
-                for(int i=0; i<numedges; i++)
-                    buf.drawLine((int)x[edges[i]],
-                                 (int)y[edges[i]], (int)x[edges[i]+1], (int)y[edges[i]+1], width, color);
+                ratio = actualLength / segLength;
+            }
+            PathTokenizer pt = new PathTokenizer(dashArray);
+            Vector v = new Vector();
+            while (pt.hasMoreTokens()) v.addElement(new Float(pt.parseFloat()));
+            float[] dashes = new float[v.size() % 2 == 0 ? v.size() : 2 * v.size()];
+            for(int i=0; i<dashes.length; i++) dashes[i] = ((Float)v.elementAt(i % v.size())).floatValue();
+            float length = 0;
+            int dashpos = dashOffset;
+            boolean on = dashpos % 2 == 0;
+            for(int i=0; i<numvertices; i++) {
+                // skip over MOVETOs -- they do not contribute to path length
+                if (x[i] == x[i+1] && y[i] == y[i+1]) continue;
+                if (x[i+1] == x[i+2] && y[i+1] == y[i+2]) continue;
+                int x1 = (int)x[i];
+                int x2 = (int)x[i + 1];
+                int y1 = (int)y[i];
+                int y2 = (int)y[i + 1];
+                float segmentLength = (float)java.lang.Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
+                int _x1 = x1, _y1 = y1;
+                float pos = 0;
+                do {
+                    pos = Math.min(segmentLength, pos + dashes[dashpos] * ratio);
+                    if (pos != segmentLength) dashpos = (dashpos + 1) % dashes.length;
+                    int _x2 = (int)((x2 * pos + x1 * (segmentLength - pos)) / segmentLength);
+                    int _y2 = (int)((y2 * pos + y1 * (segmentLength - pos)) / segmentLength);
+                    if (on) buf.drawLine(_x1, _y1, _x2, _y2, width, color, false);
+                    on = !on;
+                    _x1 = _x2; _y1 = _y2;
+                } while(pos < segmentLength);
             }
        }
     }
             }
        }
     }
-
-
+    
+    
     // Paint //////////////////////////////////////////////////////////////////////////////
 
     public static interface Paint {
        public abstract void
     // Paint //////////////////////////////////////////////////////////////////////////////
 
     public static interface Paint {
        public abstract void
-            fillTrapezoid(int tx1, int tx2, int ty1, int tx3, int tx4, int ty2, DoubleBuffer buf);
+            fillTrapezoid(int tx1, int tx2, int ty1, int tx3, int tx4, int ty2, PixelBuffer buf);
     }
 
     public static class SingleColorPaint implements Paint {
         int color;
         public SingleColorPaint(int color) { this.color = color; }
     }
 
     public static class SingleColorPaint implements Paint {
         int color;
         public SingleColorPaint(int color) { this.color = color; }
-        public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, DoubleBuffer buf) {
+        public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, PixelBuffer buf) {
             buf.fillTrapezoid(x1, x2, y1, x3, x4, y2, color);
         }
     }
             buf.fillTrapezoid(x1, x2, y1, x3, x4, y2, color);
         }
     }
-    / *
+
+}
+
+
+
+
+
+
+
+
+
+    /*
     public static abstract class GradientPaint extends Paint {
         public GradientPaint(boolean reflect, boolean repeat, Affine gradientTransform,
                              int[] stop_colors, float[] stop_offsets) {
     public static abstract class GradientPaint extends Paint {
         public GradientPaint(boolean reflect, boolean repeat, Affine gradientTransform,
                              int[] stop_colors, float[] stop_offsets) {
@@ -913,7 +658,7 @@ public final class VectorGraphics {
        int[] stop_colors;
        float[] stop_offsets;
 
        int[] stop_colors;
        float[] stop_offsets;
 
-       public void fillTrapezoid(float tx1, float tx2, float ty1, float tx3, float tx4, float ty2, DoubleBuffer buf) {
+       public void fillTrapezoid(float tx1, float tx2, float ty1, float tx3, float tx4, float ty2, PixelBuffer buf) {
             Affine a = buf.a;
            Affine inverse = a.copy().invert();
            float slope1 = (tx3 - tx1) / (ty2 - ty1);
             Affine a = buf.a;
            Affine inverse = a.copy().invert();
            float slope1 = (tx3 - tx1) / (ty2 - ty1);
@@ -975,164 +720,5 @@ public final class VectorGraphics {
        float cx, cy, r, fx, fy;
 
     }
        float cx, cy, r, fx, fy;
 
     }
-    * /
-
-    // Private Constants //////////////////////////////////////////////////////////////////////////////////
-
-    private static final int DEFAULT_PATHLEN = 1000;
-
-    / ** Copied verbatim from the SVG specification * /
-    public static Hashtable colors = new Hashtable(400);
-    static {
-       colors.put("aliceblue", new Integer((240 << 16) | (248 << 8) | 255));
-       colors.put("antiquewhite", new Integer((250 << 16) | (235 << 8) | 215));
-       colors.put("aqua", new Integer((0 << 16) | (255 << 8) | 255));
-       colors.put("aquamarine", new Integer((127 << 16) | (255 << 8) | 212));
-       colors.put("azure", new Integer((240 << 16) | (255 << 8) | 255));
-       colors.put("beige", new Integer((245 << 16) | (245 << 8) | 220));
-       colors.put("bisque", new Integer((255 << 16) | (228 << 8) | 196));
-       colors.put("black", new Integer((0 << 16) | (0 << 8) | 0));
-       colors.put("blanchedalmond", new Integer((255 << 16) | (235 << 8) | 205));
-       colors.put("blue", new Integer((0 << 16) | (0 << 8) | 255));
-       colors.put("blueviolet", new Integer((138 << 16) | (43 << 8) | 226));
-       colors.put("brown", new Integer((165 << 16) | (42 << 8) | 42));
-       colors.put("burlywood", new Integer((222 << 16) | (184 << 8) | 135));
-       colors.put("cadetblue", new Integer((95 << 16) | (158 << 8) | 160));
-       colors.put("chartreuse", new Integer((127 << 16) | (255 << 8) | 0));
-       colors.put("chocolate", new Integer((210 << 16) | (105 << 8) | 30));
-       colors.put("coral", new Integer((255 << 16) | (127 << 8) | 80));
-       colors.put("cornflowerblue", new Integer((100 << 16) | (149 << 8) | 237));
-       colors.put("cornsilk", new Integer((255 << 16) | (248 << 8) | 220));
-       colors.put("crimson", new Integer((220 << 16) | (20 << 8) | 60));
-       colors.put("cyan", new Integer((0 << 16) | (255 << 8) | 255));
-       colors.put("darkblue", new Integer((0 << 16) | (0 << 8) | 139));
-       colors.put("darkcyan", new Integer((0 << 16) | (139 << 8) | 139));
-       colors.put("darkgoldenrod", new Integer((184 << 16) | (134 << 8) | 11));
-       colors.put("darkgray", new Integer((169 << 16) | (169 << 8) | 169));
-       colors.put("darkgreen", new Integer((0 << 16) | (100 << 8) | 0));
-       colors.put("darkgrey", new Integer((169 << 16) | (169 << 8) | 169));
-       colors.put("darkkhaki", new Integer((189 << 16) | (183 << 8) | 107));
-       colors.put("darkmagenta", new Integer((139 << 16) | (0 << 8) | 139));
-       colors.put("darkolivegreen", new Integer((85 << 16) | (107 << 8) | 47));
-       colors.put("darkorange", new Integer((255 << 16) | (140 << 8) | 0));
-       colors.put("darkorchid", new Integer((153 << 16) | (50 << 8) | 204));
-       colors.put("darkred", new Integer((139 << 16) | (0 << 8) | 0));
-       colors.put("darksalmon", new Integer((233 << 16) | (150 << 8) | 122));
-       colors.put("darkseagreen", new Integer((143 << 16) | (188 << 8) | 143));
-       colors.put("darkslateblue", new Integer((72 << 16) | (61 << 8) | 139));
-       colors.put("darkslategray", new Integer((47 << 16) | (79 << 8) | 79));
-       colors.put("darkslategrey", new Integer((47 << 16) | (79 << 8) | 79));
-       colors.put("darkturquoise", new Integer((0 << 16) | (206 << 8) | 209));
-       colors.put("darkviolet", new Integer((148 << 16) | (0 << 8) | 211));
-       colors.put("deeppink", new Integer((255 << 16) | (20 << 8) | 147));
-       colors.put("deepskyblue", new Integer((0 << 16) | (191 << 8) | 255));
-       colors.put("dimgray", new Integer((105 << 16) | (105 << 8) | 105));
-       colors.put("dimgrey", new Integer((105 << 16) | (105 << 8) | 105));
-       colors.put("dodgerblue", new Integer((30 << 16) | (144 << 8) | 255));
-       colors.put("firebrick", new Integer((178 << 16) | (34 << 8) | 34));
-       colors.put("floralwhite", new Integer((255 << 16) | (250 << 8) | 240));
-       colors.put("forestgreen", new Integer((34 << 16) | (139 << 8) | 34));
-       colors.put("fuchsia", new Integer((255 << 16) | (0 << 8) | 255));
-       colors.put("gainsboro", new Integer((220 << 16) | (220 << 8) | 220));
-       colors.put("ghostwhite", new Integer((248 << 16) | (248 << 8) | 255));
-       colors.put("gold", new Integer((255 << 16) | (215 << 8) | 0));
-       colors.put("goldenrod", new Integer((218 << 16) | (165 << 8) | 32));
-       colors.put("gray", new Integer((128 << 16) | (128 << 8) | 128));
-       colors.put("grey", new Integer((128 << 16) | (128 << 8) | 128));
-       colors.put("green", new Integer((0 << 16) | (128 << 8) | 0));
-       colors.put("greenyellow", new Integer((173 << 16) | (255 << 8) | 47));
-       colors.put("honeydew", new Integer((240 << 16) | (255 << 8) | 240));
-       colors.put("hotpink", new Integer((255 << 16) | (105 << 8) | 180));
-       colors.put("indianred", new Integer((205 << 16) | (92 << 8) | 92));
-       colors.put("indigo", new Integer((75 << 16) | (0 << 8) | 130));
-       colors.put("ivory", new Integer((255 << 16) | (255 << 8) | 240));
-       colors.put("khaki", new Integer((240 << 16) | (230 << 8) | 140));
-       colors.put("lavender", new Integer((230 << 16) | (230 << 8) | 250));
-       colors.put("lavenderblush", new Integer((255 << 16) | (240 << 8) | 245));
-       colors.put("lawngreen", new Integer((124 << 16) | (252 << 8) | 0));
-       colors.put("lemonchiffon", new Integer((255 << 16) | (250 << 8) | 205));
-       colors.put("lightblue", new Integer((173 << 16) | (216 << 8) | 230));
-       colors.put("lightcoral", new Integer((240 << 16) | (128 << 8) | 128));
-       colors.put("lightcyan", new Integer((224 << 16) | (255 << 8) | 255));
-       colors.put("lightgoldenrodyellow", new Integer((250 << 16) | (250 << 8) | 210));
-       colors.put("lightgray", new Integer((211 << 16) | (211 << 8) | 211));
-       colors.put("lightgreen", new Integer((144 << 16) | (238 << 8) | 144));
-       colors.put("lightgrey", new Integer((211 << 16) | (211 << 8) | 211));
-       colors.put("lightpink", new Integer((255 << 16) | (182 << 8) | 193));
-       colors.put("lightsalmon", new Integer((255 << 16) | (160 << 8) | 122));
-       colors.put("lightseagreen", new Integer((32 << 16) | (178 << 8) | 170));
-       colors.put("lightskyblue", new Integer((135 << 16) | (206 << 8) | 250));
-       colors.put("lightslategray", new Integer((119 << 16) | (136 << 8) | 153));
-       colors.put("lightslategrey", new Integer((119 << 16) | (136 << 8) | 153));
-       colors.put("lightsteelblue", new Integer((176 << 16) | (196 << 8) | 222));
-       colors.put("lightyellow", new Integer((255 << 16) | (255 << 8) | 224));
-       colors.put("lime", new Integer((0 << 16) | (255 << 8) | 0));
-       colors.put("limegreen", new Integer((50 << 16) | (205 << 8) | 50));
-       colors.put("linen", new Integer((250 << 16) | (240 << 8) | 230));
-       colors.put("magenta", new Integer((255 << 16) | (0 << 8) | 255));
-       colors.put("maroon", new Integer((128 << 16) | (0 << 8) | 0));
-       colors.put("mediumaquamarine", new Integer((102 << 16) | (205 << 8) | 170));
-       colors.put("mediumblue", new Integer((0 << 16) | (0 << 8) | 205));
-       colors.put("mediumorchid", new Integer((186 << 16) | (85 << 8) | 211));
-       colors.put("mediumpurple", new Integer((147 << 16) | (112 << 8) | 219));
-       colors.put("mediumseagreen", new Integer((60 << 16) | (179 << 8) | 113));
-       colors.put("mediumslateblue", new Integer((123 << 16) | (104 << 8) | 238));
-       colors.put("mediumspringgreen", new Integer((0 << 16) | (250 << 8) | 154));
-       colors.put("mediumturquoise", new Integer((72 << 16) | (209 << 8) | 204));
-       colors.put("mediumvioletred", new Integer((199 << 16) | (21 << 8) | 133));
-       colors.put("midnightblue", new Integer((25 << 16) | (25 << 8) | 112));
-       colors.put("mintcream", new Integer((245 << 16) | (255 << 8) | 250));
-       colors.put("mistyrose", new Integer((255 << 16) | (228 << 8) | 225));
-       colors.put("moccasin", new Integer((255 << 16) | (228 << 8) | 181));
-       colors.put("navajowhite", new Integer((255 << 16) | (222 << 8) | 173));
-       colors.put("navy", new Integer((0 << 16) | (0 << 8) | 128));
-       colors.put("oldlace", new Integer((253 << 16) | (245 << 8) | 230));
-       colors.put("olive", new Integer((128 << 16) | (128 << 8) | 0));
-       colors.put("olivedrab", new Integer((107 << 16) | (142 << 8) | 35));
-       colors.put("orange", new Integer((255 << 16) | (165 << 8) | 0));
-       colors.put("orangered", new Integer((255 << 16) | (69 << 8) | 0));
-       colors.put("orchid", new Integer((218 << 16) | (112 << 8) | 214));
-       colors.put("palegoldenrod", new Integer((238 << 16) | (232 << 8) | 170));
-       colors.put("palegreen", new Integer((152 << 16) | (251 << 8) | 152));
-       colors.put("paleturquoise", new Integer((175 << 16) | (238 << 8) | 238));
-       colors.put("palevioletred", new Integer((219 << 16) | (112 << 8) | 147));
-       colors.put("papayawhip", new Integer((255 << 16) | (239 << 8) | 213));
-       colors.put("peachpuff", new Integer((255 << 16) | (218 << 8) | 185));
-       colors.put("peru", new Integer((205 << 16) | (133 << 8) | 63));
-       colors.put("pink", new Integer((255 << 16) | (192 << 8) | 203));
-       colors.put("plum", new Integer((221 << 16) | (160 << 8) | 221));
-       colors.put("powderblue", new Integer((176 << 16) | (224 << 8) | 230));
-       colors.put("purple", new Integer((128 << 16) | (0 << 8) | 128));
-       colors.put("red", new Integer((255 << 16) | (0 << 8) | 0));
-       colors.put("rosybrown", new Integer((188 << 16) | (143 << 8) | 143));
-       colors.put("royalblue", new Integer((65 << 16) | (105 << 8) | 225));
-       colors.put("saddlebrown", new Integer((139 << 16) | (69 << 8) | 19));
-       colors.put("salmon", new Integer((250 << 16) | (128 << 8) | 114));
-       colors.put("sandybrown", new Integer((244 << 16) | (164 << 8) | 96));
-       colors.put("seagreen", new Integer((46 << 16) | (139 << 8) | 87));
-       colors.put("seashell", new Integer((255 << 16) | (245 << 8) | 238));
-       colors.put("sienna", new Integer((160 << 16) | (82 << 8) | 45));
-       colors.put("silver", new Integer((192 << 16) | (192 << 8) | 192));
-       colors.put("skyblue", new Integer((135 << 16) | (206 << 8) | 235));
-       colors.put("slateblue", new Integer((106 << 16) | (90 << 8) | 205));
-       colors.put("slategray", new Integer((112 << 16) | (128 << 8) | 144));
-       colors.put("slategrey", new Integer((112 << 16) | (128 << 8) | 144));
-       colors.put("snow", new Integer((255 << 16) | (250 << 8) | 250));
-       colors.put("springgreen", new Integer((0 << 16) | (255 << 8) | 127));
-       colors.put("steelblue", new Integer((70 << 16) | (130 << 8) | 180));
-       colors.put("tan", new Integer((210 << 16) | (180 << 8) | 140));
-       colors.put("teal", new Integer((0 << 16) | (128 << 8) | 128));
-       colors.put("thistle", new Integer((216 << 16) | (191 << 8) | 216));
-       colors.put("tomato", new Integer((255 << 16) | (99 << 8) | 71));
-       colors.put("turquoise", new Integer((64 << 16) | (224 << 8) | 208));
-       colors.put("violet", new Integer((238 << 16) | (130 << 8) | 238));
-       colors.put("wheat", new Integer((245 << 16) | (222 << 8) | 179));
-       colors.put("white", new Integer((255 << 16) | (255 << 8) | 255));
-       colors.put("whitesmoke", new Integer((245 << 16) | (245 << 8) | 245));
-       colors.put("yellow", new Integer((255 << 16) | (255 << 8) | 0));
-       colors.put("yellowgreen", new Integer((154 << 16) | (205 << 8) | 50));
-    }
-
-    private static final float PI = (float)Math.PI;
     */
     */
-}
+
index 6fe9be4..e186789 100644 (file)
@@ -170,10 +170,22 @@ public class AWT extends JVM {
         
         public void fillRect(int x, int y, int x2, int y2, int argb) {
             // FEATURE: use an LRU cache for Color objects
         
         public void fillRect(int x, int y, int x2, int y2, int argb) {
             // FEATURE: use an LRU cache for Color objects
-            g.setColor(new Color((argb & 0x00FF0000) >> 16, (argb & 0x0000FF00) >> 8, (argb & 0x000000FF)));
-            g.fillRect(x, y, x2 - x, y2 - y);
         }
 
         }
 
+        // FIXME: try to use os acceleration
+        public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int argb) {
+            g.setColor(new Color((argb & 0x00FF0000) >> 16, (argb & 0x0000FF00) >> 8, (argb & 0x000000FF)));
+            if (x1 == x3 && x2 == x4) {
+                g.fillRect(x1, y1, x4 - x1, y2 - y1);
+            } else for(int y=y1; y<y2; y++) {
+                int _x1 = (int)Math.floor((y - y1) * (x3 - x1) / (y2 - y1) + x1);
+                int _y1 = (int)Math.floor(y);
+                int _x2 = (int)Math.ceil((y - y1) * (x4 - x2) / (y2 - y1) + x2);
+                int _y2 = (int)Math.floor(y) + 1;
+                if (_x1 > _x2) { int _x0 = _x1; _x1 = _x2; _x2 = _x0; }
+                g.fillRect(_x1, _y1, _x2 - _x1, _y2 - _y1);
+            }
+        }
     }
     
     
     }