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, 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=10.0,
27 help="Minimum flatness of the subdivided curves")
28 self.hpgl = ['IN;SP1;']
29 def output(self):
30 print ''.join(self.hpgl)
31 def effect(self):
32 path = '//svg:path'
33 for node in self.document.getroot().xpath(path, namespaces=inkex.NSS):
34 d = node.get('d')
35 if len(simplepath.parsePath(d)):
36 p = cubicsuperpath.parsePath(d)
37 cspsubdiv.cspsubdiv(p, self.options.flat)
38 for sp in p:
39 first = True
40 for csp in sp:
41 cmd = 'PD'
42 if first:
43 cmd = 'PU'
44 first = False
45 self.hpgl.append('%s%s,%s;' % (cmd,csp[1][0],csp[1][1]))
47 if __name__ == '__main__': #pragma: no cover
48 e = MyEffect()
49 e.affect()