test for basic rounded rect
This commit is contained in:
parent
f0e8e72187
commit
1292029be2
@ -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()
|
||||
|
@ -13,11 +13,22 @@ import pytest
|
||||
# minimal valid example
|
||||
(
|
||||
"<rect width='1' height='1'/>",
|
||||
"M0,0 H1 V1 H0 V0",
|
||||
"M0,0 H1 V1 H0 V0 z",
|
||||
),
|
||||
# sharp corners
|
||||
(
|
||||
"<rect x='10' y='11' width='17' height='11'/>",
|
||||
"M10,11 H27 V22 H10 V11 z",
|
||||
),
|
||||
# round corners
|
||||
(
|
||||
"<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",
|
||||
)
|
||||
]
|
||||
)
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user