[1f77fb]: devel / @svg / parsePath.py  Maximize  Restore  History

Download this file

65 lines (51 with data), 1.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
import inkex, simplepath
import sys
#import getopt
def parsePaths (filen=None):
svg = inkex.Effect ()
svg.parse (filen)
paths = svg.document.xpath ('//svg:path', namespaces=inkex.NSS)
for path in paths:
D = simplepath.parsePath (path.attrib['d'])
cmdlst = [];
parlst = [];
for cmd,params in D:
cmdlst.append(cmd)
parlst.append(params)
print 'svgpath = struct("cmd","{0}","data",{{{1}}});' \
.format(''.join(cmdlst),str(parlst).replace('[[','[').replace(']]',']'))
print 'svgpathid = "{0}"; $'.format(path.attrib['id'])
# ----------------------------
if __name__=="__main__":
'''
try:
optlist,args = getopt.getopt(sys.argv[1:],"thdp")
except getopt.GetoptError:
usage()
sys.exit(2)
doHelp = 0
c = Context()
c.doPrint = 1
for opt in optlist:
if opt[0] == "-d": c.debug = 1
if opt[0] == "-p": c.plot = 1
if opt[0] == "-t": c.triangulate = 1
if opt[0] == "-h": doHelp = 1
if not doHelp:
pts = []
fp = sys.stdin
if len(args) > 0:
fp = open(args[0],'r')
for line in fp:
fld = line.split()
x = float(fld[0])
y = float(fld[1])
pts.append(Site(x,y))
if len(args) > 0: fp.close()
if doHelp or len(pts) == 0:
usage()
sys.exit(2)
'''
svg = sys.argv[1]
parsePaths(svg)

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks