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 Thomas Estier <th...@epfl.ch> on 2003/03/17 12:04:25 UTC
bounding box of a svg element
Hello,
I'm implementing a J(DOM)tree allowing to zoom and pan (the JSVGCanvas)
on the element selected in the tree.
Inspired by FindDialog class of Squiggle, I implemented this function as
shown bellow. I'm not sure if it is the best way to do this.
My problem is : It doesn't take into account the successive transform of
parent nodes. (given by <g transform="translate(100,200)"> for instance)
Do I need to parse each "transform" attribute of the parents ?
Is there a simpler way to implement this functionnality (getting the
global bounding box of an element)?
Thanks
Tom
[...]
if (node instanceof SVGLocatable) {
SVGRect bb = ((SVGLocatable)node).getBBox();
Rectangle2D shape;
try {
shape = new
Rectangle2D.Double(bb.getX(),bb.getY(),bb.getWidth(),bb.getHeight());
} catch (NullPointerException e) { return;}
AffineTransform at;
boolean centerZoom = false;
if (centerZoom) {
at = svgCanvas.getInitialTransform();
} else {
at = svgCanvas.getRenderingTransform();
}
Rectangle2D gnb = at.createTransformedShape(shape).getBounds();
Dimension canvasSize = svgCanvas.getSize();
AffineTransform Tx = AffineTransform.getTranslateInstance(
-gnb.getX()-gnb.getWidth()/2,
-gnb.getY()-gnb.getHeight()/2);
if (centerZoom) {
double sx = canvasSize.width/gnb.getWidth();
double sy = canvasSize.height/gnb.getHeight();
double scale = Math.min(sx,sy);
if (scale > 1) {
Tx.preConcatenate(AffineTransform.getScaleInstance(scale,scale));
}
}
Tx.preConcatenate(AffineTransform.getTranslateInstance(
canvasSize.width/2,canvasSize.height/2));
AffineTransform newRT = new AffineTransform(at);
newRT.preConcatenate(Tx);
svgCanvas.setRenderingTransform(newRT);
}
[...]
--
______________________________________
Thomas Estier
Field and Space Robotics
Autonomous Systems Lab
I2S-LSA
Swiss Federal Institute of Technology
1015 Lausanne EPFL
Switzerland
Tel, Fax (+41 21 693) 38 85 / 78 07
http://dmtwww.epfl.ch/isr/asl/
email: thomas.estier@epfl.ch
______________________________________
IEEE/RSJ International Conference on
Intelligent Robots and Systems
IROS 2002 : http://iros02.epfl.ch
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org