Blob Blame History Raw
diff --git a/svg-core/src/main/java/com/kitfox/svg/ImageSVG.java b/svg-core/src/main/java/com/kitfox/svg/ImageSVG.java
index 848ceb5..926b9ef 100644
--- a/svg-core/src/main/java/com/kitfox/svg/ImageSVG.java
+++ b/svg-core/src/main/java/com/kitfox/svg/ImageSVG.java
@@ -113,28 +113,21 @@ protected void build() throws SVGException
         {
             if (getPres(sty.setName("xlink:href")))
             {
-                
-                
                 URI src = sty.getURIValue(getXMLBase());
                 if ("data".equals(src.getScheme()))
                 {
                     imageSrc = new URL(null, src.toASCIIString(), new Handler());
                 }
-                else 
+                else if (!diagram.getUniverse().isImageDataInlineOnly())
                 {
-                    
-                    if (!diagram.getUniverse().isImageDataInlineOnly())
+                    try
                     {
-                        try
-                        {
-                            imageSrc = src.toURL();
-                        } catch (Exception e)
-                        {
-                            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
-                                "Could not parse xlink:href " + src, e);
-    //                        e.printStackTrace();
-                            imageSrc = null;
-                        }
+                        imageSrc = src.toURL();
+                    } catch (Exception e)
+                    {
+                        Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
+                            "Could not parse xlink:href " + src, e);
+                        imageSrc = null;
                     }
                 }
             }
@@ -143,32 +136,33 @@ protected void build() throws SVGException
             throw new SVGException(e);
         }
 
-        diagram.getUniverse().registerImage(imageSrc);
-
-        //Set widths if not set
-        BufferedImage img = diagram.getUniverse().getImage(imageSrc);
-        if (img == null)
+        if (imageSrc != null)
         {
-            xform = new AffineTransform();
-            bounds = new Rectangle2D.Float();
-            return;
-        }
+            diagram.getUniverse().registerImage(imageSrc);
 
-        if (width == 0)
-        {
-            width = img.getWidth();
-        }
-        if (height == 0)
-        {
-            height = img.getHeight();
-        }
+            //Set widths if not set
+            BufferedImage img = diagram.getUniverse().getImage(imageSrc);
+            if (img == null)
+            {
+                xform = new AffineTransform();
+                bounds = new Rectangle2D.Float();
+                return;
+            }
+
+            if (width == 0)
+            {
+                width = img.getWidth();
+            }
+            if (height == 0)
+            {
+                height = img.getHeight();
+            }
 
-        //Determine image xform
-        xform = new AffineTransform();
-//        xform.setToScale(this.width / img.getWidth(), this.height / img.getHeight());
-//        xform.translate(this.x, this.y);
-        xform.translate(this.x, this.y);
-        xform.scale(this.width / img.getWidth(), this.height / img.getHeight());
+            //Determine image xform
+            xform = new AffineTransform();
+            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);
     }
@@ -342,16 +336,16 @@ public boolean updateTime(double curTime) throws SVGException
             {
                 URI src = sty.getURIValue(getXMLBase());
 
-                URL newVal;
+                URL newVal = null;
                 if ("data".equals(src.getScheme()))
                 {
                     newVal = new URL(null, src.toASCIIString(), new Handler());
-                } else
+                } else if (!diagram.getUniverse().isImageDataInlineOnly())
                 {
                     newVal = src.toURL();
                 }
 
-                if (!newVal.equals(imageSrc))
+                if (newVal != null && !newVal.equals(imageSrc))
                 {
                     imageSrc = newVal;
                     shapeChange = true;
diff --git a/svg-core/src/main/java/com/kitfox/svg/SVGElement.java b/svg-core/src/main/java/com/kitfox/svg/SVGElement.java
index 384c1a0..1e4a594 100644
--- a/svg-core/src/main/java/com/kitfox/svg/SVGElement.java
+++ b/svg-core/src/main/java/com/kitfox/svg/SVGElement.java
@@ -743,9 +743,10 @@ public StyleAttribute getPresAbsolute(String styName)
         return (StyleAttribute) presAttribs.get(styName);
     }
 
+    private static final Pattern TRANSFORM_PATTERN = Pattern.compile("\\w+\\([^)]*\\)");
     static protected AffineTransform parseTransform(String val) throws SVGException
     {
-        final Matcher matchExpression = Pattern.compile("\\w+\\([^)]*\\)").matcher("");
+        final Matcher matchExpression = TRANSFORM_PATTERN.matcher("");
 
         AffineTransform retXform = new AffineTransform();
 
@@ -758,9 +759,10 @@ static protected AffineTransform parseTransform(String val) throws SVGException
         return retXform;
     }
 
+    private static final Pattern WORD_PATTERN = Pattern.compile("([a-zA-Z]+|-?\\d+(\\.\\d+)?(e-?\\d+)?|-?\\.\\d+(e-?\\d+)?)");
     static public AffineTransform parseSingleTransform(String val) throws SVGException
     {
-        final Matcher matchWord = Pattern.compile("([a-zA-Z]+|-?\\d+(\\.\\d+)?(e-?\\d+)?|-?\\.\\d+(e-?\\d+)?)").matcher("");
+        final Matcher matchWord = WORD_PATTERN.matcher("");
 
         AffineTransform retXform = new AffineTransform();
 
@@ -839,9 +841,10 @@ static protected float nextFloat(LinkedList<String> l)
         return Float.parseFloat(s);
     }
 
