NAME
Image::SVG::Transform - read the "transform" attribute of an SVG element
VERSION
version 0.08
SYNOPSIS
use Image::SVG::Transform;
my $transform = Image::SVG::Transform->new();
$transform->extract_transforms('scale(0.5)');
my $view_point = $transform->transform([5, 10]);
DESCRIPTION
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.
METHODS
The following methods are available.
new ()
Constructor for the class. It takes no arguments.
transforms
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:
type
The type of transformation (scale, translate, skewX, matrix, skewY, rotate).
params
An arrayref of hashrefs. Each hashref has key for type (string) and params (arrayref of numeric parameters).
has_transforms
Returns true if the object has any transforms.
clear_transforms
Clear the set of transforms
ctm
The combined transformation matrix for the set of transforms. This is a Math::Matrix
object.
extract_transforms ( $svg_transformation )
Parses the $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 Image::SVG::Transform
to 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
transform ( $point )
Using the stored set of one or more transforms
, transform $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.
untransform ( $point )
The opposite of transform
. It takes a point from the viewport coordinates and transforms them into the local coordinate system.
PREREQS
namespace::clean Math::Trig Math::Matrix Ouch Moo
SUPPORT
AUTHOR
Colin Kuskie <colink_at_plainblack_dot_com>
SEE ALSO
Image::SVG::Path SVG::Estimate
THANKS
Thank you to Ben Bullock, author of Image::SVG::Path for the regular expressions for the parser.
LEGAL
This module is Copyright 2016 Plain Black Corporation. It is distributed under the same terms as Perl itself.