xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steiner, Dominik" <Dominik.Stei...@gigatronik.com>
Subject AW: getbbox() and update view problems
Date Mon, 01 Aug 2005 15:15:55 GMT
Thank you very much Andres and Thomas,

I got the point on 2)...

But I'm still not sure about 1)

SVGGraphicsElement graphics = (SVGGraphicsElement) element;
box = graphics.getBBox();

// I get the BBox of my GraphicsElement

// But how can I use the mentioned getScreenCTM?

Matrix matrix = Graphics.getScreenCTM(); // and then???

Thank you again so much for your help... :-)


Hi Dominik, Andres,

Andres Toussaint wrote:

>     1.) how do you get the bounding box of a graphical element from
>     svg-file that includes the transform?
> To my knowledge there is no easy way to recover the bounding box (over

> the x,y axis of your canvas) of a transformed shape.

    Well it depends on how tight you need the bounds.  So you can
fairly simply get the BBox of the element in it's local coordinate
system and then use getTransformToElement or getScreenCTM to map
that bounding box to another coordinate system.  For 99% of uses
this is good enough and makes more sense than taking the time to
reproject all the points and recalculate the max/min for each

> The only way i can think of doing it involves retrieving the Java2D 
> rendering of the element (from the GVTTree), create a new Java2D shape

> with affineTransform.createTransformedShape and then query the bounds
> that new shape. Care should be taken that all elements remain in the 
> same coordinate space.
> Thomas: Where would be a the appropriate package to suggest inserting 
> this kind of utility?

    This functionality already exists in the form of the
'getTransformedBounds' call on the batik.gvt.GraphicsNode class.

>     2.) when I change a node's attributes, the display doesn't update
>     the view, only if I'm moving the mouse e.g . How can I tell my
>     SVGCanvas to repaint itself? Or shouldn't it note that
>     automatically? (My SVGCanvas is
>     setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);)

    Andres is right, please take the time to read the FAQ:

    In particular:
	"When I change the document in Java it only updates if I move
	 the mouse over the canvas?"

>     I tried this
>     Element elementById = rootElement.getElementById("id1");
>     if (elementById != null) {
>       elementById.setAttributeNS(null, "cx", new
>       elementById.setAttributeNS(null, "cy", new
>     }
> You need to do your DOM changes in the UpdateManager Thread. You can
> an instance of the UpdateManager thread, once the gvtRendeingCompleted

> is called:
> svgCanvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() {
> public void gvtRenderingPrepare(GVTTreeRendererEvent e) {
> ...
> }
> public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
> updateM = svgCanvas.getUpdateManager();
> }
> });
> AND you use it like this:
> updateM.getUpdateRunnableQueue().invokeLater(new Runnable() {
> public void run() {
> // do your DOM changes here.
> }
> });
> Regards,
> Andres.

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

View raw message