Translating a rectangle is fairly easy: Get its x and y attributes using getAttribute(null, localName), modify them and reassign them back using setAttributeNS(null, qualifiedName, value).
The tricky bit comes into play if you also want to rotate or scale the rectangle. The solution is to use SVG's transform attribute, which combines translating, scaling, rotating and skewing effects in a transformation matrix. This option also allows one to modify arbitrary SVG elements (incl. groups)!
I've come up with two usable utility classes, which you can freely use.
I would like to sincerely thank:
- "fireball" for providing a way of how to read and parse the transformation matrix of an element into an AffineTransform. Source: xmlgraphics-batik-users mailing list
- Jonathan Wood for providing a way of how to reassign a modified AffineTransform to an element. Source: xmlgraphics-batik-users mailing list
No comments:
Post a Comment