This commit is contained in:
Michael Fogleman 2018-01-19 14:47:09 -05:00
parent 2037979ac0
commit 251f4dd6d8
1 changed files with 22 additions and 0 deletions

View File

@ -39,6 +39,28 @@ class Drawing(object):
with open(filename, 'w') as fp:
fp.write(self.dumps())
def dumps_svg(self, scale=96):
lines = []
w = (self.width + 2) * scale
h = (self.height + 2) * scale
lines.append('<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="%g" height="%g">' % (w, h))
lines.append('<g transform="scale(%g) translate(1 1)">' % scale)
for path in self.paths:
p = []
c = 'M'
for x, y in path:
p.append('%s%g %g' % (c, x, y))
c = 'L'
d = ' '.join(p)
lines.append('<path d="%s" fill="none" stroke="black" stroke-width="0.01" stroke-linecap="round" stroke-linejoin="round" />' % d)
lines.append('</g>')
lines.append('</svg>')
return '\n'.join(lines)
def dump_svg(self, filename):
with open(filename, 'w') as fp:
fp.write(self.dumps_svg())
@property
def bounds(self):
if not self._bounds: