More simple shape examples
This commit is contained in:
parent
d910ba371b
commit
1e70458679
@ -32,14 +32,14 @@ class PathBuilder(object):
|
||||
def m(self, x, y):
|
||||
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))
|
||||
def _arc(self, c, rx, ry, x, y, large_arc):
|
||||
self._Add('%s%d,%d 0 %d 1 %d,%d' % (c, rx, ry, large_arc, x, y))
|
||||
|
||||
def A(self, rx, ry, x, y):
|
||||
self._arc('A', rx, ry, x, y)
|
||||
def A(self, rx, ry, x, y, large_arc = 0):
|
||||
self._arc('A', rx, ry, x, y, large_arc)
|
||||
|
||||
def a(self, rx, ry, x, y):
|
||||
self._arc('a', rx, ry, x, y)
|
||||
def a(self, rx, ry, x, y, large_arc = 0):
|
||||
self._arc('a', rx, ry, x, y, large_arc)
|
||||
|
||||
def _vhline(self, c, x):
|
||||
self._Add('%s%d' % (c, x))
|
||||
@ -87,6 +87,22 @@ class PathBuilder(object):
|
||||
if 'd' in path.attrib:
|
||||
self.StartPath(initial_path=path.attrib['d'])
|
||||
|
||||
def _ParsePolygon(self, poly):
|
||||
if 'points' in poly.attrib:
|
||||
self.StartPath('M' + poly.attrib['points'])
|
||||
self.EndPath()
|
||||
|
||||
def _ParseCircle(self, circle):
|
||||
cx = float(circle.attrib.get('cx', 0))
|
||||
cy = float(circle.attrib.get('cy', 0))
|
||||
r = float(circle.attrib.get('r'))
|
||||
|
||||
# arc doesn't seem to like being a complete shape, draw two halves
|
||||
self.StartPath()
|
||||
self.M(cx - r, cy)
|
||||
self.A(r, r, cx + r, cy, large_arc=1)
|
||||
self.A(r, r, cx - r, cy, large_arc=1)
|
||||
|
||||
def AddPathFromElement(self, el):
|
||||
tag = el.tag
|
||||
if '}' in el.tag:
|
||||
|
@ -36,6 +36,21 @@ import pytest
|
||||
"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
|
||||
(
|
||||
"<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"
|
||||
)
|
||||
]
|
||||
)
|
||||
def test_el_to_path(svg_xml, expected_path):
|
||||
|
Loading…
x
Reference in New Issue
Block a user