You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by tk...@apache.org on 2002/06/18 14:50:06 UTC

cvs commit: xml-batik/samples/tests/spec/scripting svg.svg

tkormann    2002/06/18 05:50:06

  Modified:    sources/org/apache/batik/bridge SVGGElementBridge.java
                        SVGSVGElementBridge.java
  Added:       samples/tests/spec/scripting svg.svg
  Log:
  Add support for dynamic updates of x,y,width,height,viewBox, and
  preserveAspectRatio on <svg> element.
  
  The way it's implemented today is brutal (rebuild the whole subtree
  each time a single attribute modification happens - but with the
  current design we have no choice :(
  
  Revision  Changes    Path
  1.19      +17 -7     xml-batik/sources/org/apache/batik/bridge/SVGGElementBridge.java
  
  Index: SVGGElementBridge.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGGElementBridge.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- SVGGElementBridge.java	20 Mar 2002 16:34:43 -0000	1.18
  +++ SVGGElementBridge.java	18 Jun 2002 12:50:06 -0000	1.19
  @@ -97,7 +97,17 @@
        * Invoked when an MutationEvent of type 'DOMNodeInserted' is fired.
        */
       public void handleDOMNodeInsertedEvent(MutationEvent evt) {
  -        Element childElt = (Element)evt.getTarget();
  +        handleElementAdded((CompositeGraphicsNode)node, 
  +                           e, 
  +                           (Element)evt.getTarget());
  +    }
  +
  +    /**
  +     * Invoked when an MutationEvent of type 'DOMNodeInserted' is fired.
  +     */
  +    public void handleElementAdded(CompositeGraphicsNode gn, 
  +                                   Element parent, 
  +                                   Element childElt) {
           // build the graphics node
           GVTBuilder builder = ctx.getGVTBuilder();
           GraphicsNode childNode = builder.build(ctx, childElt);
  @@ -105,14 +115,14 @@
               return; // the added element is not a graphic element
           }
           // add the graphics node
  -        Node n = e.getFirstChild();
  -        Node lastChild = e.getLastChild();
  +        Node n = parent.getFirstChild();
  +        Node lastChild = parent.getLastChild();
           if (n == childElt) {
               // add at the beginning
  -            ((CompositeGraphicsNode)node).add(0, childNode);
  +            gn.add(0, childNode);
           } else if (lastChild == childElt) {
               // append at the end
  -            ((CompositeGraphicsNode)node).add(childNode);
  +            gn.add(childNode);
           } else {
               // find the index of the GraphicsNode to add
               int index = 0;
  @@ -125,7 +135,7 @@
                   n = n.getNextSibling();
               }
               // insert at the index
  -            ((CompositeGraphicsNode)node).add(index, childNode);
  +            gn.add(index, childNode);
           }
       }
   }
  
  
  
  1.29      +17 -2     xml-batik/sources/org/apache/batik/bridge/SVGSVGElementBridge.java
  
  Index: SVGSVGElementBridge.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGSVGElementBridge.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- SVGSVGElementBridge.java	21 Mar 2002 11:14:01 -0000	1.28
  +++ SVGSVGElementBridge.java	18 Jun 2002 12:50:06 -0000	1.29
  @@ -17,6 +17,7 @@
   import org.apache.batik.ext.awt.image.renderable.ClipRable8Bit;
   import org.apache.batik.ext.awt.image.renderable.Filter;
   import org.apache.batik.gvt.CanvasGraphicsNode;
  +import org.apache.batik.gvt.CompositeGraphicsNode;
   import org.apache.batik.gvt.GraphicsNode;
   import org.apache.batik.parser.ParseException;
   import org.apache.batik.util.SVGConstants;
  @@ -204,7 +205,21 @@
        */
       public void handleDOMAttrModifiedEvent(MutationEvent evt) {
           // Don't call 'super' because there is no 'transform' attribute on <svg>
  -   }
  +        String attrName = evt.getAttrName();
  +        if (attrName.equals(SVG_X_ATTRIBUTE) ||
  +            attrName.equals(SVG_Y_ATTRIBUTE) ||
  +            attrName.equals(SVG_WIDTH_ATTRIBUTE) ||
  +            attrName.equals(SVG_HEIGHT_ATTRIBUTE) ||
  +            attrName.equals(SVG_VIEW_BOX_ATTRIBUTE) ||
  +            attrName.equals(SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE)) {
  +            
  +            CompositeGraphicsNode gn = node.getParent();
  +            gn.remove(node);
  +            disposeTree(e);
  +
  +            handleElementAdded(gn, (Element)e.getParentNode(), e);
  +        }
  +    }
   
       /**
        * A viewport defined an &lt;svg> element.
  
  
  
  1.1                  xml-batik/samples/tests/spec/scripting/svg.svg
  
  Index: svg.svg
  ===================================================================
  <?xml version="1.0" standalone="no"?>
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
  "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
  
  <!-- ====================================================================== -->
  <!-- Copyright (C) The Apache Software Foundation. All rights reserved.     -->
  <!--                                                                        -->
  <!-- This software is published under the terms of the Apache Software      -->
  <!-- License version 1.1, a copy of which has been included with this       -->
  <!-- distribution in the LICENSE file.                                      -->
  <!-- ====================================================================== -->
  
  <!-- ====================================================================== -->
  <!-- append child test                                                      -->
  <!--                                                                        -->
  <!-- @author tkormann@ilog.fr                                               -->
  <!-- @version $Id: svg.svg,v 1.1 2002/06/18 12:50:06 tkormann Exp $ -->
  <!-- ====================================================================== -->
  
  <?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?>  
  
  <svg xmlns="http://www.w3.org/2000/svg" 
       xmlns:xlink="http://www.w3.org/1999/xlink"
       id="body" width="450" height="500" viewBox="0 0 450 500">
  
      <title>svg viewport modification 'onclick'</title>
  
      <text x="50%" y="45" class="title">svg viewport modification 'onclick'</text>
  
      <script type="text/ecmascript">
  
      function changeSize(evt) {
          var e = evt.currentTarget;
          e.setAttribute("x", "10%");
          e.setAttribute("y", "10%");
          e.setAttribute("width", "80%");
          e.setAttribute("height", "80%");
      }
  
      </script>
  
      <g id="test-content">
  
          <svg onclick="changeSize(evt)" 
               x="25%" y="25%" width="50%" height="50%" >
                  <rect width="100%" height="100%" fill="crimson" />
          </svg>
  
      </g>
  </svg>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org