+    private static final Pattern COMMAND_PATTERN = Pattern.compile("([MmLlHhVvAaQqTtCcSsZz])|([-+]?((\\d*\\.\\d+)|(\\d+))([eE][-+]?\\d+)?)");
     static protected PathCommand[] parsePathList(String list)
     {
-        final Matcher matchPathCmd = Pattern.compile("([MmLlHhVvAaQqTtCcSsZz])|([-+]?((\\d*\\.\\d+)|(\\d+))([eE][-+]?\\d+)?)").matcher(list);
+        final Matcher matchPathCmd = COMMAND_PATTERN.matcher(list);
 
         //Tokenize
         LinkedList<String> tokens = new LinkedList<String>();
diff --git a/svg-core/src/main/java/com/kitfox/svg/SVGRoot.java b/svg-core/src/main/java/com/kitfox/svg/SVGRoot.java
index 203f485..fc40717 100644
--- a/svg-core/src/main/java/com/kitfox/svg/SVGRoot.java
+++ b/svg-core/src/main/java/com/kitfox/svg/SVGRoot.java
@@ -200,8 +200,8 @@ protected void prepareViewport()
         }
         else if (viewBox != null)
         {
-            xx = (float)viewBox.x;
-            ww = (float)viewBox.width;
+            xx = viewBox.x;
+            ww = viewBox.width;
             width = new NumberWithUnits(ww, NumberWithUnits.UT_PX);
             x = new NumberWithUnits(xx, NumberWithUnits.UT_PX);
         }
@@ -228,8 +228,8 @@ else if (viewBox != null)
         }
         else if (viewBox != null)
         {
-            yy = (float)viewBox.y;
-            hh = (float)viewBox.height;
+            yy = viewBox.y;
+            hh = viewBox.height;
             height = new NumberWithUnits(hh, NumberWithUnits.UT_PX);
             y = new NumberWithUnits(yy, NumberWithUnits.UT_PX);
         }
@@ -262,6 +262,12 @@ else if (viewBox != null)
     }
 
     public void renderToViewport(Graphics2D g) throws SVGException
+    {
+        render(g);
+    }
+
+    @Override
+    public void render(Graphics2D g) throws SVGException
     {
         prepareViewport();
         
diff --git a/svg-core/src/main/java/com/kitfox/svg/SVGUniverse.java b/svg-core/src/main/java/com/kitfox/svg/SVGUniverse.java
index 3bb9973..7cc1565 100644
--- a/svg-core/src/main/java/com/kitfox/svg/SVGUniverse.java
+++ b/svg-core/src/main/java/com/kitfox/svg/SVGUniverse.java
@@ -98,9 +98,7 @@
      */
     protected double curTime = 0.0;
     private boolean verbose = false;
-    //Cache reader for efficiency
-    XMLReader cachedReader;
-    
+
     //If true, <imageSVG> elements will only load image data that is included using inline data: uris
     private boolean imageDataInlineOnly = false;
     
@@ -576,15 +574,11 @@ public URI getStreamBuiltURI(String name)
         }
     }
 
-    private XMLReader getXMLReaderCached() throws SAXException, ParserConfigurationException
+    private XMLReader getXMLReader() throws SAXException, ParserConfigurationException
     {
-        if (cachedReader == null)
-        {
-            SAXParserFactory factory = SAXParserFactory.newInstance();
-            factory.setNamespaceAware(true);
-            cachedReader = factory.newSAXParser().getXMLReader();
-        }
-        return cachedReader;
+        SAXParserFactory factory = SAXParserFactory.newInstance();
+        factory.setNamespaceAware(true);
+        return factory.newSAXParser().getXMLReader();
     }
 
     protected URI loadSVG(URI xmlBase, InputSource is)
