Just a small update. I managed to obtain the dimensions of the SVG file using 
this bit of code:


                UserAgentAdapter 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, svgDocument);

                Rectangle2D bounds =  rootGN.getBounds();


So only one question remains: how to apply a transformation to the  
SVGGraphics2D and get the result back (or update the original SVGDocument DOM)?

Thanks once again!

Tiago Matias

________________________________
From: Tiago Matias
Sent: Wednesday, August 11, 2010 2:16 PM
To: batik-users@xmlgraphics.apache.org
Subject: Rotating an existing SVG document

Hello all,

I'm sorry for asking this question once more, but I'm really having trouble 
rotating an existing SVG document.

The purpose is to load an SVG file, rotate it about the centerpoint and then 
transcode it.

I got the process sort of working except for the rotation.

Here's the code (questions below)

                               private final SVGDocument svgDocument;

            // Load the SVG file.
            SAXSVGDocumentFactory factory = new 
SAXSVGDocumentFactory(SAXParser.class.getCanonicalName());
            svgDocument = (SVGDocument) factory.createDocument(url.toString());

            SVGGraphics2D engine = new SVGGraphics2D(svgDocument);

            // 90ยบ rotation
            engine.rotate(Math.Pi / 2);

            Element root = svgDocument.getDocumentElement();
            root.appendChild(engine.getRoot());

          // Transcode.
          PNGTranscoder trans = new PNGTranscoder();

          ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048);
          trans.transcode(new TranscoderInput(svgDocument), new 
TranscoderOutput(outputStream));

My questions are:
                1) If I invoke a engine.stream() I get an empty document. It 
just contains (roughly) <SVG><G/></SVG> (plus a defs element and some styling 
attributes).
                2) To proper rotate the document I'd need to translat it to the 
origin. Thing is, how may I obtain the dimensions and height of the canvas? I 
tried engine.getDimension() but it returns null.

Additionally, the output of this bit of code is the original file transcoded to 
PNG. Which means that the original svgDocument was not changed (with or without 
rotation).

Any help would be greatly appreciated.

Best retards,

Tiago Matias


Reply via email to