[Bf-extensions-cvs] [1164b7f] master: Fix T42847: SVG importer: incorrectly imports valid SVG files
Sergey Sharybin
noreply at git.blender.org
Tue Dec 9 10:29:33 CET 2014
Commit: 1164b7f9570d17d5b91d486e0e6451f46a721daf
Author: Sergey Sharybin
Date: Tue Dec 9 14:21:05 2014 +0500
Branches: master
https://developer.blender.org/rBA1164b7f9570d17d5b91d486e0e6451f46a721daf
Fix T42847: SVG importer: incorrectly imports valid SVG files
Filled paths implies having final 'z' command to close the path.
===================================================================
M io_curve_svg/import_svg.py
===================================================================
diff --git a/io_curve_svg/import_svg.py b/io_curve_svg/import_svg.py
index e114ca3..611498a 100644
--- a/io_curve_svg/import_svg.py
+++ b/io_curve_svg/import_svg.py
@@ -547,9 +547,11 @@ class SVGPathParser:
'_handle', # Last handle coordinate
'_splines', # List of all splies created during parsing
'_spline', # Currently handling spline
- '_commands') # Hash of all supported path commands
+ '_commands', # Hash of all supported path commands
+ '_use_fill', # Splines would be filled, so expected to be closed
+ )
- def __init__(self, d):
+ def __init__(self, d, use_fill):
"""
Initialize path parser
@@ -561,6 +563,7 @@ class SVGPathParser:
self._handle = None # Last handle
self._splines = [] # List of splines in path
self._spline = None # Current spline
+ self._use_fill = use_fill
self._commands = {'M': self._pathMoveTo,
'L': self._pathLineTo,
@@ -922,6 +925,8 @@ class SVGPathParser:
Execute parser
"""
+ closed = False
+
while not self._data.eof():
code = self._data.next()
cmd = self._commands.get(code)
@@ -929,7 +934,14 @@ class SVGPathParser:
if cmd is None:
raise Exception('Unknown path command: {0}' . format(code))
+ if cmd in {'Z', 'z'}:
+ closed =True
+ else:
+ closed = False
+
cmd(code)
+ if self._use_fill and not closed:
+ self._pathClose('z')
def getSplines(self):
"""
@@ -1161,11 +1173,12 @@ class SVGGeometryPATH(SVGGeometry):
d = self._node.getAttribute('d')
- pathParser = SVGPathParser(d)
+ self._styles = SVGParseStyles(self._node, self._context)
+
+ pathParser = SVGPathParser(d, self._styles['useFill'])
pathParser.parse()
self._splines = pathParser.getSplines()
- self._styles = SVGParseStyles(self._node, self._context)
def _doCreateGeom(self, instancing):
"""
More information about the Bf-extensions-cvs
mailing list