Code

standardize indents on 4 spaces
[inkscape.git] / share / extensions / flatten.py
1 #!/usr/bin/env python 
2 '''
3 Copyright (C) 2006 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     def effect(self):
29         for id, node in self.selected.iteritems():
30             if node.tagName == 'path':
31                 d = node.attributes.getNamedItem('d')
32                 p = cubicsuperpath.parsePath(d.value)
33                 cspsubdiv.cspsubdiv(p, self.options.flat)
34                 np = []
35                 for sp in p:
36                     first = True
37                     for csp in sp:
38                         cmd = 'L'
39                         if first:
40                             cmd = 'M'
41                         first = False
42                         np.append([cmd,[csp[1][0],csp[1][1]]])
43                         d.value = simplepath.formatPath(np)
45 e = MyEffect()
46 e.affect()