Index: trunk/src/com/kitfox/svg/app/beans/SVGIcon.java
===================================================================
--- trunk/src/com/kitfox/svg/app/beans/SVGIcon.java	(revision 6002)
+++ 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);
+    }
+        
 }
