Hi Antti,

Antti wrote on 06/28/2007 04:20:26 AM:

> On Thu, 28 Jun 2007 04:24:24 +0300, <[EMAIL PROTECTED]> wrote:
> 
> > Antti 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?

   Well, you can always file one, but it's a pretty specific 
request that as I already detailed has 3 ways of being done.

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

   This is actually the simplest (except for the translate/bounds 
problem).

> >    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:
>    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):

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


class RotatingPNGTranscoder extends PNGTranscoder {
    protected void transcode(Document document,
                         String uri,
                           TranscoderOutput output)
    {
        super.transcode(document, uri, output);

        AffineTransform transform = AffineTransform.getRotateInstance( 
theta );
      if ( this.curTxf != null ) {
         this.curTxf.concatenate( transform ) ;
      } else this.curTxf = transform ;
    }

> >    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 ) ;

> 
>    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)?
 
        I ment use standard DOM methods to construct the elements.

        Element img = temp.createElementNS("http://www.w3.org/2000/svg";, 
"image");
        img.setAttributeNS("http://www.w3.org/1999/xlink";, "xlink:href", 
"foo.svg");
        img.setAttributeNS(null, "transform", "rotate(90)");
        [....]
 
        temp.getRootElement.appendChild(img);
 
> >    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...

    Good luck!


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to