From 251f4dd6d87bcbffa612117e4741ae23409ad4f4 Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Fri, 19 Jan 2018 14:47:09 -0500 Subject: [PATCH] dump svg --- axi/drawing.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/axi/drawing.py b/axi/drawing.py index 79fff94..0a3f57d 100644 --- a/axi/drawing.py +++ b/axi/drawing.py @@ -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('' % (w, h)) + lines.append('' % 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('' % d) + lines.append('') + lines.append('') + 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: