xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thomas.dewe...@kodak.com
Subject Re: problems with the SVGDocumentLoaderListener
Date Fri, 17 Mar 2006 11:02:40 GMT
Hi Daniel,

Daniel Teske <daniel.teske@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 

   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 

   I'm a little nervous about this.  'getSVGDocumentSize' will return the
contents of the 'width' and 'height' attributes on the root SVG element. 
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 

   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

View raw message