Hi Charles,
"Charles Abreu" <[EMAIL PROTECTED]> 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, [EMAIL PROTECTED] < [EMAIL PROTECTED]> wrote:
> Hi Charles,
>
> "Charles Abreu" < [EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]