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 fireball <sa...@hotmail.com> on 2012/11/01 16:19:19 UTC

How to set rotation using an existing API

I am using AffineTransform to rotate SVG elements but as far as I understand
it only provides two methods to rotate. One sets it identity matrix with a
rotation (setToRotation(theta)) and another rotates by a delta
(rotate(theta)).

What I want to do is set rotation to specific angle. I.e. I don't want to
set its matrix to identity matrix nor do I want to rotate by delta. I want
to be able to set rotation like we can by setting 'rotate' attribute. Is
there a way to do it using AffineTransform or another API?



--
View this message in context: http://batik.2283329.n4.nabble.com/How-to-set-rotation-using-an-existing-API-tp4655329.html
Sent from the Batik - Users mailing list archive at Nabble.com.

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


Re: How to set rotation using an existing API

Posted by fireball <sa...@hotmail.com>.
No it doesn't. It does not maintain the matrix. Here is an example,

/Original matrix:/
matrix(2.0, 0.0, 0.0, 2.0, 300.0, 300.0)

/Apply rotate(Math.toRadians(30)):/ *<-- This one is OK but I cannot use it
because it adds 30 and not set to 30*
matrix(1.7, 0.9, -0.9, 1.7, 300.0, 300.0) 

/Apply setToRotate(Math.toRadians(30)):/ *<-- This one is not good because
it does not maintain my original location. Plus, it should have not changed
the matrix at all because it is resetting to 30 again.*
matrix(0.8, 0.4, -0.4, 0.8, 0.0, 0.0) 

I guess my only option is to do some logic myself like finding the screen
location of the element before applying the rotation and then resetting the
location after?



--
View this message in context: http://batik.2283329.n4.nabble.com/How-to-set-rotation-using-an-existing-API-tp4655329p4655342.html
Sent from the Batik - Users mailing list archive at Nabble.com.

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


Re: How to set rotation using an existing API

Posted by DeWeese Thomas <th...@gmail.com>.
Hi Fireball,

    Well this does set your element to the specified rotation just like you had change the transform attribute to 
"rotate(rotationAngleInDegrees)", doesn't it?  What did you want it to do?  Just add an additional rotation?
In that case you want to either preMultiply or postMultiply 'at' by a new AffineTransform with your rotation
(which is appropriate depends on where you want to rotate).

You also mentioned describing what you wanted in terms of adding a rotate element to the text transform.
So simply doing that textually is always an option.

    Thomas

On Nov 2, 2012, at 9:49 AM, fireball <sa...@hotmail.com> wrote:

> Thanks Thomas for your reply. 
> 
> I am not sure what you mean by general affine transform but I have posted my
> code below so maybe you can confirm that is what I am doing or not.
> 
>        Element element = document.getElementById(elementId);
>        String transform = element.getAttributeNS(null,
> SVGConstants.SVG_TRANSFORM_ATTRIBUTE);
>        TransformListParser tlp = new TransformListParser();
>        AWTTransformProducer tp = new AWTTransformProducer();
>        tlp.setTransformListHandler(tp);
>        tlp.parse(transform);
>        AffineTransform at = tp.getAffineTransform();
>        at.setToRotation(Math.toRadians(rotatationAngleInDegrees));
>        element.setAttributeNS(null, SVGConstants.SVG_TRANSFORM_ATTRIBUTE,
> getString(at));
> 
> 
> 
> --
> View this message in context: http://batik.2283329.n4.nabble.com/How-to-set-rotation-using-an-existing-API-tp4655329p4655334.html
> Sent from the Batik - Users mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


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


Re: How to set rotation using an existing API

Posted by fireball <sa...@hotmail.com>.
Thanks Thomas for your reply. 

I am not sure what you mean by general affine transform but I have posted my
code below so maybe you can confirm that is what I am doing or not.

        Element element = document.getElementById(elementId);
        String transform = element.getAttributeNS(null,
SVGConstants.SVG_TRANSFORM_ATTRIBUTE);
        TransformListParser tlp = new TransformListParser();
        AWTTransformProducer tp = new AWTTransformProducer();
        tlp.setTransformListHandler(tp);
        tlp.parse(transform);
        AffineTransform at = tp.getAffineTransform();
        at.setToRotation(Math.toRadians(rotatationAngleInDegrees));
        element.setAttributeNS(null, SVGConstants.SVG_TRANSFORM_ATTRIBUTE,
getString(at));



--
View this message in context: http://batik.2283329.n4.nabble.com/How-to-set-rotation-using-an-existing-API-tp4655329p4655334.html
Sent from the Batik - Users mailing list archive at Nabble.com.

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


Re: How to set rotation using an existing API

Posted by DeWeese Thomas <th...@gmail.com>.
Hi fireball,

On Nov 1, 2012, at 11:19 AM, fireball <sa...@hotmail.com> wrote:

> I am using AffineTransform to rotate SVG elements but as far as I understand
> it only provides two methods to rotate. One sets it identity matrix with a
> rotation (setToRotation(theta)) and another rotates by a delta
> (rotate(theta)).
> 
> What I want to do is set rotation to specific angle. I.e. I don't want to
> set its matrix to identity matrix nor do I want to rotate by delta.

	The first method sets it to a specific rotation, not an identity matrix so it seems that is what you
want.


> I want to be able to set rotation like we can by setting 'rotate' attribute. Is
> there a way to do it using AffineTransform or another API?

	setToRotation does exactly what the 'rotate' function' does in the SVG transform attribute.

	I'm a little afraid that you are trying to adjust a general affine transform (that may have non-uniform
scaling and skew) so that it has a specific rotation. I'm afraid that is what you want to do because you can't 
really do it without coming up with a perhaps non-sensical definition of rotation...

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