xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jake B" <otakuj...@gmail.com>
Subject Re: Best way to get the the bbox of an object with respect to its transformations?
Date Sat, 22 Sep 2007 13:30:23 GMT
Thank you for your help.

Jake

On 9/22/07, thomas.deweese@kodak.com <thomas.deweese@kodak.com> wrote:
>
> Hi Jake,
>
> "Jake B" <otakuj462@gmail.com> wrote on 09/21/2007 10:27:06 PM:
>
> > Quick follow-up question to this. I believe that getScreenCTM
> > returns the transformation matrix mapping user coordinates to the
> > coordinates of the top-level viewport.
>
>    No, it returns the transform to the screen coordinate system
> (screen pixels).
>
> > If the element is inside of a nested viewport, is there a way
> > to retrieve the transformation matrix  to translate user
> > coordinates into the nested viewport coordinate system?
>
>    Yes, I mentioned it below, getTransformToElement(SVGElement elem).
> Pass that the nested viewport element and it will give you
> the transform to that element's local coordinate system.
>
>    I suggest you read about the SVGLocatable Interface in
> the SVG spec:
>    http://www.w3.org/TR/SVG11/types.html#InterfaceSVGLocatable
>
> > Thanks again for your help.
> >
> > Jake
>
> > On 9/12/07, Jake B <otakuj462@gmail.com> wrote:
> > Works great! Thank you so much for your help!
> >
> > Jake
> >
>
> > On 9/12/07, thomas.deweese@kodak.com < thomas.deweese@kodak.com> wrote:
> > Hi Jake,
> >
> > "Jake B" <otakuj462@gmail.com> wrote on 09/09/2007 08:28:25 PM:
> >
> > > I was wondering, is there was a simple way to calculate the
> > > bounding box of an SVG element with respect to its transformations?
> >
> >    The simple question here is it's bounding box in what coordinate
> > system?  The most common requests are either the root of the SVG
> > tree (the root SVG elements local coordinate system), and screen pixels.
>
> >
> > > The getBBox method does not seem to take transformations into account.
> >
> >    Correct getBBox returns the bounding box in the local coordinate
> > system of the element.  What you need to do is take that bbox and
> > map it to your desired coordinate system.
> >
> >    SVG provides fairly good methods for doing that.  The two methods
> > that you might need to use are: getScreenCTM and getTransformToElement.
> > You can use these to get the Affine transform from the local coordinate
> > system of the element to the screen or any other element's local
> > coordinate system respectively.
> >
> >    Once you have that transform you can use code like (this is js
> > but mapping it to Java is just adding types mostly):
> >     var bbox = elem.getBBox();
> >     var mat = elem.screenCTM();  // could also be tranformToElement
> >     var cPt     = document.getRootElement().createSVGPoint();
> >     cPt.x = bbox.x;
> >     cPt.y = bbox.y;
> >     cPt   = cPt.matrixTransform(mat);
> >     // repeat for other corner points and the new bbox is
> >     // simply the minX/minY  to maxX/maxY of the four points.
> >
> > > I'm using the transform attribute because it seems to be the easiest
> > > and most elegant way to translate a group of elements.
> >
> >    Yes, it is.
> >
> > > However, it is definitely necessary for me to get the bounding box
> > > of the group with respect to its transformations so that it is
> > > locatable within the SVG viewport.
> >
> >    Right.
> >
> > > If there is not an easy way to get the bounding
> > > box of an element with respect to its transform, it seems like there
> > > are only two alternatives: to make a newer, smarter getBBox method
> > > that does take transforms into account, or to not use translate,
> > > instead recursively changing the coordinates of every member of a
> > > group and its children. However, neither of these seems like a very
> > > pretty solution, so I am somewhat stuck...
> > > I would greatly appreciate any guidance anyone can provide. Thanks.
> >
> >    I hope the above helps.
> >
> >
> > ---------------------------------------------------------------------
> > 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
>
>

Mime
View raw message