You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by ca...@apache.org on 2011/03/09 07:35:41 UTC

svn commit: r1079677 - in /xmlgraphics/batik/trunk: CHANGES sources/org/apache/batik/bridge/ViewBox.java sources/org/apache/batik/dom/util/DOMUtilities.java

Author: cam
Date: Wed Mar  9 06:35:41 2011
New Revision: 1079677

URL: http://svn.apache.org/viewvc?rev=1079677&view=rev
Log:
Make sure that when an individual attribute is missing from a <view>
referenced from the URL fragment that it is looked up on the ancestor
<svg> element.  This makes us pass linking-uri-01-b (and -02-b) from
the W3C SVG test suite.

Modified:
    xmlgraphics/batik/trunk/CHANGES
    xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/ViewBox.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/dom/util/DOMUtilities.java

Modified: xmlgraphics/batik/trunk/CHANGES
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/CHANGES?rev=1079677&r1=1079676&r2=1079677&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/CHANGES (original)
+++ xmlgraphics/batik/trunk/CHANGES Wed Mar  9 06:35:41 2011
@@ -70,6 +70,8 @@ Bug fixing is an on-going task, so it is
     CSS properties on elements that subsequently became display:none.
   * The startOffset="" attribute on textPath elements now allows negative
     percentages.
+  * Correctly handle individual missing <view> attributes by looking at
+    the closest ancestor SVG element.
 
 5. Misc
 

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/ViewBox.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/ViewBox.java?rev=1079677&r1=1079676&r2=1079677&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/ViewBox.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/ViewBox.java Wed Mar  9 06:35:41 2011
@@ -28,6 +28,7 @@ import org.apache.batik.parser.FragmentI
 import org.apache.batik.parser.FragmentIdentifierParser;
 import org.apache.batik.parser.ParseException;
 import org.apache.batik.parser.PreserveAspectRatioParser;
+import org.apache.batik.dom.util.DOMUtilities;
 import org.apache.batik.util.SVGConstants;
 
 import org.w3c.dom.Document;
@@ -80,30 +81,37 @@ public abstract class ViewBox implements
         p.setFragmentIdentifierHandler(vh);
         p.parse(ref);
 
-        Element attrDefElement = e; // the element that defines the attributes
+        // Determine the 'view' element that ref refers to.
+        Element viewElement = e;
         if (vh.hasId) {
             Document document = e.getOwnerDocument();
-            attrDefElement = document.getElementById(vh.id);
+            viewElement = document.getElementById(vh.id);
         }
-        if (attrDefElement == null) {
+        if (viewElement == null) {
             throw new BridgeException(ctx, e, ERR_URI_MALFORMED,
                                       new Object[] {ref});
         }
-        // if the referenced element is not a view, the attribute
-        // values to use are those defined on the enclosed svg element
-        if (!(attrDefElement.getNamespaceURI().equals(SVG_NAMESPACE_URI)
-              && attrDefElement.getLocalName().equals(SVG_VIEW_TAG))) {
-            attrDefElement = getClosestAncestorSVGElement(e);
+        if (!(viewElement.getNamespaceURI().equals(SVG_NAMESPACE_URI)
+              && viewElement.getLocalName().equals(SVG_VIEW_TAG))) {
+            viewElement = null;
         }
 
+        Element ancestorSVG = getClosestAncestorSVGElement(e);
+
         // 'viewBox'
-        float [] vb;
+        float[] vb;
         if (vh.hasViewBox) {
             vb = vh.viewBox;
         } else {
-            String viewBoxStr = attrDefElement.getAttributeNS
-                (null, SVG_VIEW_BOX_ATTRIBUTE);
-            vb = parseViewBoxAttribute(attrDefElement, viewBoxStr, ctx);
+            Element elt;
+            if (DOMUtilities.isAttributeSpecifiedNS
+                    (viewElement, null, SVG_VIEW_BOX_ATTRIBUTE)) {
+                elt = viewElement;
+            } else {
+                elt = ancestorSVG;
+            }
+            String viewBoxStr = elt.getAttributeNS(null, SVG_VIEW_BOX_ATTRIBUTE);
+            vb = parseViewBoxAttribute(elt, viewBoxStr, ctx);
         }
 
         // 'preserveAspectRatio'
@@ -113,16 +121,23 @@ public abstract class ViewBox implements
             align = vh.align;
             meet = vh.meet;
         } else {
-            String aspectRatio = attrDefElement.getAttributeNS
-                (null, SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE);
+            Element elt;
+            if (DOMUtilities.isAttributeSpecifiedNS
+                    (viewElement, null, SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE)) {
+                elt = viewElement;
+            } else {
+                elt = ancestorSVG;
+            }
+            String aspectRatio =
+                elt.getAttributeNS(null, SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE);
             PreserveAspectRatioParser pp = new PreserveAspectRatioParser();
             ViewHandler ph = new ViewHandler();
             pp.setPreserveAspectRatioHandler(ph);
             try {
                 pp.parse(aspectRatio);
-            } catch (ParseException pEx ) {
+            } catch (ParseException pEx) {
                 throw new BridgeException
-                    (ctx, attrDefElement, pEx, ERR_ATTRIBUTE_VALUE_MALFORMED,
+                    (ctx, elt, pEx, ERR_ATTRIBUTE_VALUE_MALFORMED,
                      new Object[] {SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE,
                                        aspectRatio, pEx });
             }

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/util/DOMUtilities.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/util/DOMUtilities.java?rev=1079677&r1=1079676&r2=1079677&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/util/DOMUtilities.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/util/DOMUtilities.java Wed Mar  9 06:35:41 2011
@@ -1048,4 +1048,16 @@ public class DOMUtilities extends XMLUti
         }
         return MODIFIER_STRINGS[modifiersEx];
     }
+
+    /**
+     * Returns whether the given element has a particular attribute and that
+     * it exists due to being specified explicitly, rather than being defaulted
+     * from a DTD.
+     */
+    public static boolean isAttributeSpecifiedNS(Element e,
+                                                 String namespaceURI,
+                                                 String localName) {
+        Attr a = e.getAttributeNodeNS(namespaceURI, localName);
+        return a != null && a.getSpecified();
+    }
 }