Index: trunk/src/com/kitfox/svg/ImageSVG.java
===================================================================
--- trunk/src/com/kitfox/svg/ImageSVG.java	(revision 4256)
+++ trunk/src/com/kitfox/svg/ImageSVG.java	(revision 6002)
@@ -1,44 +1,56 @@
 /*
- * Font.java
- *
- *
- *  The Salamander Project - 2D and 3D graphics libraries in Java
- *  Copyright (C) 2004 Mark McKay
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- *  Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
- *  projects can be found at http://www.kitfox.com
+ * SVG Salamander
+ * Copyright (c) 2004, Mark McKay
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or 
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   - Redistributions of source code must retain the above 
+ *     copyright notice, this list of conditions and the following
+ *     disclaimer.
+ *   - Redistributions in binary form must reproduce the above
+ *     copyright notice, this list of conditions and the following
+ *     disclaimer in the documentation and/or other materials 
+ *     provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * 
+ * Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
+ * projects can be found at http://www.kitfox.com
  *
  * Created on February 20, 2004, 10:00 PM
  */
-
 package com.kitfox.svg;
 
 import com.kitfox.svg.app.data.Handler;
-import com.kitfox.svg.xml.*;
-
-import java.awt.*;
-import java.awt.geom.*;
-import java.awt.image.*;
-import java.net.*;
+import com.kitfox.svg.xml.StyleAttribute;
+import java.awt.AlphaComposite;
+import java.awt.Composite;
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.net.URI;
+import java.net.URL;
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
- * Implements an embedded font.
- *
- * SVG specification: http://www.w3.org/TR/SVG/fonts.html
+ * Implements an image.
  *
  * @author Mark McKay
@@ -47,35 +59,55 @@
 public class ImageSVG extends RenderableElement
 {
+    public static final String TAG_NAME = "image";
+    
     float x = 0f;
     float y = 0f;
     float width = 0f;
     float height = 0f;
-
 //    BufferedImage href = null;
     URL imageSrc = null;
-
     AffineTransform xform;
     Rectangle2D bounds;
 
-    /** Creates a new instance of Font */
+    /**
+     * Creates a new instance of Font
+     */
     public ImageSVG()
     {
     }
-    
+
+    public String getTagName()
+    {
+        return TAG_NAME;
+    }
+
     protected void build() throws SVGException
     {
         super.build();
-        
+
         StyleAttribute sty = new StyleAttribute();
-        
-        if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits();
-
-        if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits();
-
-        if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits();
-
-        if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits();
-
-        try {
+
+        if (getPres(sty.setName("x")))
+        {
+            x = sty.getFloatValueWithUnits();
+        }
+
+        if (getPres(sty.setName("y")))
+        {
+            y = sty.getFloatValueWithUnits();
+        }
+
+        if (getPres(sty.setName("width")))
+        {
+            width = sty.getFloatValueWithUnits();
+        }
+
+        if (getPres(sty.setName("height")))
+        {
+            height = sty.getFloatValueWithUnits();
+        }
+
+        try
+        {
             if (getPres(sty.setName("xlink:href")))
             {
@@ -84,19 +116,19 @@
                 {
                     imageSrc = new URL(null, src.toASCIIString(), new Handler());
-                }
-                else
-                {
-                    try {
+                } else
+                {
+                    try
+                    {
                         imageSrc = src.toURL();
-                    }
-                    catch (Exception e)
+                    } catch (Exception e)
                     {
-                        e.printStackTrace();
+                        Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
+                            "Could not parse xlink:href", e);
+//                        e.printStackTrace();
                         imageSrc = null;
                     }
                 }
             }
-        }
-        catch (Exception e)
+        } catch (Exception e)
         {
             throw new SVGException(e);
@@ -104,5 +136,5 @@
 
         diagram.getUniverse().registerImage(imageSrc);
-        
+
         //Set widths if not set
         BufferedImage img = diagram.getUniverse().getImage(imageSrc);
@@ -113,8 +145,14 @@
             return;
         }
-        
-        if (width == 0) width = img.getWidth();
-        if (height == 0) height = img.getHeight();
-        
+
+        if (width == 0)
+        {
+            width = img.getWidth();
+        }
+        if (height == 0)
+        {
+            height = img.getHeight();
+        }
+
         //Determine image xform
         xform = new AffineTransform();
@@ -123,14 +161,27 @@
         xform.translate(this.x, this.y);
         xform.scale(this.width / img.getWidth(), this.height / img.getHeight());
-        
+
         bounds = new Rectangle2D.Float(this.x, this.y, this.width, this.height);
     }
