[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1721] trunk/py/scripts/addons/ io_curve_svg/import_svg.py: fix SVG loading when a float has whitespace prefix.

Campbell Barton ideasman42 at gmail.com
Sun Mar 20 08:45:00 CET 2011


Revision: 1721
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1721
Author:   campbellbarton
Date:     2011-03-20 07:44:59 +0000 (Sun, 20 Mar 2011)
Log Message:
-----------
fix SVG loading when a float has whitespace prefix.
file from report [#26555] was raising an error becaues of this.
us.svg line 23
  <use xlink:href="#star" x=" 0.126"/>

Modified Paths:
--------------
    trunk/py/scripts/addons/io_curve_svg/import_svg.py

Modified: trunk/py/scripts/addons/io_curve_svg/import_svg.py
===================================================================
--- trunk/py/scripts/addons/io_curve_svg/import_svg.py	2011-03-20 04:27:24 UTC (rev 1720)
+++ trunk/py/scripts/addons/io_curve_svg/import_svg.py	2011-03-20 07:44:59 UTC (rev 1721)
@@ -55,12 +55,12 @@
     n = len(s)
     token = ''
 
-    # Ski[ leading whitespace characters
+    # Skip leading whitespace characters
     while i < n and (s[i].isspace() or s[i] == ','):
         i += 1
 
     if i == n:
-        return None
+        return None, i
 
     # Read sign
     if s[i] == '-':
@@ -105,7 +105,7 @@
         else:
             raise Exception('Invalid float value near ' + s[start:start + 10])
 
-    return token
+    return token, i
 
 
 def SVGCreateCurve():
@@ -146,9 +146,9 @@
     Needed to handle coordinates set in cm, mm, iches..
     """
 
-    token = SVGParseFloat(coord)
+    token, last_char = SVGParseFloat(coord)
     val = float(token)
-    unit = coord[len(token):]
+    unit = coord[last_char:].strip()  # strip() incase there is a space
 
     if unit == '%':
         return float(size) / 100.0 * val
@@ -462,11 +462,14 @@
             elif c.lower() in commands:
                 tokens.append(c)
             elif c in ['-', '.'] or c.isdigit():
-                token = SVGParseFloat(d, i)
+                token, last_char = SVGParseFloat(d, i)
                 tokens.append(token)
 
-                i += len(token) - 1
+                # in most cases len(token) and (last_char - i) are the same
+                # but with whitespace or ',' prefix they are not.
 
+                i += (last_char - i) - 1
+
             i += 1
 
         self._data = tokens



More information about the Bf-extensions-cvs mailing list