deweese     2003/06/18 17:32:12

  Modified:    sources/org/apache/batik/swing/svg JSVGComponent.java
               test-resources/org/apache/batik/test samplesRendering.xml
  Added:       test-references/samples/tests/spec/scripting zeroSize.png
               samples/tests/spec/scripting zeroSize.svg
  Log:
  1) JSVGComponent/Canvas now repaints when it changes size (even when no
     viewBox).
  2) Test files for modifying zero W/H rect, circle, ellipse
  
  Revision  Changes    Path
  1.71      +48 -44    xml-batik/sources/org/apache/batik/swing/svg/JSVGComponent.java
  
  Index: JSVGComponent.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/swing/svg/JSVGComponent.java,v
  retrieving revision 1.70
  retrieving revision 1.71
  diff -u -r1.70 -r1.71
  --- JSVGComponent.java        17 Jun 2003 01:37:57 -0000      1.70
  +++ JSVGComponent.java        19 Jun 2003 00:32:11 -0000      1.71
  @@ -677,10 +677,12 @@
       protected boolean updateRenderingTransform() {
           if ((svgDocument == null) || (gvtRoot == null))
               return false;
  +
           try {
               SVGSVGElement elt = svgDocument.getRootElement();
               Dimension d = getSize();
               Dimension oldD = prevComponentSize;
  +            if (oldD == null) oldD = d;
               prevComponentSize = d;
               if (d.width  < 1) d.width  = 1;
               if (d.height < 1) d.height = 1;
  @@ -688,53 +690,55 @@
                   (fragmentIdentifier, elt, d.width, d.height);
               CanvasGraphicsNode cgn = getCanvasGraphicsNode();
               AffineTransform vt = cgn.getViewingTransform();
  -            if (!at.equals(vt)) {
  -                if (oldD == null)
  -                    oldD = d;
  -                // Here we map the old center of the component down to
  -                // the user coodinate system with the old viewing
  -                // transform and then back to the screen with the
  -                // new viewing transform.  We then adjust the rendering
  -                // transform so it lands in the same place.
  -                Point2D pt = new Point2D.Float(oldD.width/2.0f, 
  -                                               oldD.height/2.0f);
  -                AffineTransform rendAT = getRenderingTransform();
  -                if (rendAT != null) {
  -                    try {
  -                        AffineTransform invRendAT = rendAT.createInverse();
  -                        pt = invRendAT.transform(pt, null);
  -                    } catch (NoninvertibleTransformException e) { }
  -                }
  -                if (vt != null) {
  -                    try {
  -                        AffineTransform invVT = vt.createInverse();
  -                        pt = invVT.transform(pt, null);
  -                    } catch (NoninvertibleTransformException e) { }
  -                }
  -                if (at != null)
  -                    pt = at.transform(pt, null);
  -                if (rendAT != null)
  -                    pt = rendAT.transform(pt, null);
  +            if (at.equals(vt)) {
  +                // No new transform
  +                // Only repaint if size really changed.
  +                return ((oldD.width != d.width) || (oldD.height != d.height));
  +            }
   
  -                // Now figure out how far we need to shift things
  -                // to get the center point to line up again.
  -                float dx = (float)((d.width/2.0f) -pt.getX());
  -                float dy = (float)((d.height/2.0f)-pt.getY());
  -                // Round the values to nearest integer.
  -                dx = (int)((dx < 0)?(dx - .5):(dx + .5));
  -                dy = (int)((dy < 0)?(dy - .5):(dy + .5));
  -                if ((dx != 0) || (dy != 0)) {
  -                    rendAT.preConcatenate
  -                        (AffineTransform.getTranslateInstance(dx, dy));
  -                    setRenderingTransform(rendAT, false);
  -                }
  -                cgn.setViewingTransform(at);
  -                return true;
  +            
  +            // Here we map the old center of the component down to
  +            // the user coodinate system with the old viewing
  +            // transform and then back to the screen with the
  +            // new viewing transform.  We then adjust the rendering
  +            // transform so it lands in the same place.
  +            Point2D pt = new Point2D.Float(oldD.width/2.0f, 
  +                                           oldD.height/2.0f);
  +            AffineTransform rendAT = getRenderingTransform();
  +            if (rendAT != null) {
  +                try {
  +                    AffineTransform invRendAT = rendAT.createInverse();
  +                    pt = invRendAT.transform(pt, null);
  +                } catch (NoninvertibleTransformException e) { }
  +            }
  +            if (vt != null) {
  +                try {
  +                    AffineTransform invVT = vt.createInverse();
  +                    pt = invVT.transform(pt, null);
  +                } catch (NoninvertibleTransformException e) { }
  +            }
  +            if (at != null)
  +                pt = at.transform(pt, null);
  +            if (rendAT != null)
  +                pt = rendAT.transform(pt, null);
  +            
  +            // Now figure out how far we need to shift things
  +            // to get the center point to line up again.
  +            float dx = (float)((d.width/2.0f) -pt.getX());
  +            float dy = (float)((d.height/2.0f)-pt.getY());
  +            // Round the values to nearest integer.
  +            dx = (int)((dx < 0)?(dx - .5):(dx + .5));
  +            dy = (int)((dy < 0)?(dy - .5):(dy + .5));
  +            if ((dx != 0) || (dy != 0)) {
  +                rendAT.preConcatenate
  +                    (AffineTransform.getTranslateInstance(dx, dy));
  +                setRenderingTransform(rendAT, false);
               }
  +            cgn.setViewingTransform(at);
           } catch (BridgeException e) {
               userAgent.displayError(e);
           }
  -        return false;
  +        return true;
       }
   
       /**
  
  
  
  1.1                  
xml-batik/test-references/samples/tests/spec/scripting/zeroSize.png
  
        <<Binary file>>
  
  
  1.97      +2 -1      
xml-batik/test-resources/org/apache/batik/test/samplesRendering.xml
  
  Index: samplesRendering.xml
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/test-resources/org/apache/batik/test/samplesRendering.xml,v
  retrieving revision 1.96
  retrieving revision 1.97
  diff -u -r1.96 -r1.97
  --- samplesRendering.xml      7 Jun 2003 17:19:18 -0000       1.96
  +++ samplesRendering.xml      19 Jun 2003 00:32:12 -0000      1.97
  @@ -373,6 +373,7 @@
           <test id="samples/tests/spec/scripting/visibility.svg" />
           <test id="samples/tests/spec/scripting/viewBoxOnLoad.svg" />
           <test id="samples/tests/spec/scripting/xyModifOnLoad.svg" />
  +        <test id="samples/tests/spec/scripting/zeroSize.svg" />
       </testGroup>
   
   </testSuite>
  
  
  
  1.1                  xml-batik/samples/tests/spec/scripting/zeroSize.svg
  
  Index: zeroSize.svg
  ===================================================================
  <?xml version="1.0" standalone="no"?>
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000802//EN"
  "http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.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.                                      -->
  <!-- ====================================================================== -->
  
  <!-- ====================================================================== -->
  <!-- Modification of a rect's attributes                                    -->
  <!--                                                                        -->
  <!-- @author [EMAIL PROTECTED]                                             -->
  <!-- @version $Id: zeroSize.svg,v 1.1 2003/06/19 00:32:12 deweese Exp $ -->
  <!-- ====================================================================== -->
  
  <?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?>  
  
  <svg id="body" width="450" height="500" viewBox="0 0 450 500">
    <title>Resizing zero w/h items 'onload'</title>
    <text x="50%" y="45" class="title">Resizing zero w/h items 'onload'</text>
  
    <script type="text/ecmascript"><![CDATA[
      function resizeRect(id, w, h) {
        var rect = document.getElementById(id);
        rect.setAttribute("width",  w);
        rect.setAttribute("height", h);
      }
      function resizeCircle(id, r) {
        var circle = document.getElementById(id);
        circle.setAttribute("r",  r);
      }
      function resizeEllipse(id, rx, ry) {
        var ellipse = document.getElementById(id);
        ellipse.setAttribute("rx",  rx);
        ellipse.setAttribute("ry",  ry);
      }
      ]]></script>
  
    <linearGradient id="testGrad" gradientUnits="objectBoundingBox"
      x1="0" y1="1" x2="1" y2="0">
      <stop offset="0" style="stop-color:crimson" />
      <stop offset="1" style="stop-color:gold" />
    </linearGradient>
  
    <g id="test-content">
      <g fill="red" stroke="black" stroke-width="2">
         <rect id="r1-1" x="10" y="60" width="0" height="0" 
          onload="resizeRect('r1-1', '50', '50')"/>
         <rect id="r1-2" x="70" y="60" width="50" height="0" 
          onload="resizeRect('r1-2', '50', '50')"/>
         <rect id="r1-3" x="130" y="60" width="0" height="50" 
          onload="resizeRect('r1-3', '50', '50')"/>
         <circle id="c1-1" cx="215" cy="85" r="0" 
          onload="resizeCircle('c1-1', '25')"/>
         <ellipse id="e1-1" cx="275" cy="85" rx="0" ry="0" 
          onload="resizeEllipse('e1-1', '25', '15')"/>
         <ellipse id="e1-2" cx="335" cy="85" rx="25" ry="0" 
          onload="resizeEllipse('e1-2', '25', '15')"/>
         <ellipse id="e1-3" cx="395" cy="85" rx="0" ry="15" 
          onload="resizeEllipse('e1-3', '25', '15')"/>
      </g>
  
      <g fill="url(#testGrad)" stroke="black" stroke-width="2">
         <rect id="r2-1" x="10" y="120" width="0" height="0" 
          onload="resizeRect('r2-1', '50', '50')"/>
         <rect id="r2-2" x="70" y="120" width="50" height="0" 
          onload="resizeRect('r2-2', '50', '50')"/>
         <rect id="r2-3" x="130" y="120" width="0" height="50" 
          onload="resizeRect('r2-3', '50', '50')"/>
         <circle id="c2-1" cx="215" cy="145" r="0" 
          onload="resizeCircle('c2-1', '25')"/>
         <ellipse id="e2-1" cx="275" cy="145" rx="0" ry="0" 
          onload="resizeEllipse('e2-1', '25', '15')"/>
         <ellipse id="e2-2" cx="335" cy="145" rx="50" ry="0" 
          onload="resizeEllipse('e2-2', '25', '15')"/>
         <ellipse id="e2-3" cx="395" cy="145" rx="0" ry="50" 
          onload="resizeEllipse('e2-3', '25', '15')"/>
      </g>
            
      <g fill="red" stroke="black" stroke-width="2">
         <rect id="r3-1" x="10" y="180" width="50" height="50" 
          onload="resizeRect('r3-1', '0', '0')"/>
         <rect id="r3-2" x="70" y="180" width="50" height="50" 
          onload="resizeRect('r3-2', '50', '0')"/>
         <rect id="r3-3" x="130" y="180" width="50" height="50" 
          onload="resizeRect('r3-3', '0', '50')"/>
         <circle id="c3-1" cx="215" cy="205" r="25" 
          onload="resizeCircle('c3-1', '0')"/>
         <ellipse id="e3-1" cx="275" cy="205" rx="25" ry="15" 
          onload="resizeEllipse('e3-1', '0', '0')"/>
         <ellipse id="e3-2" cx="335" cy="205" rx="25" ry="15" 
          onload="resizeEllipse('e3-2', '25', '0')"/>
         <ellipse id="e3-3" cx="395" cy="205" rx="25" ry="15" 
          onload="resizeEllipse('e3-3', '0', '15')"/>
      </g>
  
      <g fill="url(#testGrad)" stroke="black" stroke-width="2">
         <rect id="r4-1" x="10" y="240" width="50" height="50" 
          onload="resizeRect('r4-1', '0', '0')"/>
         <rect id="r4-2" x="70" y="240" width="50" height="50" 
          onload="resizeRect('r4-2', '50', '0')"/>
         <rect id="r4-3" x="130" y="240" width="50" height="50" 
          onload="resizeRect('r4-3', '0', '50')"/>
         <circle id="c4-1" cx="215" cy="265" r="25" 
          onload="resizeCircle('c4-1', '0')"/>
         <ellipse id="e4-1" cx="275" cy="265" rx="25" ry="15" 
          onload="resizeEllipse('e4-1', '0', '0')"/>
         <ellipse id="e4-2" cx="335" cy="265" rx="25" ry="15" 
          onload="resizeEllipse('e4-2', '25', '0')"/>
         <ellipse id="e4-3" cx="395" cy="265" rx="25" ry="15" 
          onload="resizeEllipse('e4-3', '0', '15')"/>
      </g>
    </g>
  </svg>
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to