Mercurial > hg > dmlib
comparison svg2qd.py @ 251:98483680ea0f
Improve converter and adjust parser accordingly.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 09 Oct 2012 20:59:30 +0300 |
parents | 3520489320bc |
children | 9c33e11c3d39 |
comparison
equal
deleted
inserted
replaced
250:3520489320bc | 251:98483680ea0f |
---|---|
7 def bf(x) : | 7 def bf(x) : |
8 return int(round(float(x))) | 8 return int(round(float(x))) |
9 | 9 |
10 | 10 |
11 def printVertex(v) : | 11 def printVertex(v) : |
12 return "{:.2f},{:.2f},{:.2f}".format(v[0], v[1], v[2]) | 12 if type(v) is list : |
13 | 13 return "{:.2f},{:.2f},{:.2f}".format(v[0], v[1], v[2]) |
14 else : | |
15 return v | |
14 | 16 |
15 def getTransform(elem) : | 17 def getTransform(elem) : |
16 if "transform" in elem.attrib : | 18 if "transform" in elem.attrib : |
17 ntrans = elem.attrib["transform"] | 19 ntrans = elem.attrib["transform"] |
18 tmatch = re.compile(r"translate\((.*?)\)", re.IGNORECASE) | 20 tmatch = re.compile(r"translate\((.*?)\)", re.IGNORECASE) |
56 vertices = [] | 58 vertices = [] |
57 type = "" | 59 type = "" |
58 for elem in path.attrib["d"].split(" ") : | 60 for elem in path.attrib["d"].split(" ") : |
59 if elem == "m" or elem == "M": | 61 if elem == "m" or elem == "M": |
60 out += printVertices(type, vertices, width) | 62 out += printVertices(type, vertices, width) |
61 pos = [0,0,0] | |
62 type = elem | 63 type = elem |
63 elif elem == "z" : | 64 elif elem == "z" : |
64 v = vertices[0] | 65 vertices.append("Z") |
65 vertices.append([v[0] - pos[0], v[1] - pos[1], v[2] - pos[2]]) | |
66 else : | 66 else : |
67 tmp = elem.split(",") | 67 tmp = elem.split(",") |
68 px = float(tmp[0]) | 68 px = float(tmp[0]) |
69 py = float(tmp[1]) | 69 py = float(tmp[1]) |
70 pos[0] += px | |
71 pos[1] += py | |
72 vertices.append([px, py, 0]) | 70 vertices.append([px, py, 0]) |
73 | 71 |
74 out += printVertices(type, vertices, width) | 72 out += printVertices(type, vertices, width) |
75 print "{}{}".format(" "*level, out) | 73 print "{}{}".format(" "*level, out) |
76 if trans : | 74 if trans : |