Hi Alex,
   I think this is likely to be a much better solution given your stated 
requirements.
The canvas goes to great lengths to make everything asynchronous so it doesn't 
block the UI thread.
   The only thing that might be better would be to look at the transcoder 
package which does much of the code below for you in a set of base classes.  
I'm not entirely sure how you are looking to use the document which makes it 
hard to know of you would end up fighting the base classes or if they would 
offer additional functionality for you.

    Good luck,
    Thomas

On Nov 24, 2011, at 10:31 AM, Alex Geller <a...@4js.com> wrote:

> Hi,
> just to let everyone know. I am now using a much shorter solution posted by
> someone else on this forum. It is synchronous, caters for different input
> sources (URL, Reader, InputStream, ect.) and gets the viewBox right. Is this
> the way it should be done?
> 
>    public static org.apache.batik.gvt.GraphicsNode getSvgIcon(java.net.URL
> url) {
>        org.apache.batik.gvt.GraphicsNode svgIcon = null;
>        try {
>            String xmlParser =
> org.apache.batik.util.XMLResourceDescriptor.getXMLParserClassName();
>            org.apache.batik.dom.svg.SAXSVGDocumentFactory df = new
> org.apache.batik.dom.svg.SAXSVGDocumentFactory(
>                xmlParser);
>            org.w3c.dom.svg.SVGDocument doc =
> df.createSVGDocument(url.toString());
>            org.apache.batik.bridge.UserAgent userAgent = new
> org.apache.batik.bridge.UserAgentAdapter();
>            org.apache.batik.bridge.DocumentLoader loader = new
> org.apache.batik.bridge.DocumentLoader(userAgent);
>            org.apache.batik.bridge.BridgeContext ctx = new
> org.apache.batik.bridge.BridgeContext(userAgent, loader);
> 
> ctx.setDynamicState(org.apache.batik.bridge.BridgeContext.DYNAMIC);
>            org.apache.batik.bridge.GVTBuilder builder = new
> org.apache.batik.bridge.GVTBuilder();
>            svgIcon = builder.build(ctx, doc);
>        } catch (Exception excp) {
>            svgIcon = null;
>            excp.printStackTrace();
>        }
>        return svgIcon;
>    }
> 
> Thanks,
> Alex
> 
> --
> View this message in context: 
> http://batik.2283329.n4.nabble.com/General-difficulties-and-problems-getting-the-size-right-in-painting-an-SVG-document-containing-a-vi-tp4100365p4104302.html
> Sent from the Batik - Users mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscr...@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org
> 

Reply via email to