from fontTools.svgLib.path import shapes from fontTools.misc import etree import pytest @pytest.mark.parametrize( "svg_xml, expected_path, expected_transform", [ # path: direct passthrough ( "", "I love kittens", None ), # path no @d ( "", None, None ), # line ( '', 'M10,110 L50,150', None ), # line, decimal positioning ( '', 'M10,110.2 L50.5,150.7', None ), # rect: minimal valid example ( "", "M0,0 H1 V1 H0 V0 z", None ), # rect: sharp corners ( "", "M10,11 H27 V22 H10 V11 z", None ), # rect: round corners ( "", "M11,9 H18 A2,2 0 0 1 20,11 V14 A2,2 0 0 1 18,16 H11" " A2,2 0 0 1 9,14 V11 A2,2 0 0 1 11,9 z", None ), # rect: simple ( "", "M11.5,16 H22.5 V18 H11.5 V16 z", None ), # rect: the one above plus a rotation ( "", "M11.5,16 H22.5 V18 H11.5 V16 z", (0.7071, -0.7071, 0.7071, 0.7071, -7.0416, 16.9999) ), # polygon ( "", "M30,10 50,30 10,30 z", None ), # polyline ( "", "M30,10 50,30 10,30", None ), # circle, minimal valid example ( "", "M-1,0 A1,1 0 1 1 1,0 A1,1 0 1 1 -1,0", None ), # circle ( "", "M500,200 A100,100 0 1 1 700,200 A100,100 0 1 1 500,200", None ), # circle, decimal positioning ( "", "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 ( '', 'M0,50 A100,50 0 1 1 200,50 A100,50 0 1 1 0,50', None ), # ellipse, decimal positioning ( '', '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): pb = shapes.PathBuilder() pb.add_path_from_element(etree.fromstring(svg_xml)) if expected_path: expected_paths = [expected_path] expected_transforms = [expected_transform] else: expected_paths = [] expected_transforms = [] assert pb.paths == expected_paths assert pb.transforms == expected_transforms