Stefán Freyr Stefánsson wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

It was pointed out to me by Mr. Thomas DeWeese that I could use SVGLocatable.getBBox() to find the location and size of elements in a SVG document.

I did manage to get it to work... in a way... but I'm still having some problems and I'm hoping that someone can explain some things for me.

First off: Does anybody know where I can find JavaDoc for the org.w3c.dom.svg stuff? There are JavaDoc pages for that package on the Batik web site but there is no text... just the skeleton html.

The SVG Specification defines these interfaces.


But now for what I've managed to do and the problems I'm running into:
[...]
So I've been trying to parse the original file and get the <use> elements that have the "embla:chair-id" attribute in order to find out where I should put the <svg> elements in each of the layers.

Now, there is no problem finding the elements and all but I'm having problems working with the getBBox() method to get the correct location, width and height.

The BBox returned is in the local coordinate system of the element (0, 0) is at x,y for the use element. You want to transform the bbox to the coordinate system of another element. This is what the SVGLocatable.getTransformToElement(SVGLocatable) is for:

SVGMatrix mat = element.getTransformToElement(element.getParentNode())

  Gives the transform from element to it's parent you should probably
use the group that you want to add the SVG elements to instead of
the use element's parent (and you will probably have to add some casts).

Here is a code snippet:
    ArrayList chairs = getAllChairElements( root );

    for( int i = 0; i < chairs.size(); i++ )
    {
        System.out.println( chairs.get( i ).getClass() );

        SVGLocatable element = (SVGLocatable) chairs.get( i );
        SVGRect bbox = element.getBBox();

System.out.println( "\tUse Element Location: (" + bbox.getX() + ", " + bbox.getY() + "); " +
"Width: " + bbox.getWidth() + "; " +
"Height: " + bbox.getHeight() );
}


But here's what this code will write out:
class org.apache.batik.dom.svg.SVGOMUseElement
        Use Element Location: (-0.75, -0.75); Width: 401.5; Height: 401.5
class org.apache.batik.dom.svg.SVGOMUseElement
        Use Element Location: (-0.75, -0.75); Width: 401.5; Height: 401.5
class org.apache.batik.dom.svg.SVGOMUseElement
        Use Element Location: (-0.75, -0.75); Width: 401.5; Height: 401.5
class org.apache.batik.dom.svg.SVGOMUseElement
        Use Element Location: (-0.75, -0.75); Width: 401.5; Height: 401.5
class org.apache.batik.dom.svg.SVGOMUseElement
        Use Element Location: (-0.75, -0.75); Width: 401.5; Height: 401.5

So... can anybody help me out with this a bit? I've managed to understand that the -0.75 is because that's the half of the line width... so a line width of 4 would result in (-2.0, -2.0) to be displayed... so this seems to be the "offset" from the actual defined location for x and y of the object. The height is basically correct... the rectangles are 401.5 in height and width. But this is not what I'm looking for! :o( Can anybody help me find the actual location of the elements on the canvas?

Another thing: Is there any way of calculating this without actually having to draw this thing to screen? Is there any "non-gui" version of this that actually renders the image without displaying it to the screen? The reason I ask this is that this processing should be performed once in our system and should be done centrally... that is on a server that will then serve the produced image to the clients. But I don't want to make the server have to have a window environment.

I hope someone can help.

Kind regards, Stefan Freyr.

p.s. sorry for the long post.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iQEVAwUBP1dCYL0ge6mq4AL2AQJhNQf/SctDf5Fft+INQHo/nMNmuOccfdwIm+c0
nvQ08p6hJD8tgRNRoaAzFzZUEg0kR1iDWFMG/Mrpve2srP5GQ6ggvrm1yxUPj/t8
AIl8QehZmJw+//GVoiJ6qENYdg4r8k4kIEFFnKGJ3eurRpPZXkmppEqS69Tf9hvg
r12JJvzEn5w+W3fGNKPIVS8w4qwkAUBLlPs/iDuLyqh2Z5rmn9CnjJaD2fffkSUD
9brTKcwMaRPHJj6pIBNpuRXu0pEyIw6p6ZVbew36U65bKy0pgG+iQqAYo67p4i8t
idHakIXBskjztgekF/d+HnCUhFZa9Hdci7AiJLjMIkjdt01zV0ZK1w==
=iJnJ
-----END PGP SIGNATURE-----


--------------------------------------------------------------------- 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]



Reply via email to