From d5adee46d9abd94c7a190441d235f931d69bc7dc Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Tue, 2 Apr 2019 00:30:09 -0700 Subject: [PATCH] [svgLib] Complete support for matrix transforms --- Lib/fontTools/svgLib/path/__init__.py | 7 +++++-- Lib/fontTools/svgLib/path/shapes.py | 3 +++ Tests/svgLib/path/shapes_test.py | 12 ++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Lib/fontTools/svgLib/path/__init__.py b/Lib/fontTools/svgLib/path/__init__.py index 012438e11..5dd3329cf 100644 --- a/Lib/fontTools/svgLib/path/__init__.py +++ b/Lib/fontTools/svgLib/path/__init__.py @@ -55,7 +55,10 @@ class SVGPath(object): # xpath | doesn't seem to reliable work so just walk it for el in self.root.iter(): pb.add_path_from_element(el) + original_pen = pen for path, transform in zip(pb.paths, pb.transforms): - # TODO use transform + if transform: + pen = TransformPen(original_pen, transform) + else: + pen = original_pen parse_path(path, pen) - diff --git a/Lib/fontTools/svgLib/path/shapes.py b/Lib/fontTools/svgLib/path/shapes.py index ad50dbf31..a0b529429 100644 --- a/Lib/fontTools/svgLib/path/shapes.py +++ b/Lib/fontTools/svgLib/path/shapes.py @@ -19,6 +19,9 @@ def _strip_xml_ns(tag): def _transform(raw_value): + # TODO assumes a 'matrix' transform. + # No other transform functions are supported at the moment. + # https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform # start simple: if you aren't exactly matrix(...) then no love match = re.match(r'matrix\((.*)\)', raw_value) if not match: diff --git a/Tests/svgLib/path/shapes_test.py b/Tests/svgLib/path/shapes_test.py index c9eaac160..550eef623 100644 --- a/Tests/svgLib/path/shapes_test.py +++ b/Tests/svgLib/path/shapes_test.py @@ -76,6 +76,12 @@ import pytest "M10.5,6.5 A1.5,1.5 0 1 1 13.5,6.5 A1.5,1.5 0 1 1 10.5,6.5", None ), + # circle, with transform + ( + '', + 'M35.6,51 A14.3,14.3 0 1 1 64.2,51 A14.3,14.3 0 1 1 35.6,51', + (0.9871, -0.1602, 0.1602, 0.9871, -7.525, 8.6516) + ), # ellipse ( '', @@ -88,6 +94,12 @@ import pytest 'M90.5,50 A10,50.5 0 1 1 110.5,50 A10,50.5 0 1 1 90.5,50', None ), + # ellipse, with transform + ( + '', + 'M28.6,59.1 A30.9,11.9 0 1 1 90.4,59.1 A30.9,11.9 0 1 1 28.6,59.1', + (0.9557, -0.2945, 0.2945, 0.9557, -14.7694, 20.1454) + ), ] ) def test_el_to_path(svg_xml, expected_path, expected_transform):