c5f6e8149b9f167ad1af65f01942d864c54c32a6
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, simplestyle, simplepath
21 class Dots(inkex.Effect):
22 def __init__(self):
23 inkex.Effect.__init__(self)
24 self.OptionParser.add_option("-d", "--dotsize",
25 action="store", type="string",
26 dest="dotsize", default="10px",
27 help="Size of the dots placed at path nodes")
28 self.OptionParser.add_option("-f", "--fontsize",
29 action="store", type="string",
30 dest="fontsize", default="20",
31 help="Size of node label numbers")
32 def effect(self):
33 for id, node in self.selected.iteritems():
34 if node.tagName == 'path':
35 self.group = self.document.createElement('svg:g')
36 node.parentNode.appendChild(self.group)
37 new = self.document.createElement('svg:path')
39 try:
40 t = node.attributes.getNamedItem('transform').value
41 self.group.setAttribute('transform', t)
42 except AttributeError:
43 pass
45 s = simplestyle.parseStyle(node.attributes.getNamedItem('style').value)
46 s['stroke-linecap']='round'
47 s['stroke-width']=self.options.dotsize
48 new.setAttribute('style', simplestyle.formatStyle(s))
50 a =[]
51 p = simplepath.parsePath(node.attributes.getNamedItem('d').value)
52 num = 1
53 for cmd,params in p:
54 if cmd != 'Z':
55 a.append(['M',params[-2:]])
56 a.append(['L',params[-2:]])
57 self.addText(self.group,params[-2],params[-1],num)
58 num += 1
59 new.setAttribute('d', simplepath.formatPath(a))
60 self.group.appendChild(new)
61 node.parentNode.removeChild(node)
64 def addText(self,node,x,y,text):
65 new = self.document.createElement('svg:text')
66 s = {'font-size': self.options.fontsize, 'fill-opacity': '1.0', 'stroke': 'none',
67 'font-weight': 'normal', 'font-style': 'normal', 'fill': '#000000'}
68 new.setAttribute('style', simplestyle.formatStyle(s))
69 new.setAttribute('x', str(x))
70 new.setAttribute('y', str(y))
71 new.appendChild(self.document.createTextNode(str(text)))
72 node.appendChild(new)
74 e = Dots()
75 e.affect()