xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andres Toussaint <and...@onemileup.com>
Subject Re: JSVGCanvas resizing document on initial load
Date Tue, 06 Apr 2004 19:18:02 GMT
Hi Mike:

That happened to me also, and it turned out that my original SVG file 
was the source of the error. You have to specify the viewport with the 
exact same dimensions as the width height attributes in your SVG 
declaration:

<svg width="1000" height ="500" viewport="0 0 1000 500" ..... >
...
</svg>

Or another solution you could use, in case you have no control over the 
original SVG (i.e. a user is providing it to your app), you can try 
adding a Load listener and set the canvas dimensions from the SVG file:

....
// Set the JSVGCanvas listeners.
         svgCanvas.addSVGDocumentLoaderListener(new 
SVGDocumentLoaderAdapter() {
             public void documentLoadingStarted(SVGDocumentLoaderEvent 
e) {
             }

             public void documentLoadingCompleted(SVGDocumentLoaderEvent 
e) {

                 SVGDocument document = e.getSVGDocument();
                 SVGOMSVGElement  documentElement = 
(SVGOMSVGElement)document.getDocumentElement();

	      //Get the dimensions from the SVG document
                 String theW = documentElement.getAttribute("width");
                 String theH = documentElement.getAttribute("height");

                 Integer WW = new Integer(theW);
                 Integer HH = new Integer(theH);

	      //this is actually where we indicate the JSVGCanvas to modify 
its viewport size
                 svgCanvas.setMySize(new Dimension(WW.intValue(), 
HH.intValue()));
             }
         });

protected JSVGCanvas svgCanvas;


This might work for you. It does for me.
Best regards,

Andres.

On Tuesday, April 6, 2004, at 10:15 AM, Mike Favata wrote:

> Hello all,
>
> I am having a small problem when my JSVGCanvas first loads a document. 
>  When the document is first loaded it is scaled down and only takes up 
> a small portion of the canvas.  When I move the mouse over the canvas 
> the document scales to best fit the size of the canvas.  What am I 
> doing wrong?  I would like the document to best fit the canvas on 
> first load without having to wait for the user to move the mouse over 
> the canvas.  Has anyone ran into this problem before?  Any help would 
> be appreciated.  Thanks!
>
> -Mike Favata
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>
>



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


Mime
View raw message