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 Charles Abreu <ch...@gmail.com> on 2006/04/26 21:51:08 UTC

JSVGCanvas - positioning a displayed drawing point in the center of the canvas

Hi all,

I need to position a specified point of the displayed drawing on the certer
of the canvas (drawing area), regardless of the canvas size and the drawing
scale. The point will be specified by a parameter. There is no mouse clicked
involved. Could anybody help me with a code snippet with the transforms that
must be applied?

thanks
Charles

Re: JSVGCanvas - positioning a displayed drawing point in the center of the canvas

Posted by th...@kodak.com.
Hi Charles,

"Charles Abreu" <ch...@gmail.com> wrote on 04/27/2006 09:48:25 AM:

> I have an svg drawing file which contains the following line:
> 
> <svg width="400" height="200" viewBox="0 0 400 200">
> 
> ...and I have a canvas sized to 800x600.
> 
> When I load the svg file into the canvas, the drawing expands to fill 
the canvas area. 
> Suppose I want to move center point (200, 100) of the _drawing the file_ 
to 
> the point (0,0) of the canvas.

    Use 'SVGLocatable.getScreenCTM()'  This returns the matrix from any 
element
in the SVG file to the screen.  So if you call it on the root SVG element 
it will
give you what I think you want (it's important to remember that this 
transform
can be different for different parts of the document, so just having a 
point
is not enough you need to know what coordinate system that point is in - 
your
example is using the local coordinate system of the root element).

> To accomplish it, I discovered I need to apply 
> a (-400, -200) translate transformation, not a (-200, -100), due to the 
scale 
> previously applied to the drawing when loaded into the canvas. How can I 
find 
> out that scale? Or, how can I get the coordinates translated? 
> 
> Thanks!
> 
> Charles
> 

> On 4/27/06, thomas.deweese@kodak.com < thomas.deweese@kodak.com> wrote:
> Hi Charles,
> 
> "Charles Abreu" < charlesabreu@gmail.com> wrote on 04/26/2006 03:51:08 
PM:
> 
> > I need to position a specified point of the displayed drawing on the
> certer of
> > the canvas (drawing area), regardless of the canvas size and the 
drawing 
> 
> > scale. The point will be specified by a parameter. There is no mouse
> clicked
> > involved. Could anybody help me with a code snippet with the 
transforms
> that
> > must be applied?
> 
>    I can't provide real code, but you should look at 
> batik.apps.svgbrowser.FindDialog this does essentially what you want
> around line 350.  You might need to do some extra manipulations
> of the given point depending on the coordinate system you need the
> point in. 
> 
>    But the basic idea is to move the point you want centered on
> the screen to 0,0:
> 
>         // translate the highlight region to (0, 0) in the canvas
> coordinate
>         // system
>         AffineTransform Tx = AffineTransform.getTranslateInstance
>             (-gnb.getX()-gnb.getWidth()/2,
>              -gnb.getY()-gnb.getHeight()/2);
> 
>    The move it to the center of the canvas:
> 
>         Dimension canvasSize = svgCanvas.getSize ();
>         Tx.preConcatenate(AffineTransform.getTranslateInstance
>                           (canvasSize.width/2, canvasSize.height/2));
> 
>    In your case you will probably need to preConcatenate this with
> the current rendering transform (the find dialog does a wholesale 
> replacement of the rendering transform).
> 
> 
> ---------------------------------------------------------------------
> 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: JSVGCanvas - positioning a displayed drawing point in the center of the canvas

Posted by Charles Abreu <ch...@gmail.com>.
Hi, Thomas.

Thanks for your help! I think the problem I am facing comes before this
transformations you provided. The problem is that I cannot find a way to
translate the drawing coordinates to the canvas coordinates. I'm hardly a
expert in the graphics area, so let me try to explain with an example of
what I'm trying to do.

I have an svg drawing file which contains the following line:

<svg width="400" height="200" viewBox="0 0 400 200">

...and I have a canvas sized to 800x600.

When I load the svg file into the canvas, the drawing expands to fill the
canvas area.
Suppose I want to move center point (200, 100) of the _drawing the file_ to
the point (0,0) of the canvas. To accomplish it, I discovered I need to
apply a (-400, -200) translate transformation, not a (-200, -100), due to
the scale previously applied to the drawing when loaded into the canvas. How
can I find out that scale? Or, how can I get the coordinates translated?

Thanks!

Charles


On 4/27/06, thomas.deweese@kodak.com <th...@kodak.com> wrote:
>
> Hi Charles,
>
> "Charles Abreu" <ch...@gmail.com> wrote on 04/26/2006 03:51:08 PM:
>
> > I need to position a specified point of the displayed drawing on the
> certer of
> > the canvas (drawing area), regardless of the canvas size and the drawing
>
> > scale. The point will be specified by a parameter. There is no mouse
> clicked
> > involved. Could anybody help me with a code snippet with the transforms
> that
> > must be applied?
>
>    I can't provide real code, but you should look at
> batik.apps.svgbrowser.FindDialog this does essentially what you want
> around line 350.  You might need to do some extra manipulations
> of the given point depending on the coordinate system you need the
> point in.
>
>    But the basic idea is to move the point you want centered on
> the screen to 0,0:
>
>         // translate the highlight region to (0, 0) in the canvas
> coordinate
>         // system
>         AffineTransform Tx = AffineTransform.getTranslateInstance
>             (-gnb.getX()-gnb.getWidth()/2,
>              -gnb.getY()-gnb.getHeight()/2);
>
>    The move it to the center of the canvas:
>
>         Dimension canvasSize = svgCanvas.getSize();
>         Tx.preConcatenate(AffineTransform.getTranslateInstance
>                           (canvasSize.width/2, canvasSize.height/2));
>
>    In your case you will probably need to preConcatenate this with
> the current rendering transform (the find dialog does a wholesale
> replacement of the rendering transform).
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>

Re: JSVGCanvas - positioning a displayed drawing point in the center of the canvas

Posted by th...@kodak.com.
Hi Charles,

"Charles Abreu" <ch...@gmail.com> wrote on 04/26/2006 03:51:08 PM:

> I need to position a specified point of the displayed drawing on the 
certer of
> the canvas (drawing area), regardless of the canvas size and the drawing 

> scale. The point will be specified by a parameter. There is no mouse 
clicked 
> involved. Could anybody help me with a code snippet with the transforms 
that 
> must be applied? 

   I can't provide real code, but you should look at 
batik.apps.svgbrowser.FindDialog this does essentially what you want
around line 350.  You might need to do some extra manipulations
of the given point depending on the coordinate system you need the
point in.

   But the basic idea is to move the point you want centered on
the screen to 0,0:

        // translate the highlight region to (0, 0) in the canvas 
coordinate
        // system
        AffineTransform Tx = AffineTransform.getTranslateInstance
            (-gnb.getX()-gnb.getWidth()/2,
             -gnb.getY()-gnb.getHeight()/2);

   The move it to the center of the canvas:

        Dimension canvasSize = svgCanvas.getSize();
        Tx.preConcatenate(AffineTransform.getTranslateInstance
                          (canvasSize.width/2, canvasSize.height/2));

   In your case you will probably need to preConcatenate this with
the current rendering transform (the find dialog does a wholesale
replacement of the rendering transform).


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