Code

rename
[inkscape.git] / share / extensions / handles.py
1 #!/usr/bin/env python 
2 '''
3 Copyright (C) 2005 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, simplepath, simplestyle
21 class Handles(inkex.Effect):
22     def effect(self):
23         for id, node in self.selected.iteritems():
24             if node.tagName == 'path':
25                 p = simplepath.parsePath(node.attributes.getNamedItem('d').value)
26                 a =[]
27                 pen = None
28                 subPathStart = None
29                 for cmd,params in p:
30                     if cmd == 'C':
31                         a.extend([['M', params[:2]], ['L', pen],
32                             ['M', params[2:4]], ['L', params[-2:]]])
33                     if cmd == 'Q':
34                         a.extend([['M', params[:2]], ['L', pen],
35                             ['M', params[:2]], ['L', params[-2:]]])
36                     
37                     if cmd == 'M':
38                         subPathStart = params
40                     if cmd == 'Z':
41                         pen = subPathStart
42                     else:
43                         pen = params[-2:]
44                     
45                 if len(a) > 0:
46                     new = self.document.createElement('svg:path')
47                     s = {'stroke-linejoin': 'miter', 'stroke-width': '1.0px', 
48                         'stroke-opacity': '1.0', 'fill-opacity': '1.0', 
49                         'stroke': '#000000', 'stroke-linecap': 'butt', 
50                         'fill': 'none'}
51                     new.setAttribute('style', simplestyle.formatStyle(s))
52                     new.setAttribute('d', simplepath.formatPath(a))
53                     node.parentNode.appendChild(new)
55 e = Handles()
56 e.affect()