Code

Merge from fe-moved
[inkscape.git] / share / extensions / dots.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, 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.tag == inkex.addNS('path','svg'):
35                 self.group = inkex.etree.SubElement(node.getparent(),inkex.addNS('g','svg'))
36                 new = inkex.etree.SubElement(self.group,inkex.addNS('path','svg'))
37                 
38                 try:
39                     t = node.get('transform')
40                     self.group.set('transform', t)
41                 except:
42                     pass
44                 s = simplestyle.parseStyle(node.get('style'))
45                 s['stroke-linecap']='round'
46                 s['stroke-width']=self.options.dotsize
47                 new.set('style', simplestyle.formatStyle(s))
49                 a =[]
50                 p = simplepath.parsePath(node.get('d'))
51                 num = 1
52                 for cmd,params in p:
53                     if cmd != 'Z':
54                         a.append(['M',params[-2:]])
55                         a.append(['L',params[-2:]])
56                         self.addText(self.group,params[-2],params[-1],num)
57                         num += 1
58                 new.set('d', simplepath.formatPath(a))
59                 node.clear()
61                 
62     def addText(self,node,x,y,text):
63                 new = inkex.etree.SubElement(node,inkex.addNS('text','svg'))
64                 s = {'font-size': self.options.fontsize, 'fill-opacity': '1.0', 'stroke': 'none',
65                     'font-weight': 'normal', 'font-style': 'normal', 'fill': '#000000'}
66                 new.set('style', simplestyle.formatStyle(s))
67                 new.set('x', str(x))
68                 new.set('y', str(y))
69                 new.text = str(text)
71 if __name__ == '__main__':
72     e = Dots()
73     e.affect()
76 # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99