Hi Mathieu,
there is a nice getBBox() method for SVGLocatable, which works quite
well (at least with Batik 1.8), although it is tricky and not really
documented. You have to boot CSS/GVT before and be sure the Element you
are investigating is bound within your SVG document (with existing parent).
/**
* Parsing SVG Document
*/
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
String uri = sourcefile.toURI().toString();
SVGDocument svgDoc = (SVGDocument) f.createDocument(uri);
/**
* Booting CSS/GVT
*/
UserAgent userAgent = new UserAgentAdapter();
DocumentLoader loader = new DocumentLoader(userAgent);
BridgeContext ctx = new BridgeContext(userAgent, loader);
ctx.setDynamicState(BridgeContext.DYNAMIC);
GVTBuilder builder = new GVTBuilder();
GraphicsNode rootGN = builder.build(ctx, svgDoc);
/**
* Get <svg> element and calculate it's bounding box
*/
SVGElement svgElement = (SVGElement)svgDoc.getDocumentElement();
SVGRect bbox = ((SVGLocatable) svgElement).getBBox();
Just pasted out of my code. Hope this helps.
Regards and have a nice weekend
Paul.
Mathieu Pedrero wrote:
Hello
Il would like to know the size of the smallest rectangle which can
contain my SVG picture (when this image is displayed in my JSVG Canvas
whith the initial affine transform Identity).
Is there a method which could help me? Or do i have to write it?
I think that in the rasterizer application, pictures are builded with
the help of these dimension. Could any people having worked on the Batik
Projed tell me if i'm right?
Thanks a lot!
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]