2019-02-07 19:00:26 -08:00
|
|
|
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(
|
2019-02-08 11:37:00 -08:00
|
|
|
"svg_xml, expected_path",
|
2019-02-07 19:00:26 -08:00
|
|
|
[
|
2019-02-08 11:37:00 -08:00
|
|
|
# path: direct passthrough
|
|
|
|
(
|
|
|
|
"<path d='I love kittens'/>",
|
|
|
|
"I love kittens"
|
|
|
|
),
|
|
|
|
# path no @d
|
|
|
|
(
|
|
|
|
"<path duck='Mallard'/>",
|
|
|
|
None
|
|
|
|
),
|
|
|
|
# rect: minimal valid example
|
2019-02-07 19:00:26 -08:00
|
|
|
(
|
|
|
|
"<rect width='1' height='1'/>",
|
2019-02-08 10:50:22 -08:00
|
|
|
"M0,0 H1 V1 H0 V0 z",
|
|
|
|
),
|
2019-02-08 11:37:00 -08:00
|
|
|
# rect: sharp corners
|
2019-02-08 10:50:22 -08:00
|
|
|
(
|
|
|
|
"<rect x='10' y='11' width='17' height='11'/>",
|
|
|
|
"M10,11 H27 V22 H10 V11 z",
|
|
|
|
),
|
2019-02-08 11:37:00 -08:00
|
|
|
# rect: round corners
|
2019-02-08 10:50:22 -08:00
|
|
|
(
|
|
|
|
"<rect x='9' y='9' width='11' height='7' rx='2'/>",
|
|
|
|
"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",
|
2019-02-08 11:37:00 -08:00
|
|
|
),
|
2019-02-07 19:00:26 -08:00
|
|
|
]
|
|
|
|
)
|
2019-02-08 11:37:00 -08:00
|
|
|
def test_el_to_path(svg_xml, expected_path):
|
2019-02-07 19:00:26 -08:00
|
|
|
pb = shapes.PathBuilder()
|
2019-02-08 11:37:00 -08:00
|
|
|
pb.AddPathFromElement(etree.fromstring(svg_xml))
|
|
|
|
if expected_path:
|
|
|
|
expected = [expected_path]
|
|
|
|
else:
|
|
|
|
expected = []
|
|
|
|
assert pb.pathes == expected
|