1 #!/usr/bin/env python
2 '''
3 Copyright (C) 2008 Aaron Spike, aaron@ekips.org
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 '''
19 import inkex, cubicsuperpath, simplepath, simplestyle, cspsubdiv
21 class MyEffect(inkex.Effect):
22 def __init__(self):
23 inkex.Effect.__init__(self)
24 self.OptionParser.add_option("-f", "--flatness",
25 action="store", type="float",
26 dest="flat", default=0.2,
27 help="Minimum flatness of the subdivided curves")
28 self.OptionParser.add_option("-m", "--mirror",
29 action="store", type="inkbool",
30 dest="mirror", default="FALSE",
31 help="Mirror Y-Axis")
32 self.OptionParser.add_option("-x", "--xOrigin",
33 action="store", type="float",
34 dest="xOrigin", default=0.0,
35 help="X Origin (pixels)")
36 self.OptionParser.add_option("-y", "--yOrigin",
37 action="store", type="float",
38 dest="yOrigin", default=0.0,
39 help="Y Origin (pixels)")
40 self.OptionParser.add_option("-p", "--plotInvisibleLayers",
41 action="store", type="inkbool",
42 dest="plotInvisibleLayers", default="FALSE",
43 help="Plot invisible layers")
45 self.hpgl = ['IN;SP1;']
46 def output(self):
47 print ''.join(self.hpgl)
48 def effect(self):
49 x0 = self.options.xOrigin
50 y0 = self.options.yOrigin
51 scale = 1016.0/90
52 mirror = 1.0
53 if self.options.mirror:
54 mirror = -1.0
55 if self.document.getroot().get('height'):
56 y0 -= float(self.document.getroot().get('height'))
57 i = 0
58 layerPath = '//svg:g[@inkscape:groupmode="layer"]'
59 for layer in self.document.getroot().xpath(layerPath, namespaces=inkex.NSS):
60 i += 1
61 style = layer.get('style')
62 if style:
63 style = simplestyle.parseStyle(style)
64 if style['display']=='none':
65 if not self.options.plotInvisibleLayers:
66 continue
67 nodePath = ('//svg:g[@inkscape:groupmode="layer"][%d]/descendant::svg:path') % i
68 for node in self.document.getroot().xpath(nodePath, namespaces=inkex.NSS):
69 d = node.get('d')
70 if len(simplepath.parsePath(d)):
71 p = cubicsuperpath.parsePath(d)
72 cspsubdiv.cspsubdiv(p, self.options.flat)
73 for sp in p:
74 first = True
75 for csp in sp:
76 cmd = 'PD'
77 if first:
78 cmd = 'PU'
79 first = False
80 self.hpgl.append('%s%d,%d;' % (cmd,(csp[1][0] - x0)*scale,(csp[1][1]*mirror - y0)*scale))
82 if __name__ == '__main__': #pragma: no cover
83 e = MyEffect()
84 e.affect()
86 # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99