changeset 255:cac0b6cfebb4

Improve python converter.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 09 Oct 2012 22:08:12 +0300
parents 9c33e11c3d39
children 31ce6d32408f 370521e7a960
files svg2qd.py
diffstat 1 files changed, 9 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/svg2qd.py	Tue Oct 09 21:49:47 2012 +0300
+++ b/svg2qd.py	Tue Oct 09 22:08:12 2012 +0300
@@ -34,17 +34,17 @@
    return style
 
 
-def printVertices(type, vertices, width) :
+def printVertices(type, vertices, width, level) :
    if len(vertices) > 0 :
       list = map(lambda v:printVertex(v), vertices)
-      str = "# "
+      str = "# "+ type
       if type == "m" :
          str = "R"
       elif type == "M" :
          str = "L"
-      return str + "{} {} {}".format(len(vertices)-1, " ".join(list), width)
-   else :
-      return ""
+      elif type == "c" :
+         str = "R"
+      print "{}{}{} {} {}".format("  "*level, str, len(vertices)-1, " ".join(list), width)
 
 
 def printPath(path, level) :
@@ -55,12 +55,12 @@
    if trans :
       print "{}G{}".format("  "*level, printVertex(trans))
 
-   out = ""
    vertices = []
    type = ""
    for elem in path.attrib["d"].split(" ") :
-      if elem == "m" or elem == "M" or elem == "c":
-         out += printVertices(type, vertices, width)
+      if elem == "m" or elem == "M" or elem == "c" or elem == "C":
+         printVertices(type, vertices, width, level)
+         vertices = []
          type = elem
       elif elem == "z" :
          vertices.append("Z")
@@ -70,8 +70,7 @@
          py = float(tmp[1])
          vertices.append([px, py, 0])
 
-   out += printVertices(type, vertices, width)
-   print "{}{}".format("  "*level, out)
+   printVertices(type, vertices, width, level)
    if trans :
       print "{}E\n".format("  "*level)