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 Mathieu Pedrero <ma...@centraliens-lille.org> on 2009/06/19 13:06:17 UTC

"size" of a svg document!

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!

Re: "size" of a svg document!

Posted by Paul Wellner Bou <pa...@purecodes.org>.
Hi Helder,

> Well, I wouldn't say tricky: [...]

I would. At least for me. I spent hours in debugging and searching for 
documentation. There are very few places explaining that you have to 
"boot" CSS/GVT before (or at least one of them), the error messages are 
almost impossible to track down (Nullpointer Exceptions -- same if you 
have an element which is not bound into your tree or if you did not boot 
CSS/GVT).

Furthermore, working with BBox, matrixes and so on, it is a bit 
confusing. Why it is possible to transform an SVGPoint directly, but 
with all other elements this has to be done generating a string out of 
your calculated matrix and applying this setting the attribute. There 
are more issues.

May be correct and all ok, but if you just want to work with SVG files 
in Java, all those issues and all the casting to SVGElement, 
SVGLocatable, ... are confusing. The learning curve is quite flat.

Don't misunderstand me. That's my impression and that is what I would 
tell others starting with Batik.

Regards and have a nice weekend
Paul.

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


Re: "size" of a svg document!

Posted by Helder Magalhães <he...@gmail.com>.
Hi Paul,

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

Well, I wouldn't say tricky: that method is part of the SVG DOM and
therefore it's better documented within the specification [1].
Nevertheless, you have example(s) [2] within the Batik documentation
and a recent explanation [3] in the mailing list why the Javadoc isn't
available for those few interfaces... ;-)

Hope this helps,
 Helder

[1] http://www.w3.org/TR/SVG/types.html#InterfaceSVGLocatable
[2] http://xmlgraphics.apache.org/batik/using/scripting/java.html#SVGDOM
[3] http://www.nabble.com/javadoc-links-to-w3.org-broken--td22811749.html#a22818793

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


Re: "size" of a svg document!

Posted by Paul Wellner Bou <pa...@purecodes.org>.
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: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: "size" of a svg document!

Posted by Mathieu Pedrero <ma...@centraliens-lille.org>.
Excuse me for spamming, but this solution doesnt even works if the size of
the document is smaller than the size of the jScrollPane.

2009/6/19 Mathieu Pedrero <ma...@centraliens-lille.org>

> Maybe it would help you to understand what kind of dimensions i would like
> to get:
>
> Now, I add my JSVG Canvas to a Jpanel (whith Cardinal Layout, to fit on my
> canvas), and I add my Jpanel to a JscrollPane. Then when rendering is
> completed, I get the size of my JPanel.
>
> This "Bricolage" (excuse me please to use a french word, I really don't
> know how to say that in english...) gives me the dimensions I would like to
> get. But I would like to know if there is an easier way to get these
> dimensions.
>
> Thank you.
>
> 2009/6/19 Mathieu Pedrero <ma...@centraliens-lille.org>
>
> 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!
>>
>
>

Re: "size" of a svg document!

Posted by Mathieu Pedrero <ma...@centraliens-lille.org>.
Maybe it would help you to understand what kind of dimensions i would like
to get:

Now, I add my JSVG Canvas to a Jpanel (whith Cardinal Layout, to fit on my
canvas), and I add my Jpanel to a JscrollPane. Then when rendering is
completed, I get the size of my JPanel.

This "Bricolage" (excuse me please to use a french word, I really don't know
how to say that in english...) gives me the dimensions I would like to get.
But I would like to know if there is an easier way to get these dimensions.

Thank you.

2009/6/19 Mathieu Pedrero <ma...@centraliens-lille.org>

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