diff --git a/Lib/fontTools/svgLib/path/shapes.py b/Lib/fontTools/svgLib/path/shapes.py
index 041f59c56..ba77a0312 100644
--- a/Lib/fontTools/svgLib/path/shapes.py
+++ b/Lib/fontTools/svgLib/path/shapes.py
@@ -12,6 +12,9 @@ class PathBuilder(object):
def StartPath(self):
self.pathes.append('')
+ def EndPath(self):
+ self._Add('z')
+
def _Add(self, path_snippet):
path = self.pathes[-1]
if path:
@@ -30,7 +33,7 @@ class PathBuilder(object):
self._move('m', x, y)
def _arc(self, c, rx, ry, x, y):
- self._Add('%s%d %d 0 0 1 %d %d' % (c, rx, ry, x, y))
+ self._Add('%s%d,%d 0 0 1 %d,%d' % (c, rx, ry, x, y))
def A(self, rx, ry, x, y):
self._arc('A', rx, ry, x, y)
@@ -56,7 +59,7 @@ class PathBuilder(object):
def Rect(self, rect):
# TODO what format(s) do these #s come in?
x = float(rect.attrib.get('x', 0))
- y = float(rect.attrib.get('x', 0))
+ y = float(rect.attrib.get('y', 0))
w = float(rect.attrib.get('width'))
h = float(rect.attrib.get('height'))
rx = float(rect.attrib.get('rx', 0))
@@ -69,10 +72,13 @@ class PathBuilder(object):
self.H(x + w -rx)
if rx > 0:
self.A(rx, ry, x + w, y + ry)
- self.V(x + h -ry)
+ self.V(y + h -ry)
if rx > 0:
- self.A(rx, ry, x + w, y + ry)
+ self.A(rx, ry, x + w - rx, y + h)
self.H(x + rx)
if rx > 0:
self.A(rx, ry, x, y + h - ry)
self.V(y + ry)
+ if rx > 0:
+ self.A(rx, ry, x + rx, y)
+ self.EndPath()
diff --git a/Tests/svgLib/path/shapes_test.py b/Tests/svgLib/path/shapes_test.py
index a9386152a..7611f58f0 100644
--- a/Tests/svgLib/path/shapes_test.py
+++ b/Tests/svgLib/path/shapes_test.py
@@ -13,11 +13,22 @@ import pytest
# minimal valid example
(
"",
- "M0,0 H1 V1 H0 V0",
+ "M0,0 H1 V1 H0 V0 z",
+ ),
+ # sharp corners
+ (
+ "",
+ "M10,11 H27 V22 H10 V11 z",
+ ),
+ # 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",
)
]
)
def test_rect_to_path(rect, expected_path):
pb = shapes.PathBuilder()
pb.Rect(etree.fromstring(rect))
- assert pb.pathes == [expected_path]
+ assert [expected_path] == pb.pathes