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 Alan Deikman <Al...@znyx.com> on 2009/03/12 03:37:14 UTC
Re: JSVGCanvas Rotation with AffineTransform
Thomas Palfray wrote:
> Thanks for your answer.
>
> thomas.deweese@kodak.com a écrit :
>>
>> Hi Thomas,
>>
>> Thomas Palfray <th...@gmail.com> wrote on 10/25/2008
>> 05:08:39 AM:
>>
>> > Well, i'm working on an application wich need to rotate a JSVGCanvas
>> > (90°, 180°, 270°). I used AffineTransform and the method
>> > setRenderingTransform like that :
>>
>> If you only need to support 90, 180 & 270 deg rotations.
>> I would suggest simply hard coding the correction factors.
>> For 90deg it will be a translate in X by the height before rotation.
>> for 180 deg it will be translate in X by the width and
>> in Y by the height (both before rotation), for 270 a
>> translate in Y by the width before rotation.
I'm having the same problem -- I have a JSVGCanvas I want to paint in
different orientations. I have tried the setRenderingTransform()
method with no success -- it just gets overwritten by some other logic
within batik with the identity transform when the component is resized.
Question: at what point can setRenderingTransform(at, true) be used or
is meaningful within the lifecycle of GVT rendering process?
Another question -- is there anything to read to understand the usage of
the different transforms in JSVGCanvas? You have the initial
transform, rendering transform, viewing transform, viewbox transform,
and painting transform.
Thanks in advance for any pointers.
--
Alan Deikman
ZNYX Networks
Re: JSVGCanvas Rotation with AffineTransform
Posted by Alan Deikman <Al...@znyx.com>.
Alan Deikman wrote:
>
> The JSVGCanvas shows up in the right place in the right bounding box,
> but the image within is not rotated. As the output shows, something
> overwrites the rotation transform with a new identity transform. My
> question is at one point does the setRenderingTransform() /not/ get
> over-written this way?
>
I solved this one last weekend, but it brings up a new problem which I
will start a new thread with.
The problem was that I thought I was doing the setRenderingTransform()
in the UpdateManager's thread. I was -- but it was a thread associated
with the /parent /JSVGCanvas, not the "child" JSVGCanvas that was being
rotated and zoomed. Once I deferred the execution of my code into the
UpdateManager thread started by JSVGCanvas that was being rotated, it
all started to work fine.
Hopefully with this in the mailing list archive someone else can avoid
the same mistake.
--
Alan Deikman
Re: JSVGCanvas Rotation with AffineTransform
Posted by Alan Deikman <Al...@znyx.com>.
Thomy wrote:
> I answered this question recently.
> Here is a snap of my source code :
>
>
Thank you for answering -- I do something similar but it doesn't work.
Here is an excerpt of my code, which executes in the UpdateManager's thread:
if (display.position != null) {
SVGRect bbox = display.position.getBBox();
Point2D ul = new Point2D.Float(bbox.getX(), bbox.getY());
Point2D lr = new Point2D.Float(bbox.getX() +
bbox.getWidth(),
bbox.getY() + bbox.getHeight());
AffineTransform t = getViewBoxTransform();
t.transform(ul, ul);
t.transform(lr, lr);
display.panel.setBounds((int) ul.getX(), (int) ul.getY(),
(int) (lr.getX() - ul.getX()),
(int) (lr.getY() - ul.getY()));
if (isRotationNeeded(display.panel)) {
AffineTransform at =
display.panel.getRenderingTransform();
at.rotate(Math.PI/2);
display.panel.setRenderingTransform(at);
}
display.panel.setVisible(true);
}
Hopefully the definitions are clear from context. In order to figure
out what is going on, in the JSVGCanvas sub-class (display.panel in the
example) I implemented the following overrides:
@Override public void setRenderingTransform(AffineTransform t,
boolean doRedraw) {
System.out.println("setRenderingTransform: " + t.toString());
super.setRenderingTransform(t, doRedraw);
}
@Override public void resize(int width, int height) {
System.out.println("resize " + width + " " + height);
super.resize(width, height);
}
@Override public void reshape(int x, int y, int width, int height) {
System.out.println("reshape (" + x + ", " + y + ", " + width +
", " + height + ")");
super.reshape(x,y,width,height);
}
This results in the following output:
setRenderingTransform: AffineTransform[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
reshape (128, 0, 26, 296)
setRenderingTransform: AffineTransform[[0.0, -1.0, 0.0], [1.0, -0.0, 0.0]]
setRenderingTransform: AffineTransform[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
gvtRenderingPrepare
gvtRenderingStart
The JSVGCanvas shows up in the right place in the right bounding box,
but the image within is not rotated. As the output shows, something
overwrites the rotation transform with a new identity transform. My
question is at one point does the setRenderingTransform() /not/ get
over-written this way?
--
Alan Deikman
ZNYX Networks
Re: JSVGCanvas Rotation with AffineTransform
Posted by Thomy <th...@gmail.com>.
Hi Alan,
I answered this question recently.
Here is a snap of my source code :
public void setSVGAffineTransformation(){
AffineTransform tx = svgCanvas.getRenderingTransform();
// Zoom Level
tx.setToScale(zoomLevel(),zoomLevel());
// The user want to rotate ???
if(Main.getFenetrePrincipale().getZoomControl().getAngleRotation() != 0){
// Sinus of Rotation angle
double sinA =
Math.sin(Main.getFenetrePrincipale().getZoomControl().getAngleRotation());
// Do the rotation on the center of the picture
tx.rotate(Main.getFenetrePrincipale().getZoomControl().getAngleRotation(),
Main.getFenetrePrincipale().getFenetreManuscrit().getPaintCanvas().getImage().getWidth(null)
/2,
Main.getFenetrePrincipale().getFenetreManuscrit().getPaintCanvas().getImage().getHeight(null)/2);
// Do the translation, depend on the sinus
if(sinA == 1)
{
tx.translate(-sinA *
Main.getFenetrePrincipale().getFenetreManuscrit().getPaintCanvas().getRect().getX(),
-sinA *
Main.getFenetrePrincipale().getFenetreManuscrit().getPaintCanvas().getRect().getY());
}
else
{
tx.translate(sinA *
Main.getFenetrePrincipale().getFenetreManuscrit().getPaintCanvas().getRect().getX(),
sinA *
Main.getFenetrePrincipale().getFenetreManuscrit().getPaintCanvas().getRect().getY());
}
}
// set the rendering :)
svgCanvas.setRenderingTransform(tx);
}
The wrong position of the JSVGCanvas was due to a mathematical error :)
Check the translate method.
Hope this will help
Alan Deikman wrote:
>
> Thomas Palfray wrote:
>> Thanks for your answer.
>>
>> thomas.deweese@kodak.com a écrit :
>>>
>>> Hi Thomas,
>>>
>>> Thomas Palfray <th...@gmail.com> wrote on 10/25/2008
>>> 05:08:39 AM:
>>>
>>> > Well, i'm working on an application wich need to rotate a JSVGCanvas
>>> > (90°, 180°, 270°). I used AffineTransform and the method
>>> > setRenderingTransform like that :
>>>
>>> If you only need to support 90, 180 & 270 deg rotations.
>>> I would suggest simply hard coding the correction factors.
>>> For 90deg it will be a translate in X by the height before rotation.
>>> for 180 deg it will be translate in X by the width and
>>> in Y by the height (both before rotation), for 270 a
>>> translate in Y by the width before rotation.
> I'm having the same problem -- I have a JSVGCanvas I want to paint in
> different orientations. I have tried the setRenderingTransform()
> method with no success -- it just gets overwritten by some other logic
> within batik with the identity transform when the component is resized.
>
> Question: at what point can setRenderingTransform(at, true) be used or
> is meaningful within the lifecycle of GVT rendering process?
>
> Another question -- is there anything to read to understand the usage of
> the different transforms in JSVGCanvas? You have the initial
> transform, rendering transform, viewing transform, viewbox transform,
> and painting transform.
>
> Thanks in advance for any pointers.
>
> --
> Alan Deikman
> ZNYX Networks
>
>
>
--
View this message in context: http://www.nabble.com/JSVGCanvas-Rotation-with-AffineTransform-tp20162475p22472250.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