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:
authorSergey Sharybin <sergey.vfx@gmail.com>2011-02-22 00:53:16 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2011-02-22 00:53:16 +0300
commit8ead47d43e029251b64c17711b3a1255add42895 (patch)
treed2d2ac8443e087dfc55458254aa48bbacabfb2a8 /io_curve_svg
parente7fca458071113a0ac8ccda00032c568c2eddf40 (diff)
SVG importer:
- Fixed incorrect usage of 255 color range -- each component should be from segment [0..1] - Added "style" tag parsing
Diffstat (limited to 'io_curve_svg')
-rw-r--r--io_curve_svg/import_svg.py62
1 files changed, 48 insertions, 14 deletions
diff --git a/io_curve_svg/import_svg.py b/io_curve_svg/import_svg.py
index f5761819..bab8d0f9 100644
--- a/io_curve_svg/import_svg.py
+++ b/io_curve_svg/import_svg.py
@@ -193,7 +193,7 @@ def SVGGetMaterial(color, context):
return None
mat = bpy.data.materials.new(name='SVGMat')
- mat.diffuse_color = diff
+ mat.diffuse_color = ([x / 255.0 for x in diff])
materials[color] = mat
@@ -292,6 +292,48 @@ SVGTransforms = {'translate': SVGTransformTranslate,
'matrix': SVGTransformMatrix,
'rotate': SVGTransformRotate}
+
+def SVGParseStyles(node, context):
+ """
+ Parse node to get different styles for displaying geometries
+ (materilas, filling flags, etc..)
+ """
+
+ styles = {'useFill': None,
+ 'fill': None}
+
+ style = node.getAttribute('style')
+ if style:
+ elems = style.split(';')
+ print(elems)
+ for elem in elems:
+ s = elem.split(':')
+
+ name = s[0].strip().lower()
+ val = s[1].strip()
+
+ if name == 'fill':
+ val = val.lower()
+ if val == 'none':
+ styles['useFill'] = False
+ else:
+ styles['useFill'] = True
+ styles['fill'] = SVGGetMaterial(val, context)
+
+ return styles
+
+ if styles['useFill'] is None:
+ fill = self._node.getAttribute('fill')
+ if fill:
+ fill = fill.lower()
+ if fill == 'none':
+ styles['useFill'] = False
+ else:
+ styles['useFill'] = True
+ styles['fill'] = SVGGetMaterial(fill, context)
+
+ return styles
+
#### SVG path helpers ####
@@ -921,8 +963,7 @@ class SVGGeometryPATH(SVGGeometry):
"""
__slots__ = ('_splines', # List of splines after parsing
- '_useFill', # Should path be filled?
- '_fill') # Material used for filling
+ '_styles') # Styles, used for displaying
def __init__(self, node, context):
"""
@@ -932,8 +973,7 @@ class SVGGeometryPATH(SVGGeometry):
super().__init__(node, context)
self._splines = []
- self._fill = None
- self._useFill = False
+ self._styles = None
def parse(self):
"""
@@ -946,13 +986,7 @@ class SVGGeometryPATH(SVGGeometry):
pathParser.parse()
self._splines = pathParser.getSplines()
- self._fill = None
- self._useFill = False
-
- fill = self._node.getAttribute('fill')
- if fill:
- self._useFill = True
- self._fill = SVGGetMaterial(fill, self._context)
+ self._styles = SVGParseStyles(self._node, self._context)
def _doCreateGeom(self):
"""
@@ -962,9 +996,9 @@ class SVGGeometryPATH(SVGGeometry):
ob = SVGCreateCurve()
cu = ob.data
- if self._useFill:
+ if self._styles['useFill']:
cu.dimensions = '2D'
- cu.materials.append(self._fill)
+ cu.materials.append(self._styles['fill'])
else:
cu.dimensions = '3D'