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-08 13:11:33 -08:00
|
|
|
# polygon
|
|
|
|
(
|
|
|
|
"<polygon points='30,10 50,30 10,30'/>",
|
|
|
|
"M30,10 50,30 10,30 z"
|
|
|
|
),
|
|
|
|
# circle, minimal valid example
|
|
|
|
(
|
|
|
|
"<circle r='1'/>",
|
|
|
|
"M-1,0 A1,1 0 1 1 1,0 A1,1 0 1 1 -1,0"
|
|
|
|
),
|
|
|
|
# circle
|
|
|
|
(
|
|
|
|
"<circle cx='600' cy='200' r='100'/>",
|
|
|
|
"M500,200 A100,100 0 1 1 700,200 A100,100 0 1 1 500,200"
|
2019-02-08 14:57:10 -08:00
|
|
|
),
|
|
|
|
# circle, decimal positioning
|
|
|
|
(
|
|
|
|
"<circle cx='12' cy='6.5' r='1.5'></circle>",
|
|
|
|
"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"
|
2019-02-08 13:11:33 -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-12 11:53:27 -08:00
|
|
|
pb.add_path_from_element(etree.fromstring(svg_xml))
|
2019-02-08 11:37:00 -08:00
|
|
|
if expected_path:
|
2019-02-12 11:53:27 -08:00
|
|
|
expected = [expected_path]
|
2019-02-08 11:37:00 -08:00
|
|
|
else:
|
2019-02-12 11:53:27 -08:00
|
|
|
expected = []
|
2019-02-14 17:18:33 +00:00
|
|
|
assert pb.paths == expected
|