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 Robert Hinn <ex...@online.de> on 2002/11/13 12:48:34 UTC

get size of document (drawing page borders)

Hi.

I am having some problems fetching the sizes (width, height) of an SVG 
document in a java application using batik. What I'm trying to do is: I 
display an svg document in an JSVGComponent (I want to write my own 
zoom, pan, etc. handlers, that's why I don't need to use JSVGCanvas). I 
would like to show the page borders of the document (displaying a box 
around the document at the pixel positions corresponding to the 
document's width and height). (By the way: I'm doing this in an 
overridden paint() method, displaying my stuff after the JSVGComponent 
paints itself. I'm aware that I could also draw "underneath" the 
JSVGComponent if I set it's background color to transparent.)

I already got the offset working (constructing a Point2D(0,0) and 
transforming it using the getRenderingTransform() AffineTransform.

However, I'm not quite sure what kind of units are used in the internal 
representation of JSVGComponents... When I fetch the mouse position 
(using an inverse getRenderingTransform() transformation), I see that 
it's definitely not millimeters ;-)

The getDocumentSize().getWidth() (not sure of the syntax here) returns 
the pixel width of the document. However, this doesn't seem to depend on 
the current zoom factor used by the JSVGComponent... I already tried 
multiplying this value (or dividing) by 
getRenderingTransform().getScaleX(), but the getScaleX() method seems to 
return strangely small values...

I also wanted to try the UnitProcessor to convert the sizes I fetched 
from the document via the getRootElement().getWidth().getBaseVal() (not 
sure, I don't have my code with me right now) to pixel (or to 
millimeters for display)... However, the UnitProcessor needs a Context, 
and I couldn't find out how to obtain one...

Maybe I'm heading in a totally wrong direction, I suppose there must be 
a fairly easy way to achieve this ;-)


So, basically, my questions are:
- How can I get the current zoom factor used by the JSVGComponent?
- How can I get/convert the document width/height to millimeters and pixels?
- Is the SVGDocument completely independent of the representation 
(JSVGComponent or the GVT renderers)? I mean: I got the impression that 
you can only fetch the document's sizes (getRootElement().getWidth()...) 
after the GVT build-up/rendering finishes?

Sorry for the long posting, I just wanted to provide a detailed 
specification of my problem ;-)
   Robert.


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