]> git.mxchange.org Git - flightgear.git/blobdiff - utils/Modeller/uv_import_svg.py
mingw fix
[flightgear.git] / utils / Modeller / uv_import_svg.py
index 25fe8c2fa6fd9bcf703649217cb9acf98fbca640..b366d41255d848a87035d99a97c0ed298653d631 100755 (executable)
@@ -8,12 +8,12 @@
 # """
 
 __author__ = "Melchior FRANZ < mfranz # aon : at >"
-__url__ = "http://www.flightgear.org/"
-__version__ = "0.1"
+__url__ = ["http://www.flightgear.org/", "http://cvs.flightgear.org/viewvc/source/utils/Modeller/uv_import_svg.py"]
+__version__ = "0.2"
 __bpydoc__ = """\
 Imports an SVG file containing UV maps, which has been saved by the
 uv_export.svg script. This allows to move, scale, and rotate object
-mapping in SVG editors like Inkscape. Note that all contained UV maps
+mappings in SVG editors like Inkscape. Note that all contained UV maps
 will be set, no matter which objects are actually selected at the moment.
 The choice has been made when the file was saved!
 """
@@ -41,8 +41,7 @@ The choice has been made when the file was saved!
 ID_SEPARATOR = '_.:._'
 
 
-import Blender, BPyMessages, sys, math, re
-from xml.sax import saxexts
+import Blender, BPyMessages, sys, math, re, xml.sax
 
 
 numwsp = re.compile('(?<=[\d.])\s+(?=[-+.\d])')
@@ -73,9 +72,7 @@ class Matrix:
                self.a = a; self.b = b; self.c = c; self.d = d; self.e = e; self.f = f
 
        def transform(self, u, v):
-               x = u * self.a + v * self.c + self.e
-               y = u * self.b + v * self.d + self.f
-               return (x, y)
+               return u * self.a + v * self.c + self.e, u * self.b + v * self.d + self.f
 
        def translate(self, dx, dy):
                self.multiply(Matrix(1, 0, 0, 1, dx, dy))
@@ -153,7 +150,7 @@ def parse_transform(s):
 
                elif cmd == "matrix":
                        if num == 6:
-                               matrix.multiply(Matrix(arg[0], arg[1], arg[2], arg[3], arg[4], arg[5]))
+                               matrix.multiply(Matrix(*arg))
                                continue
 
                else:
@@ -167,7 +164,7 @@ def parse_transform(s):
        return matrix
 
 
-class import_svg:
+class import_svg(xml.sax.handler.ContentHandler):
        # err_handler
        def error(self, exception):
                raise Abort(str(exception))
@@ -200,15 +197,18 @@ class import_svg:
        def endDocument(self):
                pass
 
-       def characters(self, data, start, length):
+       def characters(self, data):
                if not self.scandesc:
                        return
-               if data[start:start + length].startswith("uv_export_svg.py"):
+               if data.startswith("uv_export_svg.py"):
                        self.verified = True
 
        def ignorableWhitespace(self, data, start, length):
                pass
 
+       def processingInstruction(self, target, data):
+               pass
+
        def startElement(self, name, attrs):
                currmat = self.matrices[-1]
                if "transform" in attrs:
@@ -285,10 +285,7 @@ def run_parser(path):
        Blender.Window.WaitCursor(1)
 
        try:
-               svg = saxexts.ParserFactory().make_parser("xml.sax.drivers.drv_xmlproc")
-               svg.setDocumentHandler(import_svg())
-               svg.setErrorHandler(import_svg())
-               svg.parse(path)
+               xml.sax.parse(path, import_svg(), import_svg())
                Blender.Registry.SetKey("UVImportExportSVG", { "path" : path }, False)
 
        except Abort, e: