Index: trunk/src/com/kitfox/svg/ClipPath.java
===================================================================
--- trunk/src/com/kitfox/svg/ClipPath.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/ClipPath.java	(revision 7676)
@@ -131,6 +131,8 @@
      * all attributes with track information.
      *
+     * @param curTime
      * @return - true if this node has changed state as a result of the time
      * update
+     * @throws com.kitfox.svg.SVGException
      */
     public boolean updateTime(double curTime) throws SVGException
@@ -160,4 +162,10 @@
         }
 
+        for (int i = 0; i < children.size(); ++i)
+        {
+            SVGElement ele = (SVGElement) children.get(i);
+            ele.updateTime(curTime);
+        }
+        
         return shapeChange;
     }
Index: trunk/src/com/kitfox/svg/Group.java
===================================================================
--- trunk/src/com/kitfox/svg/Group.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/Group.java	(revision 7676)
@@ -160,8 +160,8 @@
         //Do not process offscreen groups
         boolean ignoreClip = diagram.ignoringClipHeuristic();
-        if (!ignoreClip && outsideClip(g))
-        {
-            return;
-        }
+//        if (!ignoreClip && outsideClip(g))
+//        {
+//            return;
+//        }
 
         beginLayer(g);
@@ -271,12 +271,16 @@
                 RenderableElement rendEle = (RenderableElement) ele;
                 Rectangle2D bounds = rendEle.getBoundingBox();
-                if (bounds != null)
+                if (bounds != null && (bounds.getWidth() != 0 || bounds.getHeight() != 0))
                 {
                     if (retRect == null)
                     {
                         retRect = bounds;
-                    } else
+                    }
+                    else
                     {
-                        retRect = retRect.createUnion(bounds);
+                        if (retRect.getWidth() != 0 || retRect.getHeight() != 0)
+                        {
+                            retRect = retRect.createUnion(bounds);
+                        }
                     }
                 }
Index: trunk/src/com/kitfox/svg/ImageSVG.java
===================================================================
--- trunk/src/com/kitfox/svg/ImageSVG.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/ImageSVG.java	(revision 7676)
@@ -124,5 +124,5 @@
                     {
                         Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
-                            "Could not parse xlink:href", e);
+                            "Could not parse xlink:href " + src, e);
 //                        e.printStackTrace();
                         imageSrc = null;
Index: trunk/src/com/kitfox/svg/RadialGradient.java
===================================================================
--- trunk/src/com/kitfox/svg/RadialGradient.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/RadialGradient.java	(revision 7676)
@@ -121,9 +121,5 @@
         Point2D.Float pt1 = new Point2D.Float(cx, cy);
         Point2D.Float pt2 = new Point2D.Float(fx, fy);
