Code

get the CORRECT Sodipodi namespace in there
[inkscape.git] / share / extensions / cubicsuperpath.py
1 #!/usr/bin/env python
2 """
3 cubicsuperpath.py
5 Copyright (C) 2005 Aaron Spike, aaron@ekips.org
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 """
22 import simplepath 
24 def CubicSuperPath(simplepath):
25         csp = []
26         subpath = -1
27         subpathstart = []
28         last = []
29         lastctrl = []
30         for s in simplepath:
31                 cmd, params = s         
32                 if cmd == 'M':
33                         if last:
34                                 csp[subpath].append([lastctrl[:],last[:],last[:]])
35                         subpath += 1
36                         csp.append([])
37                         subpathstart =  params[:]
38                         last = params[:]
39                         lastctrl = params[:]
40                 elif cmd == 'L':
41                         csp[subpath].append([lastctrl[:],last[:],last[:]])
42                         last = params[:]
43                         lastctrl = params[:]
44                 elif cmd == 'C':
45                         csp[subpath].append([lastctrl[:],last[:],params[:2]])
46                         last = params[-2:]
47                         lastctrl = params[2:4]
48                 elif cmd == 'Q':
49                         #TODO: convert to cubic
50                         csp[subpath].append([lastctrl[:],last[:],last[:]])
51                         last = params[-2:]
52                         lastctrl = params[-2:]
53                 elif cmd == 'A':
54                         #TODO: convert to cubics
55                         csp[subpath].append([lastctrl[:],last[:],last[:]])
56                         last = params[-2:]
57                         lastctrl = params[-2:]
58                 elif cmd == 'Z':
59                         csp[subpath].append([lastctrl[:],last[:],last[:]])
60                         last = subpathstart[:]
61                         lastctrl = subpathstart[:]
62         #append final superpoint
63         csp[subpath].append([lastctrl[:],last[:],last[:]])
64         return csp      
66 def unCubicSuperPath(csp):
67         a = []
68         for subpath in csp:
69                 if subpath:
70                         a.append(['M',subpath[0][1][:]])
71                         for i in range(1,len(subpath)):
72                                 a.append(['C',subpath[i-1][2][:] + subpath[i][0][:] + subpath[i][1][:]])
73         return a
75 def parsePath(d):
76         return CubicSuperPath(simplepath.parsePath(d))
78 def formatPath(p):
79         return simplepath.formatPath(unCubicSuperPath(p))