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 Daniel Teske <da...@web.de> on 2006/03/16 20:34:07 UTC

problems with the SVGDocumentLoaderListener

Hi there..

Since some days i'm trying tofind a way th center the svgDokument into the Canvas.
I'm tryin to discripe my current situation.
I know that the svgDucument must be loadED(!) befor i can work with it.

So i added a listener to the Canvas:

->    jsvgCanvas.addSVGDocumentLoaderListener(new
->                                            SVGDocumentLoaderListener()
->      {
->        public void documentLoadingCompleted(SVGDocumentLoaderEvent e) {
->          //loading complete
->          System.out.println("DOCUMENTsize: " +
->                             jsvgCanvas.getSVGDocumentSize());
->        }
->        public void documentLoadingStarted(SVGDocumentLoaderEvent e) { 
->        }
->        public void documentLoadingCancelled(SVGDocumentLoaderEvent e) { 
->        }
->       public void documentLoadingFailed(SVGDocumentLoaderEvent e) {
->        }
->      });

But when i load the svgDocument 

->     jsvgCanvas.setURI(svgPath.toURL().toString());

the output is "DOCUMENTsize: null" !!


i added the Canvas into my MyJPanel:
->   this.add(jsvgCanvas);

The area where the Canvase have to be is changing some times.
Thats the way i'm realising this:

->   jsvgCanvas.setBounds(newX, newY, newWidth, newHeigth)

It's working good, but is this the right way? i didn't found a better methode.

The next i want to do is to center the svgDocument into to Canvas.
But befor i can do the AffineTransformation i must get the size of the Document.



Thank you very much for help!!
______________________________________________________________________
XXL-Speicher, PC-Virenschutz, Spartarife & mehr: Nur im WEB.DE Club!		
Jetzt gratis testen! http://freemail.web.de/home/landingpad/?mc=021130


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: problems with the SVGDocumentLoaderListener

Posted by th...@kodak.com.
Hi Daniel,

Daniel Teske <da...@web.de> wrote on 03/16/2006 02:34:07 PM:

> Since some days i'm trying tofind a way th center the svgDokument into 
the Canvas.
> I'm tryin to discripe my current situation.
> I know that the svgDucument must be loadED(!) befor i can work with it.
> 
> So i added a listener to the Canvas:
> 
> ->    jsvgCanvas.addSVGDocumentLoaderListener(new

    The Canvas's load listener is called when the document has been read
be before any of the SVG DOM is active.  This would be a good time to
register an SVG/DOM 'onload' event handler.  The 'onload' event handler
is called when the SVG DOM (is available).

> But when i load the svgDocument 
> 
> ->     jsvgCanvas.setURI(svgPath.toURL().toString());
> 
> the output is "DOCUMENTsize: null" !!

    Since you are actually calling the getSVGDocumentSize you could also
register a GVTTreeBuilderListener instead of the document load listener
(once the GVT Tree is built the size of the document is available).

    Personally I prefer to stick with events from the SVG standard
but it is little more work to register an onload listener for Java.


> The area where the Canvas have to be is changing some times.
> Thats the way i'm realising this:
> 
> ->   jsvgCanvas.setBounds(newX, newY, newWidth, newHeigth)
> 
> It's working good, but is this the right way? i didn't found a better 
methode.

   I think it's fine.  This part is really a Swing question, anything that
changes the Canvas's bounds should be fine.

> The next i want to do is to center the svgDocument into to Canvas.
> But befor i can do the AffineTransformation i must get the size of the 
Document.

   I'm a little nervous about this.  'getSVGDocumentSize' will return the
contents of the 'width' and 'height' attributes on the root SVG element. 
This
is different from the bounds of the geometry of the document.  Also if the
document has a width/height and a viewBox the Canvas should automatically
center the content in the Window (assuming preserveAspectRatio is left 
alone).

   So I'm guessing that what you really want is the bounding box of the
root SVG element.  This is first available in the SVG onload callback.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org