NAME

Image::SVG::Transform - read the "transform" attribute of an SVG element

VERSION

version 0.001

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

The list of parameters for the transform.

See the specific classes for more information.

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 update the stored transforms and clears the stored combined transformation matrix.

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.

PREREQS

namespace::clean Clone Math::Trig Math::Matrix Carp Moo

SUPPORT

Repository

http://github.com/perlDreamer/Image-SVG-Transform

Bug Reports

http://github.com/perlDreamer/Image-SVG-Transform/issues

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.