Re: Read/Write transform values

jonathan wood <[email protected]>
Newsgroups gmane.text.xml.batik.user
Message-ID <CAKiJDQTpJE-4hEGG-QMn=cDXK2tAn5H52TWBCZJxZ30pf15DYQ@mail.gmail.com>
On Mon, Aug 13, 2012 at 11:42 AM, fireball <[email protected]> wrote:

> Thanks! Jonathan.
>
> This makes things much cleaner and easier to deal with.
>
> The only thing is rotation. It does not sound straight forward like the
> other values (translate, shear, scale).
>
> Is there a simple way to set/get rotate value?
> I tried something like this for setting it but it did not work:
>
> String strTransform = elt.getAttributeNS(null,
> SVGConstants.SVG_TRANSFORM_ATTRIBUTE);
> TransformListParser p = new TransformListParser();
> AWTTransformProducer tp = new AWTTransformProducer();
> p.setTransformListHandler(tp);
> p.parse(strTransform);
> AffineTransform at = tp.getAffineTransform();
> at.rotate(Math.toRadians(Double.valueOf(rotateAngle)));
>
>

 This looks correct....did you also replace your original transform with
this one?

Something like this:

...
el.setAttributeNS(null, SVGConstants.SVG_TRANSFORM_ATTRIBUTE,
affineTransformToString(at));
....

    public String affineTransformToString(final AffineTransform at) {
        double[] matrix = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
        at.getMatrix(matrix);
        return matrixArrayToString(matrix);
    }

    public String matrixArrayToString(double[] vals) {
        return new StringBuilder("matrix(").append(vals[0]).append("
").append(vals[1]).append(" ").append(vals[2]).append("
").append(vals[3]).append(" ").append(vals[4]).append("
").append(vals[5]).append(") ").toString();
    }



> For getting it I had to parse the transform string myself to get rotate
> value.
>
> Note that my transform is like this: transform="matrix(a,b,c,d,e,f)
> rotate(angle)". Should rotate be part of the matrix?
>

both are correct.  I tend to use matrix only because of
 TransformListParser/AffineTransform, but that does not mean you can't
concat multiple matrices, or explicit transforms like rotate/scale...


>
> Any thoughts?
>
>
>
> --
> View this message in context:
> http://batik.2283329.n4.nabble.com/Read-Write-transform-values-tp4655190p4655199.html
> Sent from the Batik - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.