@@ -600,7 +594,7 @@ protected URI loadSVG(URI xmlBase, InputSource is)
         try
         {
             // Parse the input
-            XMLReader reader = getXMLReaderCached();
+            XMLReader reader = getXMLReader();
             reader.setEntityResolver(
                 new EntityResolver()
                 {
@@ -617,8 +611,8 @@ public InputSource resolveEntity(String publicId, String systemId)
             return xmlBase;
         } catch (SAXParseException sex)
         {
-            System.err.println("Error processing " + xmlBase);
-            System.err.println(sex.getMessage());
+            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
+                "Error processing " + xmlBase, sex);
 
             loadedDocs.remove(xmlBase);
             return null;
diff --git a/svg-core/src/main/java/com/kitfox/svg/Text.java b/svg-core/src/main/java/com/kitfox/svg/Text.java
index 64d2dd5..b306edc 100644
--- a/svg-core/src/main/java/com/kitfox/svg/Text.java
+++ b/svg-core/src/main/java/com/kitfox/svg/Text.java
@@ -178,7 +178,7 @@ public void build() throws SVGException
         }
         else
         {
-            fontFamily = "Sans Serif";
+            fontFamily = "SansSerif";
         }
 
         if (getStyle(sty.setName("font-size")))
diff --git a/svg-core/src/main/java/com/kitfox/svg/Tspan.java b/svg-core/src/main/java/com/kitfox/svg/Tspan.java
index 1d9fa32..3b66188 100644
--- a/svg-core/src/main/java/com/kitfox/svg/Tspan.java
+++ b/svg-core/src/main/java/com/kitfox/svg/Tspan.java
@@ -228,13 +228,18 @@ public void appendToShape(GeneralPath addShape, Point2D cursor) throws SVGExcept
 
         //Get font
         Font font = diagram.getUniverse().getFont(fontFamily);
-        if (font == null)
+        if (font == null && fontFamily != null)
         {
             font = FontSystem.createFont(fontFamily, fontStyle, fontWeight, (int)fontSize);
 //            addShapeSysFont(addShape, font, fontFamily, fontSize, letterSpacing, cursor);
 //            return;
         }
 
+        if (font == null)
+        {
+            font = FontSystem.createFont("Serif", fontStyle, fontWeight, fontStyle);
+        }
+
 //        FontFace fontFace = font.getFontFace();
 //        int ascent = fontFace.getAscent();
 //        float fontScale = fontSize / (float) ascent;
diff --git a/svg-core/src/main/java/com/kitfox/svg/animation/AnimTimeParser.jjt b/svg-core/src/main/java/com/kitfox/svg/animation/parser/AnimTimeParser.jjt
similarity index 100%
rename from svg-core/src/main/java/com/kitfox/svg/animation/AnimTimeParser.jjt
rename to svg-core/src/main/java/com/kitfox/svg/animation/parser/AnimTimeParser.jjt
diff --git a/svg-core/src/main/java/com/kitfox/svg/util/FontSystem.java b/svg-core/src/main/java/com/kitfox/svg/util/FontSystem.java
index 5c4ebf2..df90b64 100644
--- a/svg-core/src/main/java/com/kitfox/svg/util/FontSystem.java
+++ b/svg-core/src/main/java/com/kitfox/svg/util/FontSystem.java
@@ -47,6 +47,7 @@
 import java.awt.font.GlyphVector;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Locale;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -67,7 +68,7 @@ public static boolean checkIfSystemFontExists(String fontName)
     {
         if (sysFontNames.isEmpty())
         {
-            for (String name: GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames())
+            for (String name: GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(Locale.ENGLISH))
             {
                 sysFontNames.add(name);
             }
@@ -81,15 +82,33 @@ public static FontSystem createFont(String fontFamily, int fontStyle, int fontWe
         String[] families = fontFamily.split(",");
         for (String fontName: families)
         {
-            if (checkIfSystemFontExists(fontName))
+            String javaFontName = mapJavaFontName(fontName);
+            if (checkIfSystemFontExists(javaFontName))
             {
-                return new FontSystem(fontName, fontStyle, fontWeight, (int) fontSize);
+                return new FontSystem(javaFontName, fontStyle, fontWeight, (int) fontSize);
             }
         }
         
         return null;
     }
-    
+
+    private static String mapJavaFontName(String fontName)
+    {
+        if ("serif".equals(fontName))
+        {
+            return java.awt.Font.SERIF;
+        }
+        else if ("sans-serif".equals(fontName))
+        {
+            return java.awt.Font.SANS_SERIF;
+        }
+        else if ("monospace".equals(fontName))
+        {
+            return java.awt.Font.MONOSPACED;
+        }
+        return fontName;
+    }
+
     private FontSystem(String fontFamily, int fontStyle, int fontWeight, int fontSize)
     {
         int style;
diff --git a/svg-core/src/main/java/com/kitfox/svg/xml/XMLParseUtil.java b/svg-core/src/main/java/com/kitfox/svg/xml/XMLParseUtil.java
index bfc0be4..4f1a1df 100644
--- a/svg-core/src/main/java/com/kitfox/svg/xml/XMLParseUtil.java
+++ b/svg-core/src/main/java/com/kitfox/svg/xml/XMLParseUtil.java
@@ -54,6 +54,7 @@
 {
     static final Matcher fpMatch = Pattern.compile("([-+]?((\\d*\\.\\d+)|(\\d+))([eE][+-]?\\d+)?)(\\%|in|cm|mm|pt|pc|px|em|ex)?").matcher("");
     static final Matcher intMatch = Pattern.compile("[-+]?\\d+").matcher("");
+    static final Matcher quoteMatch = Pattern.compile("^'|'$").matcher("");
 
     /** Creates a new instance of XMLParseUtil */
     private XMLParseUtil()
@@ -822,7 +823,7 @@ public static ReadableXMLElement getElement(Class<?> classType, Element root, St
             }
 
             String key = styles[i].substring(0, colon).trim();
-            String value = styles[i].substring(colon + 1).trim();
+            String value = quoteMatch.reset(styles[i].substring(colon + 1).trim()).replaceAll("");
 
             map.put(key, new StyleAttribute(key, value));
         }