xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From BlueInGreeen <blue_in_gr...@fastwebnet.it>
Subject Re: Need help to fit svg images into fixed diemension JSVGCanvas?
Date Fri, 19 Aug 2005 12:46:34 GMT
Ok thank you Thomas for the reply.
Let's assume that changing attributes of documents in main memory  
isn't a problem.
I tried doing this in this way:
svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); // I don't  
know if this is necessary.
svgCanvas.setURI(f.toURL().toString()); //where f is a file selected  
by a filechooser
svgCanvas.getSVGDocument().getRootElement().setAttribute("viewBox",  
"0 0 400 400");

but notthing happened except that often I experimented application  
freezes or crashes.
Where I'm wrong??
In the meanwhile I'll try with getViewBoxTransform as you told me.

Thank you again

Francesco








--------------
   This is the purpose of the viewBox attribute.  The viewBox
attribute indicates what portion of the infinite canvas should
be displayed in the available screen/output space.


> And possibly without changing the input svg files (e.g. Adding or  
> setting attributes).
>

    So this is the real problem, how are you to know what the
'correct' part of the infinite canvas to display if the document
doesn't tell you?  You can get the bounding box of all the content
on the canvas and display that but it can be wrong for some
documents.

    You can use the code from batik.swing.JSVGScrollPane.getViewBoxRect
as and example of how to get the bounds of the image.  The simplest
thing is then to add a viewBox attribute to the document in memory.

    You could also use 'JSVGCanvas.getViewBoxTransform()' to get
the mapping from the document's userspace to screen space.  You can
apply that mapping to the viewBox to get the size of the image
on the screen, which you can use to construct a scaling
java.awt.geom.AffineTransform to fit the image to the display space,
which you can then set as the rendering transform on the Canvas.



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


Mime
View raw message