[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1639] trunk/py/scripts/addons/ io_curve_svg/import_svg.py: SVG importer:

Sergey Sharybin g.ulairi at gmail.com
Mon Feb 21 22:53:16 CET 2011


Revision: 1639
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1639
Author:   nazgul
Date:     2011-02-21 21:53:16 +0000 (Mon, 21 Feb 2011)
Log Message:
-----------
SVG importer:

- Fixed incorrect usage of 255 color range -- each component should
  be from segment [0..1]
- Added "style" tag parsing

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-02-21 21:51:11 UTC (rev 1638)
+++ trunk/py/scripts/addons/io_curve_svg/import_svg.py	2011-02-21 21:53:16 UTC (rev 1639)
@@ -193,7 +193,7 @@
         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 @@
                  '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 @@
     """
 
     __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 @@
         super().__init__(node, context)
 
         self._splines = []
-        self._fill = None
-        self._useFill = False
+        self._styles = None
 
     def parse(self):
         """
@@ -946,14 +986,8 @@
         pathParser.parse()
 
         self._splines = pathParser.getSplines()
-        self._fill = None
-        self._useFill = False
+        self._styles = SVGParseStyles(self._node, self._context)
 
-        fill = self._node.getAttribute('fill')
-        if fill:
-            self._useFill = True
-            self._fill = SVGGetMaterial(fill, self._context)
-
     def _doCreateGeom(self):
         """
         Create real geometries
@@ -962,9 +996,9 @@
         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'
 



More information about the Bf-extensions-cvs mailing list