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 "Steiner, Dominik" <Do...@gigatronik.com> on 2005/08/01 13:48:29 UTC

getbbox() and update view problems

Hi dear fellows,

 

1.) how do you get the bounding box of a graphical element from the
svg-file that includes the transform?

 

I tried this

 

box = ((SVGOMPolylineElement)node).getBBox();

 

but this just gives me the bounding box of the polyline node without the
transformation I added to that node with the attribute
'transform="rotate(-9)"' in the svg file

 

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);)

 

I tried this

 

Element elementById = rootElement.getElementById("id1");

if (elementById != null) {

  elementById.setAttributeNS(null, "cx", new Double(gps.x).toString());

  elementById.setAttributeNS(null, "cy", new Double(gps.y).toString());

}

 


Re: getbbox() and update view problems

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Dominik, Andres,

Andres Toussaint wrote:

>     1.) how do you get the bounding box of a graphical element from the
>     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
segment.

> 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 of 
> 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:

	http://xml.apache.org/batik/faqs.html
	
    In particular:
	"When I change the document in Java it only updates if I move
	 the mouse over the canvas?"
      http://xml.apache.org/batik/faqs.html#faq-22

>     I tried this
>      
>     Element elementById = rootElement.getElementById(“id1”);
>     if (elementById != null) {
>       elementById.setAttributeNS(null, "cx", new Double(gps.x).toString());
>       elementById.setAttributeNS(null, "cy", new Double(gps.y).toString());
>     }
>      
> 
> 
> You need to do your DOM changes in the UpdateManager Thread. You can get 
> 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


Re: getbbox() and update view problems

Posted by Andres Toussaint <an...@onemileup.com>.
Hello Dominik:

>
> 1.) how do you get the bounding box of a graphical element from the 
> 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.

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 
of 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?

>  
> 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);)
>  
> I tried this
>  
> Element elementById = rootElement.getElementById(“id1”);
> if (elementById != null) {
>   elementById.setAttributeNS(null, "cx", new Double(gps.x).toString());
>   elementById.setAttributeNS(null, "cy", new Double(gps.y).toString());
> }
>  

You need to do your DOM changes in the UpdateManager Thread. You can 
get 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.