Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-03-20 10:44:59 +0300
committerCampbell Barton <ideasman42@gmail.com>2011-03-20 10:44:59 +0300
commit5dda667bdf12534699539acbe473895f3dc26ee4 (patch)
tree661723a03956e5803991c30c535f5fa396f383a3 /io_curve_svg
parent53836eae7a4dc55c410e3b1ff4caafdf4ae48f7a (diff)
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"/>
Diffstat (limited to 'io_curve_svg')
-rw-r--r--io_curve_svg/import_svg.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/io_curve_svg/import_svg.py b/io_curve_svg/import_svg.py
index 00c11bcf..3881a619 100644
--- a/io_curve_svg/import_svg.py
+++ b/io_curve_svg/import_svg.py
@@ -55,12 +55,12 @@ def SVGParseFloat(s, i=0):
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 @@ def SVGParseFloat(s, i=0):
else:
raise Exception('Invalid float value near ' + s[start:start + 10])
- return token
+ return token, i
def SVGCreateCurve():
@@ -146,9 +146,9 @@ def SVGParseCoord(coord, size):
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,10 +462,13 @@ class SVGPathData:
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