- SEE ALSO
Image::SVG::Transform - read the "transform" attribute of an SVG element
use Image::SVG::Transform; my $transform = Image::SVG::Transform->new(); $transform->extract_transforms('scale(0.5)'); my $view_point = $transform->transform([5, 10]);
This module parses and converts the contents of the transform attribute in SVG into a series of array of hashes, and then provide a convenience method for doing point transformation from the transformed space to the viewpoint space.
This is useful if you're doing SVG rendering, or if you are trying to estimate the length of shapes in an SVG file.
The following methods are available.
Constructor for the class. It takes no arguments.
The list of transforms that were extracted from the transform string that submitted to extract_transforms. Each transform will be a hashref with these keys:
The type of transformation (scale, translate, skewX, matrix, skewY, rotate).
An arrayref of hashrefs. Each hashref has key for type (string) and params (arrayref of numeric parameters).
Returns true if the object has any transforms.
Clear the set of transforms
The combined transformation matrix for the set of transforms. This is a
$svg_transformation string, which is expected to contain a valid set of SVG transformations as described in section 7.6 of the SVG spec: https://www.w3.org/TR/SVG/coords.html#TransformAttribute. Unrecognized transformation types, or valid types with the wrong number of arguments, will cause
croak with an error message.
After it is done parsing, it updates the stored
transforms and clears the stored combined transformation matrix.
Passing in the empty string will clear the set of transformations.
In the following conditions,
Image::SVG::Transform will throw an exception using Ouch:
- The transform string could not be parsed
- The transform contains un unknown type
- The type of transform has the wrong number of arguments
Using the stored set of one or more
$point from the local coordinate system to viewport coordinate system. The combined transformation matrix is cached so that it isn't recalculated everytime this method is called.
The opposite of
transform. It takes a point from the viewport coordinates and transforms them into the local coordinate system.
- Bug Reports
Colin Kuskie <colink_at_plainblack_dot_com>
Thank you to Ben Bullock, author of Image::SVG::Path for the regular expressions for the parser.
This module is Copyright 2016 Plain Black Corporation. It is distributed under the same terms as Perl itself.