Module: Fontisan::SvgToGlyf::Geometry::TransformParser
- Defined in:
- lib/fontisan/svg_to_glyf/geometry/transform_parser.rb
Overview
Parses an SVG transform="..." attribute string into a single
AffineTransform representing the accumulated composition.
Supports all six SVG transform functions:
translate, scale, rotate, matrix, skewX, skewY
Multiple functions compose left-to-right (leftmost is applied last to the point), matching the SVG specification.
Constant Summary collapse
- FUNCTION_RE =
/(\w+)\s*\(([^)]*)\)/
Class Method Summary collapse
Class Method Details
.parse(transform_string) ⇒ AffineTransform
19 20 21 22 23 24 25 26 |
# File 'lib/fontisan/svg_to_glyf/geometry/transform_parser.rb', line 19 def self.parse(transform_string) return AffineTransform.identity if transform_string.nil? || transform_string.strip.empty? transforms = transform_string.scan(FUNCTION_RE).map do |name, args| build_transform(name, args) end transforms.reduce(AffineTransform.identity) { |acc, t| acc.compose(t) } end |