dump svg
This commit is contained in:
parent
2037979ac0
commit
251f4dd6d8
|
@ -39,6 +39,28 @@ class Drawing(object):
|
||||||
with open(filename, 'w') as fp:
|
with open(filename, 'w') as fp:
|
||||||
fp.write(self.dumps())
|
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
|
@property
|
||||||
def bounds(self):
|
def bounds(self):
|
||||||
if not self._bounds:
|
if not self._bounds:
|
||||||
|
|
Loading…
Reference in New Issue