Hi Thomas! Thanks again for the answer!


On Thu, 28 Jun 2007 13:29:57 +0300, <[EMAIL PROTECTED]> wrote:

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.

I would consider it a plus for an API if it provided simple ways to do common operations. I would imagine that rotating an image is a commonplace operation, but I may be wrong - I don't have any statistics.
  But ok, I won't 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...

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

If I understood correctly, that bit is about how to link to something inside an svg document. So I tried to use this syntax to view some svg images rotated w/ Firefox and Opera. I used the following url:
file:///C:/programs/batik-1.6/samples/anne.svg#svgView(transform(rotate(90)))

The image was not rotated, so it seems Firefox / Opera don't support this.

Squiggle got it right, but there is the problem with the image location. Some translation / viewBox setting would need to be done.

  For some reason, squiggle changed the above url to
file:/C:/programs/batik-1.6/samples/anne.svg#svgView(transform(rotate(90)))#svgView(transform(rotate(90)))#svgView(transform(rotate(90)))#svgView(transform(rotate(90)))

  Is that a bug?


Anyhow, how would I pass this fragment identifier to the transcoder? My use case is such that I get an svg image (in memory, not in a file) and have to produce a png that has the corresponding image rotated +-90 degrees. So, providing an external link to the svg is not really an option (it is produced by an API I am using, and I need the png image to proceed).


>    However, I would probably subclass the Transcoder to adjust the
> 'curTxf' member to include the desired transform.

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

I tried it, it doesn't work. The problem is that the transformation is set after calling super.transcode (-> ImageTranscoder.transcode), i.e. after writing the transcoded image has already happened. Setting curTxf at that stage clearly has no effect on anything.

To have setting curTxf have any effect, it would need to be done in ImageTranscoder *after* line 89 (batik 1.6 sources):

        // Sets up root, curTxf & curAoi
        super.transcode(document, uri, output);

The comment is original, not mine. Like it says, the above call to SVGAbstractTranscoder.transcode sets curTxf. After this, the real work is done. So, I can't see any way of setting curTxf from outside batik source code so it would have any effect.


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

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

Hmm, if I understand this correctly, the target (svg) of the link would have to exist somewhere that I could point to w/ an URI. In my case that is not possible - the svg I process exists only in memory. Of course I could save it to a temporary file on the hard drive, but it seems awfully clumsy way of achieving such a basic operation as picture rotation.



      -Antti-



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

Reply via email to