Code

added HPGL export extension, courtesy of Aaron Spike
[inkscape.git] / share / extensions / hpgl_output.py
1 #!/usr/bin/env python \r
2 '''\r
3 Copyright (C) 2008 Aaron Spike, aaron@ekips.org\r
4 \r
5 This program is free software; you can redistribute it and/or modify\r
6 it under the terms of the GNU General Public License as published by\r
7 the Free Software Foundation; either version 2 of the License, or\r
8 (at your option) any later version.\r
9 \r
10 This program is distributed in the hope that it will be useful,\r
11 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 GNU General Public License for more details.\r
14 \r
15 You should have received a copy of the GNU General Public License\r
16 along with this program; if not, write to the Free Software\r
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
18 '''\r
19 import inkex, cubicsuperpath, simplepath, cspsubdiv\r
20 \r
21 class MyEffect(inkex.Effect):\r
22     def __init__(self):\r
23         inkex.Effect.__init__(self)\r
24         self.OptionParser.add_option("-f", "--flatness",\r
25                         action="store", type="float", \r
26                         dest="flat", default=10.0,\r
27                         help="Minimum flatness of the subdivided curves")\r
28         self.hpgl = ['IN;SP1;']\r
29     def output(self):\r
30         print ''.join(self.hpgl)\r
31     def effect(self):\r
32         path = '//svg:path'
33         for node in self.document.getroot().xpath(path, namespaces=inkex.NSS):\r
34             d = node.get('d')\r
35             p = cubicsuperpath.parsePath(d)\r
36             cspsubdiv.cspsubdiv(p, self.options.flat)\r
37             for sp in p:\r
38                 first = True\r
39                 for csp in sp:\r
40                     cmd = 'PD'\r
41                     if first:\r
42                         cmd = 'PU'\r
43                     first = False\r
44                     self.hpgl.append('%s%s,%s;' % (cmd,csp[1][0],csp[1][1]))\r
45 \r
46 e = MyEffect()\r
47 e.affect()