from __future__ import print_function, absolute_import, division from fontTools.misc.py23 import * from fontTools.pens.recordingPen import RecordingPen from fontTools.svgLib.path import shapes from fontTools.misc import etree import pytest @pytest.mark.parametrize( "svg_xml, expected_path", [ # path: direct passthrough ( "", "I love kittens" ), # path no @d ( "", None ), # rect: minimal valid example ( "", "M0,0 H1 V1 H0 V0 z", ), # rect: sharp corners ( "", "M10,11 H27 V22 H10 V11 z", ), # 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", ), # polygon ( "", "M30,10 50,30 10,30 z" ), # circle, minimal valid example ( "", "M-1,0 A1,1 0 1 1 1,0 A1,1 0 1 1 -1,0" ), # circle ( "", "M500,200 A100,100 0 1 1 700,200 A100,100 0 1 1 500,200" ), # 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" ) ] ) def test_el_to_path(svg_xml, expected_path): pb = shapes.PathBuilder() pb.add_path_from_element(etree.fromstring(svg_xml)) if expected_path: expected = [expected_path] else: expected = [] assert pb.paths == expected