3
This extension converts a path into a dashed line using 'stroke-dasharray'
4
It is a modification of the file addnodes.py
6
Copyright (C) 2005,2007 Aaron Spike, aaron@ekips.org
7
Copyright (C) 2009 Alvin Penner, penner@vaxxine.com
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
import inkex, cubicsuperpath, bezmisc, simplestyle
26
def tpoint((x1,y1), (x2,y2), t = 0.5):
27
return [x1+t*(x2-x1),y1+t*(y2-y1)]
28
def cspbezsplit(sp1, sp2, t = 0.5):
29
m1=tpoint(sp1[1],sp1[2],t)
30
m2=tpoint(sp1[2],sp2[0],t)
31
m3=tpoint(sp2[0],sp2[1],t)
35
return [[sp1[0][:],sp1[1][:],m1], [m4,m,m5], [m3,sp2[1][:],sp2[2][:]]]
36
def cspbezsplitatlength(sp1, sp2, l = 0.5, tolerance = 0.001):
37
bez = (sp1[1][:],sp1[2][:],sp2[0][:],sp2[1][:])
38
t = bezmisc.beziertatlength(bez, l, tolerance)
39
return cspbezsplit(sp1, sp2, t)
40
def cspseglength(sp1,sp2, tolerance = 0.001):
41
bez = (sp1[1][:],sp1[2][:],sp2[0][:],sp2[1][:])
42
return bezmisc.bezierlength(bez, tolerance)
44
class SplitIt(inkex.Effect):
46
inkex.Effect.__init__(self)
49
for id, node in self.selected.iteritems():
50
if node.tag == inkex.addNS('path','svg'):
52
style = simplestyle.parseStyle(node.get('style'))
53
if style.has_key('stroke-dasharray'):
54
if style['stroke-dasharray'].find(',') > 0:
55
dashes = [float (dash) for dash in style['stroke-dasharray'].split(',')]
57
p = cubicsuperpath.parsePath(node.get('d'))
63
new.append([sub[0][:]])
67
length = cspseglength(new[-1][-1], sub[i])
69
new[-1][-1], next, sub[i] = cspbezsplitatlength(new[-1][-1], sub[i], dash/length)
70
if idash % 2: # create a gap
72
else: # splice the curve
73
new[-1].append(next[:])
74
length = length - dash
75
idash = (idash + 1) % len(dashes)
80
new[-1].append(sub[i])
82
node.set('d',cubicsuperpath.formatPath(new))
84
if __name__ == '__main__':
89
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99