Hi Thomas. Thanks for the reply!
On Thu, 28 Jun 2007 04:24:24 +0300, <[EMAIL PROTECTED]> wrote:
news <[EMAIL PROTECTED]> wrote on 06/27/2007 03:19:50 AM:
I have an svg image that I need to rotate (90 or -90 degrees) and
rasterize. What is the correct way to do this?
I have the rasterizing (to png) already working using the transcoder
API. Is it possible to do the rotation at the same time, i.e. use some
transcoding hint for this?
There isn't currently a transcoding hint for this.
Should I file an enhancement request?
It could be done using an SVG Fragment Identifier:
http://www.w3.org/TR/SVG11/linking.html#SVGFragmentIdentifiers
This one looks a bit scary as I am not that familiar with the SVG
specification. I guess I'll have to dig into this if all else fails...
However, I would probably subclass the Transcoder to adjust the
'curTxf' member to include the desired transform.
I tried this, but I must be missing something here. I made a simple
subclass:
class RotatingPNGTranscoder extends PNGTranscoder {
public RotatingPNGTranscoder( double theta ) {
AffineTransform transform = AffineTransform.getRotateInstance( theta )
;
if ( this.curTxf != null ) {
this.curTxf.concatenate( transform ) ;
} else this.curTxf = transform ;
}
}
But it turns out setting curTxf field this way in the constructor is
useless. When calling transcode method, the following lines in
SVGAbstractTranscoder reset the curTxf field (lines 266-271 in batik 1.6
sources):
if (cgn != null) {
cgn.setViewingTransform(Px);
curTxf = new AffineTransform();
} else {
curTxf = Px;
}
I could not figure out a way to get to modify curTxf during transcoding
after the above executes, short of modifying batik sources. = / Did I miss
something?
If not, how do I produce a new (rotated) svg from an existing svg?
All I
found on this was how to do it w/ JSVGCanvas, but I need to do this
w/out
starting a gui.
You could do this be building a small SVG document dynamically that
used
the 'image' element to pull in the 'real' SVG document. Then you can use
the transform attribute on the image element to rotate things.
Do you mean something like this:
String parser =
XMLResourceDescriptor.getXMLParserClassName() ;
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory( parser ) ;
Document temp =
factory.createDocument( SVGDOMImplementation.SVG_NAMESPACE_URI ) ;
SVGGraphics2D graphics = new SVGGraphics2D( temp ) ;
But where to from here? SVGGraphics2D has methods for drawing Images,
but how do I get from Document to image (i.e. the svg I have is as a
Document object)?
The tricky bits of all this is that when you rotate you typically need
to add a translate to move the document (or provide a viewBox) and that
depends on the dimensions of the image in question. If you subclass the
Transcoder this information is fairly readily available.
Well, I'll worry about that once I get some rotation happening at all...
-Antti-
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]