-        if (pt1.equals(pt2))
-        {
-            Color[] colors = getStopColors();
-            paint = colors.length > 0 ? colors[0] : Color.black;
-        } else if (gradientUnits == GU_USER_SPACE_ON_USE)
+        if (gradientUnits == GU_USER_SPACE_ON_USE)
         {
             paint = new com.kitfox.svg.batik.RadialGradientPaint(
Index: trunk/src/com/kitfox/svg/SVGDiagram.java
===================================================================
--- trunk/src/com/kitfox/svg/SVGDiagram.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/SVGDiagram.java	(revision 7676)
@@ -103,5 +103,5 @@
     public void render(Graphics2D g) throws SVGException
     {
-        root.render(g);
+        root.renderToViewport(g);
     }
     
Index: trunk/src/com/kitfox/svg/SVGElement.java
===================================================================
--- trunk/src/com/kitfox/svg/SVGElement.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/SVGElement.java	(revision 7676)
@@ -588,5 +588,5 @@
     static public AffineTransform parseSingleTransform(String val) throws SVGException
     {
-        final Matcher matchWord = Pattern.compile("[-.\\w]+").matcher("");
+        final Matcher matchWord = Pattern.compile("([a-zA-Z]+|-?\\d+(\\.\\d+)?|-?\\.\\d+)").matcher("");
 
         AffineTransform retXform = new AffineTransform();
Index: trunk/src/com/kitfox/svg/SVGRoot.java
===================================================================
--- trunk/src/com/kitfox/svg/SVGRoot.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/SVGRoot.java	(revision 7676)
@@ -44,5 +44,8 @@
 import java.awt.Shape;
 import java.awt.geom.AffineTransform;
+import java.awt.geom.NoninvertibleTransformException;
+import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
+import java.util.List;
 
 /**
@@ -239,4 +242,25 @@
         clipRect.setRect(xx, yy, ww, hh);
 
+//        if (viewBox == null)
+//        {
+//            viewXform.setToIdentity();
+//        }
+//        else
+//        {
+//            //If viewport window is set, we are drawing to entire viewport
+//            clipRect.setRect(deviceViewport);
+//            
+//            viewXform.setToIdentity();
+//            viewXform.setToTranslation(deviceViewport.x, deviceViewport.y);
+//            viewXform.scale(deviceViewport.width, deviceViewport.height);
+//            viewXform.scale(1 / viewBox.width, 1 / viewBox.height);
+//            viewXform.translate(-viewBox.x, -viewBox.y);
+//        }
+    }
+
+    public void renderToViewport(Graphics2D g) throws SVGException
+    {
+        prepareViewport();
+
         if (viewBox == null)
         {
@@ -245,14 +269,14 @@
         else
         {
-            viewXform.setToTranslation(clipRect.x, clipRect.y);
-            viewXform.scale(clipRect.width, clipRect.height);
+            Rectangle deviceViewport = g.getClipBounds();
+            //If viewport window is set, we are drawing to entire viewport
+            clipRect.setRect(deviceViewport);
+            
+            viewXform.setToIdentity();
+            viewXform.setToTranslation(deviceViewport.x, deviceViewport.y);
+            viewXform.scale(deviceViewport.width, deviceViewport.height);
             viewXform.scale(1 / viewBox.width, 1 / viewBox.height);
             viewXform.translate(-viewBox.x, -viewBox.y);
         }
-    }
-
-    public void render(Graphics2D g) throws SVGException
-    {
-        prepareViewport();
         
         AffineTransform cachedXform = g.getTransform();
@@ -262,4 +286,32 @@
         
         g.setTransform(cachedXform);
+    }
+
+    public void pick(Rectangle2D pickArea, AffineTransform ltw, boolean boundingBox, List retVec) throws SVGException
+    {
+        if (viewXform != null)
+        {
+            ltw = new AffineTransform(ltw);
+            ltw.concatenate(viewXform);
+        }
+        
+        super.pick(pickArea, ltw, boundingBox, retVec);
+    }
+    
+    public void pick(Point2D point, boolean boundingBox, List retVec) throws SVGException
+    {
+        Point2D xPoint = new Point2D.Double(point.getX(), point.getY());
+        if (viewXform != null)
+        {
+            try
+            {
+                viewXform.inverseTransform(point, xPoint);
+            } catch (NoninvertibleTransformException ex)
+            {
+                throw new SVGException(ex);
+            }
+        }
+        
+        super.pick(xPoint, boundingBox, retVec);
     }
 
Index: trunk/src/com/kitfox/svg/SVGUniverse.java
===================================================================
--- trunk/src/com/kitfox/svg/SVGUniverse.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/SVGUniverse.java	(revision 7676)
@@ -55,6 +55,5 @@
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.net.URLConnection;
-import java.net.URLStreamHandler;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -389,5 +388,5 @@
             {
                 //Workaround for resources stored in jars loaded by Webstart.
-                //https://bugs.openjdk.java.net/browse/JDK-6753651
+                //http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6753651
                 url = SVGUniverse.class.getResource("xmlBase.getPath()");
             }
@@ -627,43 +626,22 @@
     }
 
-//    public static void main(String argv[])
-//    {
-//        try
-//        {
-//            URL url = new URL("svgSalamander", "localhost", -1, "abc.svg",
-//                    new URLStreamHandler()
-//            {
-//                protected URLConnection openConnection(URL u)
-//                {
-//                    return null;
-//                }
-//            }
-//            );
-////            URL url2 = new URL("svgSalamander", "localhost", -1, "abc.svg");
-//            
-//            //Investigate URI resolution
-//            URI uriA, uriB, uriC, uriD, uriE;
-//            
-//            uriA = new URI("svgSalamander", "/names/mySpecialName", null);
-////            uriA = new URI("http://www.kitfox.com/salamander");
-////            uriA = new URI("svgSalamander://mySpecialName/grape");
-//            System.err.println(uriA.toString());
-//            System.err.println(uriA.getScheme());
-//            
-//            uriB = uriA.resolve("#begin");
-//            System.err.println(uriB.toString());
-//            
-//            uriC = uriA.resolve("tree#boing");
-//            System.err.println(uriC.toString());
-//            
-//            uriC = uriA.resolve("../tree#boing");
-//            System.err.println(uriC.toString());
-//        }
-//        catch (Exception e)
-//        {
-//            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 
-//                "Could not parse", e);
-//        }
-//    }
+    /**
+     * Get list of uris of all loaded documents and subdocuments.
+     * @return 
+     */
+    public ArrayList getLoadedDocumentURIs()
+    {
+        return new ArrayList(loadedDocs.keySet());
+    }
+    
+    /**
+     * Remove loaded document from cache.
+     * @param uri 
+     */
+    public void removeDocument(URI uri)
+    {
+        loadedDocs.remove(uri);
+    }
+    
     public boolean isVerbose()
     {
Index: trunk/src/com/kitfox/svg/ShapeElement.java
===================================================================
--- trunk/src/com/kitfox/svg/ShapeElement.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/ShapeElement.java	(revision 7676)
@@ -87,5 +87,5 @@
     void pick(Point2D point, boolean boundingBox, List retVec) throws SVGException
     {
-        StyleAttribute styleAttrib = new StyleAttribute();
+//        StyleAttribute styleAttrib = new StyleAttribute();
 //        if (getStyle(styleAttrib.setName("fill")) && getShape().contains(point))
         if ((boundingBox ? getBoundingBox() : getShape()).contains(point))
Index: trunk/src/com/kitfox/svg/Text.java
===================================================================
--- trunk/src/com/kitfox/svg/Text.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/Text.java	(revision 7676)
@@ -42,4 +42,5 @@
 import java.awt.geom.AffineTransform;
 import java.awt.geom.GeneralPath;
+import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 import java.util.Iterator;
@@ -209,5 +210,5 @@
         } else
         {
-            fontWeight = TXWE_BOLD;
+            fontWeight = TXWE_NORMAL;
         }
 
@@ -352,5 +353,5 @@
             {
                 AffineTransform at = new AffineTransform();
-                at.translate(-textPath.getBounds2D().getWidth() / 2, 0);
+                at.translate(-textPath.getBounds().getWidth() / 2, 0);
                 textPath.transform(at);
                 break;
@@ -359,5 +360,5 @@
             {
                 AffineTransform at = new AffineTransform();
-                at.translate(-textPath.getBounds2D().getWidth(), 0);
+                at.translate(-textPath.getBounds().getWidth(), 0);
                 textPath.transform(at);
                 break;
@@ -390,5 +391,6 @@
             if (obj instanceof String)
             {
-                String text = (String) obj;
+                String text = (String)obj;
+                text = text.trim();
 
                 Shape textShape = font.createGlyphVector(frc, text).getOutline(cursorX, cursorY);
@@ -415,10 +417,13 @@
 
 
-                Tspan tspan = (Tspan) obj;
-                tspan.setCursorX(cursorX);
-                tspan.setCursorY(cursorY);
-                tspan.addShape(textPath);
-                cursorX = tspan.getCursorX();
-                cursorY = tspan.getCursorY();
+                Tspan tspan = (Tspan)obj;
+                Point2D cursor = new Point2D.Float(cursorX, cursorY);
+//                tspan.setCursorX(cursorX);
+//                tspan.setCursorY(cursorY);
+                tspan.appendToShape(textPath, cursor);
+//                cursorX = tspan.getCursorX();
+//                cursorY = tspan.getCursorY();
+                cursorX = (float)cursor.getX();
+                cursorY = (float)cursor.getY();
 
             }
@@ -430,5 +435,5 @@
             {
                 AffineTransform at = new AffineTransform();
-                at.translate(-textPath.getBounds2D().getWidth() / 2, 0);
+                at.translate(-textPath.getBounds().getWidth() / 2, 0);
                 textPath.transform(at);
                 break;
@@ -437,5 +442,5 @@
             {
                 AffineTransform at = new AffineTransform();
-                at.translate(-textPath.getBounds2D().getWidth(), 0);
+                at.translate(-Math.ceil(textPath.getBounds().getWidth()), 0);
                 textPath.transform(at);
                 break;
Index: trunk/src/com/kitfox/svg/TransformableElement.java
===================================================================
--- trunk/src/com/kitfox/svg/TransformableElement.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/TransformableElement.java	(revision 7676)
@@ -71,5 +71,5 @@
     public AffineTransform getXForm()
     {
-        return xform != null ? new AffineTransform(xform) : null;
+        return xform == null ? null : new AffineTransform(xform);
     }
     /*
Index: trunk/src/com/kitfox/svg/Tspan.java
===================================================================
--- trunk/src/com/kitfox/svg/Tspan.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/Tspan.java	(revision 7676)
@@ -44,4 +44,5 @@
 import java.awt.geom.AffineTransform;
 import java.awt.geom.GeneralPath;
+import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 
@@ -60,6 +61,6 @@
     float[] rotate = null;
     private String text = "";
-    float cursorX;
-    float cursorY;
+//    float cursorX;
+//    float cursorY;
 
 //    Shape tspanShape;
@@ -76,23 +77,23 @@
     }
 
-    public float getCursorX()
-    {
-        return cursorX;
-    }
-
-    public float getCursorY()
-    {
-        return cursorY;
-    }
-
-    public void setCursorX(float cursorX)
-    {
-        this.cursorX = cursorX;
-    }
-
-    public void setCursorY(float cursorY)
-    {
-        this.cursorY = cursorY;
-    }
+//    public float getCursorX()
+//    {
+//        return cursorX;
+//    }
+//
+//    public float getCursorY()
+//    {
+//        return cursorY;
+//    }
+//
+//    public void setCursorX(float cursorX)
+//    {
+//        this.cursorX = cursorX;
+//    }
+//
+//    public void setCursorY(float cursorY)
+//    {
+//        this.cursorY = cursorY;
+//    }
     /*
      public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
@@ -165,21 +166,21 @@
     }
 
-    public void addShape(GeneralPath addShape) throws SVGException
-    {
-        if (x != null)
-        {
-            cursorX = x[0];
-        } else if (dx != null)
-        {
-            cursorX += dx[0];
-        }
-
-        if (y != null)
-        {
-            cursorY = y[0];
-        } else if (dy != null)
-        {
-            cursorY += dy[0];
-        }
+    public void appendToShape(GeneralPath addShape, Point2D cursor) throws SVGException
+    {
+//        if (x != null)
+//        {
+//            cursorX = x[0];
+//        } else if (dx != null)
+//        {
+//            cursorX += dx[0];
+//        }
+//
+//        if (y != null)
+//        {
+//            cursorY = y[0];
+//        } else if (dy != null)
+//        {
+//            cursorY += dy[0];
+//        }
 
         StyleAttribute sty = new StyleAttribute();
@@ -209,5 +210,5 @@
         if (font == null)
         {
-            addShapeSysFont(addShape, font, fontFamily, fontSize, letterSpacing);
+            addShapeSysFont(addShape, font, fontFamily, fontSize, letterSpacing, cursor);
             return;
         }
@@ -221,8 +222,30 @@
         strokeWidthScalar = 1f / fontScale;
 
-        int posPtr = 1;
-
-        for (int i = 0; i < text.length(); i++)
-        {
+        float cursorX = (float)cursor.getX();
+        float cursorY = (float)cursor.getY();
+    
+//        int i = 0;
+
+        String drawText = this.text;
+        drawText = drawText.trim();
+        for (int i = 0; i < drawText.length(); i++)
+        {
+            if (x != null && i < x.length)
+            {
+                cursorX = x[i];
+            } else if (dx != null && i < dx.length)
+            {
+                cursorX += dx[i];
+            }
+            
+            if (y != null && i < y.length)
+            {
+                cursorY = y[i];
+            } else if (dy != null && i < dy.length)
+            {
+                cursorY += dy[i];
+            }
+  //          i++;
+            
             xform.setToIdentity();
             xform.setToTranslation(cursorX, cursorY);
@@ -230,8 +253,8 @@
             if (rotate != null)
             {
-                xform.rotate(rotate[posPtr]);
-            }
-
-            String unicode = text.substring(i, i + 1);
+                xform.rotate(rotate[i]);
+            }
+
+            String unicode = drawText.substring(i, i + 1);
             MissingGlyph glyph = font.getGlyph(unicode);
 
@@ -243,35 +266,48 @@
             }
 
-            if (x != null && posPtr < x.length)
-            {
-                cursorX = x[posPtr];
-                cursorY = y[posPtr++];
-            } else if (dx != null && posPtr < dx.length)
-            {
-                cursorX += dx[posPtr];
-                cursorY += dy[posPtr++];
-            }
-
             cursorX += fontScale * glyph.getHorizAdvX() + letterSpacing;
         }
 
+        //Save final draw point so calling method knows where to begin next
+        // text draw
+        cursor.setLocation(cursorX, cursorY);
         strokeWidthScalar = 1f;
     }
 
     private void addShapeSysFont(GeneralPath addShape, Font font,
-        String fontFamily, float fontSize, float letterSpacing)
-    {
+        String fontFamily, float fontSize, float letterSpacing, Point2D cursor)
+    {
+
         java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int) fontSize);
 
         FontRenderContext frc = new FontRenderContext(null, true, true);
-        GlyphVector textVector = sysFont.createGlyphVector(frc, text);
+        String renderText = this.text.trim();
 
         AffineTransform xform = new AffineTransform();
 
-        int posPtr = 1;
-        for (int i = 0; i < text.length(); i++)
-        {
+        float cursorX = (float)cursor.getX();
+        float cursorY = (float)cursor.getY();
+//        int i = 0;
+        for (int i = 0; i < renderText.length(); i++)
+        {
+            if (x != null && i < x.length)
+            {
+                cursorX = x[i];
+            } else if (dx != null && i < dx.length)
+            {
+                cursorX += dx[i];
+            }
+
+            if (y != null && i < y.length)
+            {
+                cursorY = y[i];
+            } else if (dy != null && i < dy.length)
+            {
+                cursorY += dy[i];
+            }
+//            i++;
+            
             xform.setToIdentity();
-            xform.setToTranslation(cursorX + i * letterSpacing, cursorY);
+            xform.setToTranslation(cursorX, cursorY);
             if (rotate != null)
             {
@@ -279,25 +315,25 @@
             }
 
-            String unicode = text.substring(i, i + 1);
-            Shape glyphOutline = textVector.getGlyphOutline(i);
-            GlyphMetrics glyphMetrics = textVector.getGlyphMetrics(i);
+//            String unicode = renderText.substring(i, i + 1);
+            GlyphVector textVector = sysFont.createGlyphVector(frc, renderText.substring(i, i + 1));
+            Shape glyphOutline = textVector.getGlyphOutline(0);
+            GlyphMetrics glyphMetrics = textVector.getGlyphMetrics(0);
 
             glyphOutline = xform.createTransformedShape(glyphOutline);
             addShape.append(glyphOutline, false);
 
-            if (x != null && posPtr < x.length)
-            {
-                cursorX = x[posPtr];
-                cursorY = y[posPtr++];
-            } else if (dx != null && posPtr < dx.length)
-            {
-                cursorX += dx[posPtr];
-                cursorY += dy[posPtr++];
-            }
-        }
+
+//            cursorX += fontScale * glyph.getHorizAdvX() + letterSpacing;
+            cursorX += glyphMetrics.getAdvance() + letterSpacing;
+        }
+        
+        cursor.setLocation(cursorX, cursorY);
     }
 
     public void render(Graphics2D g) throws SVGException
     {
+        float cursorX = 0;
+        float cursorY = 0;
+    
         if (x != null)
         {
@@ -385,4 +421,7 @@
     protected void renderSysFont(Graphics2D g, java.awt.Font font) throws SVGException
     {
+        float cursorX = 0;
+        float cursorY = 0;
+    
         int posPtr = 1;
         FontRenderContext frc = g.getFontRenderContext();
Index: trunk/src/com/kitfox/svg/Use.java
===================================================================
--- trunk/src/com/kitfox/svg/Use.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/Use.java	(revision 7676)
@@ -124,5 +124,5 @@
         }
 
-        RenderableElement rendEle = (RenderableElement) ref;
+        RenderableElement rendEle = (RenderableElement)ref;
         rendEle.pushParentContext(this);
         rendEle.render(g);
Index: trunk/src/com/kitfox/svg/app/beans/SVGIcon.java
===================================================================
--- trunk/src/com/kitfox/svg/app/beans/SVGIcon.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/app/beans/SVGIcon.java	(revision 7676)
@@ -51,6 +51,8 @@
 {
     public static final long serialVersionUID = 1;
-    
-    private PropertyChangeSupport changes = new PropertyChangeSupport(this);
+
+    public static final String PROP_AUTOSIZE = "PROP_AUTOSIZE";
+    
+    private final PropertyChangeSupport changes = new PropertyChangeSupport(this);
     
     SVGUniverse svgUniverse = SVGCache.getSVGUniverse();
@@ -63,11 +65,16 @@
     private boolean clipToViewbox;
     
-//    private String svgPath;
     URI svgURI;
     
-    private boolean scaleToFit;
+//    private boolean scaleToFit;
     AffineTransform scaleXform = new AffineTransform();
-    
-//    Dimension preferredSize = new Dimension(100, 100);
+
+    public static final int AUTOSIZE_NONE = 0;
+    public static final int AUTOSIZE_HORIZ = 1;
+    public static final int AUTOSIZE_VERT = 2;
+    public static final int AUTOSIZE_BESTFIT = 3;
+    public static final int AUTOSIZE_STRETCH = 4;
+    private int autosize = AUTOSIZE_NONE;
+    
     Dimension preferredSize;
     
@@ -92,5 +99,7 @@
     public int getIconHeight()
     {
-        if (scaleToFit && preferredSize != null)
+        if (preferredSize != null &&
+                (autosize == AUTOSIZE_VERT || autosize == AUTOSIZE_STRETCH 
+                || autosize == AUTOSIZE_BESTFIT))
         {
             return preferredSize.height;
@@ -110,5 +119,7 @@
     public int getIconWidth()
     {
-        if (scaleToFit && preferredSize != null)
+        if (preferredSize != null &&
+                (autosize == AUTOSIZE_HORIZ || autosize == AUTOSIZE_STRETCH 
+                || autosize == AUTOSIZE_BESTFIT))
         {
             return preferredSize.width;
@@ -172,6 +183,5 @@
         
         
-        
-        if (!scaleToFit)
+        if (autosize == AUTOSIZE_NONE)
         {
             try
@@ -210,8 +220,32 @@
         
         
-        final Rectangle2D.Double rect = new Rectangle2D.Double();
-        diagram.getViewRect(rect);
-        
-        scaleXform.setToScale(width / rect.width, height / rect.height);
+//        final Rectangle2D.Double rect = new Rectangle2D.Double();
+//        diagram.getViewRect(rect);
+//        
+//        scaleXform.setToScale(width / rect.width, height / rect.height);
+        double diaWidth = diagram.getWidth();
+        double diaHeight = diagram.getHeight();
+        
+        double scaleW = 1;
+        double scaleH = 1;
+        if (autosize == AUTOSIZE_BESTFIT)
+        {
+            scaleW = scaleH = (height / diaHeight < width / diaWidth) 
+                    ? height / diaHeight : width / diaWidth;
+        }
+        else if (autosize == AUTOSIZE_HORIZ)
+        {
+            scaleW = scaleH = width / diaWidth;
+        }
+        else if (autosize == AUTOSIZE_VERT)
+        {
+            scaleW = scaleH = height / diaHeight;
+        }
+        else if (autosize == AUTOSIZE_STRETCH)
+        {
+            scaleW = width / diaWidth;
+            scaleH = height / diaHeight;
+        }
+        scaleXform.setToScale(scaleW, scaleH);
         
         AffineTransform oldXform = g.getTransform();
@@ -315,15 +349,22 @@
      * If this SVG document has a viewbox, if scaleToFit is set, will scale the viewbox to match the
      * preferred size of this icon
+     * @deprecated 
+     * @return 
      */
     public boolean isScaleToFit()
     {
-        return scaleToFit;
-    }
-    
+        return autosize == AUTOSIZE_STRETCH;
+    }
+    
+    /**
+     * @deprecated 
+     * @return 
+     */
     public void setScaleToFit(boolean scaleToFit)
     {
-        boolean old = this.scaleToFit;
-        this.scaleToFit = scaleToFit;
-        changes.firePropertyChange("scaleToFit", old, scaleToFit);
+        setAutosize(AUTOSIZE_STRETCH);
+//        boolean old = this.scaleToFit;
+//        this.scaleToFit = scaleToFit;
+//        firePropertyChange("scaleToFit", old, scaleToFit);
     }
     
@@ -429,4 +470,22 @@
         this.clipToViewbox = clipToViewbox;
     }
-    
+
+    /**
+     * @return the autosize
+     */
+    public int getAutosize()
+    {
+        return autosize;
+    }
+
+    /**
+     * @param autosize the autosize to set
+     */
+    public void setAutosize(int autosize)
+    {
+        int oldAutosize = this.autosize;
+        this.autosize = autosize;
+        changes.firePropertyChange(PROP_AUTOSIZE, oldAutosize, autosize);
+    }
+        
 }
Index: trunk/src/com/kitfox/svg/pattern/PatternPaintContext.java
===================================================================
--- trunk/src/com/kitfox/svg/pattern/PatternPaintContext.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/pattern/PatternPaintContext.java	(revision 7676)
@@ -97,5 +97,5 @@
     {
 //System.err.println("" + x + ", " + y + ", " + w + ", " + h);
-        if (buf == null || buf.getWidth() != w || buf.getHeight() != buf.getHeight())
+        if (buf == null || buf.getWidth() != w || buf.getHeight() != h)
         {
             buf = new BufferedImage(w, h, source.getType());
Index: trunk/src/com/kitfox/svg/xml/ColorTable.java
===================================================================
--- trunk/src/com/kitfox/svg/xml/ColorTable.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/xml/ColorTable.java	(revision 7676)
@@ -225,4 +225,9 @@
         Color retVal = null;
 
+        if ("".equals(val))
+        {
+            return null;
+        }
+        
         if (val.charAt(0) == '#')
         {
Index: trunk/src/com/kitfox/svg/xml/cpx/CPXInputStream.java
===================================================================
--- trunk/src/com/kitfox/svg/xml/cpx/CPXInputStream.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/xml/cpx/CPXInputStream.java	(revision 7676)
@@ -39,10 +39,8 @@
 import com.kitfox.svg.SVGConst;
 import java.io.*;
-import java.util.*;
 import java.util.zip.*;
 import java.security.*;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import javax.crypto.*;
 
 /**
Index: trunk/src/com/kitfox/svg/xml/cpx/CPXOutputStream.java
===================================================================
--- trunk/src/com/kitfox/svg/xml/cpx/CPXOutputStream.java	(revision 6617)
+++ trunk/src/com/kitfox/svg/xml/cpx/CPXOutputStream.java	(revision 7676)
@@ -39,6 +39,4 @@
 import java.io.*;
 import java.util.zip.*;
-import java.security.*;
-import javax.crypto.*;
 
 /**