-    
-    
-    
-    public float getX() { return x; }
-    public float getY() { return y; }
-    public float getWidth() { return width; }
-    public float getHeight() { return height; }
+
+    public float getX()
+    {
+        return x;
+    }
+
+    public float getY()
+    {
+        return y;
+    }
+
+    public float getWidth()
+    {
+        return width;
+    }
+
+    public float getHeight()
+    {
+        return height;
+    }
 
     void pick(Point2D point, boolean boundingBox, List retVec) throws SVGException
@@ -155,9 +206,12 @@
         if (getStyle(styleAttrib.setName("visibility")))
         {
-            if (!styleAttrib.getStringValue().equals("visible")) return;
-        }
-        
+            if (!styleAttrib.getStringValue().equals("visible"))
+            {
+                return;
+            }
+        }
+
         beginLayer(g);
-        
+
         float opacity = 1f;
         if (getStyle(styleAttrib.setName("opacity")))
@@ -165,9 +219,12 @@
             opacity = styleAttrib.getRatioValue();
         }
-        
-        if (opacity <= 0) return;
+
+        if (opacity <= 0)
+        {
+            return;
+        }
 
         Composite oldComp = null;
-        
+
         if (opacity < 1)
         {
@@ -176,19 +233,25 @@
             g.setComposite(comp);
         }
-        
+
         BufferedImage img = diagram.getUniverse().getImage(imageSrc);
-        if (img == null) return;
-        
+        if (img == null)
+        {
+            return;
+        }
+
         AffineTransform curXform = g.getTransform();
         g.transform(xform);
-        
+
         g.drawImage(img, 0, 0, null);
-        
+
         g.setTransform(curXform);
-        if (oldComp != null) g.setComposite(oldComp);
-        
+        if (oldComp != null)
+        {
+            g.setComposite(oldComp);
+        }
+
         finishLayer(g);
     }
-    
+
     public Rectangle2D getBoundingBox()
     {
@@ -197,6 +260,7 @@
 
     /**
-     * Updates all attributes in this diagram associated with a time event.
-     * Ie, all attributes with track information.
+     * Updates all attributes in this diagram associated with a time event. Ie,
+     * all attributes with track information.
+     *
      * @return - true if this node has changed state as a result of the time
      * update
@@ -210,5 +274,5 @@
         StyleAttribute sty = new StyleAttribute();
         boolean shapeChange = false;
-        
+
         if (getPres(sty.setName("x")))
         {
@@ -220,5 +284,5 @@
             }
         }
-        
+
         if (getPres(sty.setName("y")))
         {
@@ -230,5 +294,5 @@
             }
         }
-        
+
         if (getPres(sty.setName("width")))
         {
@@ -240,5 +304,5 @@
             }
         }
-        
+
         if (getPres(sty.setName("height")))
         {
@@ -250,11 +314,20 @@
             }
         }
-        
-        try {
+
+        try
+        {
             if (getPres(sty.setName("xlink:href")))
             {
                 URI src = sty.getURIValue(getXMLBase());
-                URL newVal = src.toURL();
-                
+
+                URL newVal;
+                if ("data".equals(src.getScheme()))
+                {
+                    newVal = new URL(null, src.toASCIIString(), new Handler());
+                } else
+                {
+                    newVal = src.toURL();
+                }
+
                 if (!newVal.equals(imageSrc))
                 {
@@ -263,15 +336,16 @@
                 }
             }
-        }
-        catch (IllegalArgumentException ie)
-        {
-            new Exception("Image provided with illegal value for href: \"" + sty.getStringValue() + '"', ie).printStackTrace();
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-        }
-
-        
+        } catch (IllegalArgumentException ie)
+        {
+            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
+                "Image provided with illegal value for href: \""
+                + sty.getStringValue() + '"', ie);
+        } catch (Exception e)
+        {
+            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
+                "Could not parse xlink:href", e);
+        }
+
+
         if (shapeChange)
         {
@@ -303,5 +377,5 @@
 //            return true;
         }
-        
+
         return changeState || shapeChange;
     }
