You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Oliver Brook <ol...@gmx.de> on 2008/02/25 20:01:12 UTC

Unexpected behaviour of SVGTransform

Hi everybody,

In my application I am translating, scaling and rotating elements  
using a transform attribute on each element in the following way:

transform="translate(x,y) scale(s) rotate(r, cx, cy)"

In order to edit the transforms of each element in my document I am  
accessing the element's SVGTransformList and then editing the  
properties of the SVGTransforms in the list. This works great except  
for rotation transforms. When I use SVGTransform.setRotate(rotation,  
cx, cy) the canvas is updated as it should be and the element is  
rotated by the correct amount around cx,cy. If, however, I then call  
System.out.println(e.getAttribute("transform")) I can see the rotation  
amount but the optional cx and cy components of the rotate transform  
are missing from the DOM. This means that when save my document to a  
file the resulting svg document has all of the rotate transforms  
acting around the origin and, as a result, is a complete mess.

The code I am using to rotate an element looks like this:

SVGTransformable s = (SVGTransformable) e;
         SVGAnimatedTransformList atl = s.getTransform();
         SVGTransformList tl = atl.getBaseVal();
         AbstractSVGTransform trans = (AbstractSVGTransform)  
tl.getItem(2);
         if (trans.getType() == trans.SVG_TRANSFORM_ROTATE) {
         trans.setRotate(initialAngle + differenceAngle,  
center.getX(), center.getY());

I can not understand why the element would be displayed correctly  
inside Batik even though the DOM is not being correctly updated. Is it  
possible that the GVT tree is being updated and the DOM is not?

I have thoroughly checked the rest of my program and am pretty certain  
the problem is with my use of this method. Can anyone see an error I  
am making here, or is this a Batik bug?

Any help would be greatly appreciated.

Oliver

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


Re: Unexpected behaviour of SVGTransform

Posted by Cameron McCormack <ca...@mcc.id.au>.
Hi Oliver.

Oliver Brook:
> In my application I am translating, scaling and rotating elements  
> using a transform attribute on each element in the following way:
> 
> transform="translate(x,y) scale(s) rotate(r, cx, cy)"
> 
> In order to edit the transforms of each element in my document I am  
> accessing the element's SVGTransformList and then editing the  
> properties of the SVGTransforms in the list. This works great except  
> for rotation transforms. When I use SVGTransform.setRotate(rotation,  
> cx, cy) the canvas is updated as it should be and the element is  
> rotated by the correct amount around cx,cy. If, however, I then call  
> System.out.println(e.getAttribute("transform")) I can see the rotation  
> amount but the optional cx and cy components of the rotate transform  
> are missing from the DOM. This means that when save my document to a  
> file the resulting svg document has all of the rotate transforms  
> acting around the origin and, as a result, is a complete mess.
…
> I have thoroughly checked the rest of my program and am pretty certain  
> the problem is with my use of this method. Can anyone see an error I  
> am making here, or is this a Batik bug?

I tried calling setRotate() using script, and the DOM attribute seemed
to update for me:

  <svg xmlns='http://www.w3.org/2000/svg'>
    <g id='g' transform='translate(0,0) scale(1) rotate(1,2,3)'/>
    <script>
      var g = document.getElementById('g');
      var item = g.transform.baseVal.getItem(2);
      item.setRotate(4, 5, 6);
      alert(g.getAttribute('transform'));
    </script>
  </svg>

What version of Batik are you using?  Does the above document alert the
right attribute value?

-- 
Cameron McCormack, http://mcc.id.au/
	xmpp:heycam@jabber.org  ▪  ICQ 26955922  ▪  MSN cam@mcc.id.au

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