I may not understand the details of what you are trying to achieve - but I am assuming that you have an SVG file (that you don't control), you want to rotate the image by some arbitrary amount, and transcode the rotated image as a PNG? Putting to one side the problem of working out the size of the output image, I would create my own SVG as follows:
<svg ...> <g transform="rotate(45, <x>, <y>)"> <svg>Imported SVG file</svg> </g> </svg> Obviously, the dimensions of the outer SVG document must be at least as large as the bounding box of the rotated inner document. HTH Martin On 12 August 2010 10:13, Tiago Matias <tiagomat...@psiengine.com> wrote: > 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 > > > > -- >From my MacBook Pro --------------------------------------------------------------------- To unsubscribe, e-mail: batik-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org