Hi All,
I'm modifying the Batik Squiggle program into a
drawing tool. I can draw a bounding box (rectangle) on the screen around an
element using getbbox() , but if I zoom and do getbbox() again, the box
isn't in the right place.
I have the following code that is executed by mouse
click:
if ((elt != null) && elt
instanceof SVGOMPathElement)
{
SVGOMPathElement s = (SVGOMPathElement) elt; Graphics g =
svgCanvas.getGraphics();
SVGRect svgr = s.getBBox(); int x = new Float(svgr.getX()).intValue(); int y = new Float(svgr.getY()).intValue(); int width = new Float(svgr.getWidth()).intValue(); int height = new Float(svgr.getHeight()).intValue(); SVGOMPoint spoint; SVGPoint spointInv; spoint = new SVGOMPoint(x,
y);
SVGMatrix svgMatrix =
s.getTransformToElement((SVGElement)s.getParentNode());
SVGMatrix invMat = svgMatrix.inverse(); spointInv =
spoint.matrixTransform(invMat);
int newX = new
Float(spointInv.getX()).intValue();
int newY = new Float(spointInv.getY()).intValue(); g.drawRect(newX, newY, width,
height);
}
How can I make it work no matter whether I have
zoomed or not?
Regards,
Ron
|
- Re: drawing a rectangle using getbbox Ron King
- Re: drawing a rectangle using getbbox Thomas DeWeese