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

Sergey Sharybin g.ulairi at gmail.com
Sat Feb 26 21:51:48 CET 2011


Revision: 1660
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1660
Author:   nazgul
Date:     2011-02-26 20:51:47 +0000 (Sat, 26 Feb 2011)
Log Message:
-----------
SVG importer:
- Handle situation when last point of path segment has got the same position,
  as first segment point. It used by Illustrator to set up handles of first
  point and to make segment closed.
  Not sure about standatr about this, maybe SVG files from other editors should
  be handled in different way, if it'll be issues -- could be easily fixed.
- Use black fill as default (all viewers/editors use this).

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-26 15:41:49 UTC (rev 1659)
+++ trunk/py/scripts/addons/io_curve_svg/import_svg.py	2011-02-26 20:51:47 UTC (rev 1660)
@@ -407,6 +407,10 @@
                     styles['useFill'] = True
                     styles['fill'] = SVGGetMaterial(val, context)
 
+        if styles['useFill'] is None:
+            styles['useFill'] = True
+            styles['fill'] = SVGGetMaterial('#000', context)
+
         return styles
 
     if styles['useFill'] is None:
@@ -419,6 +423,10 @@
                 styles['useFill'] = True
                 styles['fill'] = SVGGetMaterial(fill, context)
 
+    if styles['useFill'] is None:
+        styles['useFill'] = True
+        styles['fill'] = SVGGetMaterial('#000', context)
+
     return styles
 
 #### SVG path helpers ####
@@ -482,6 +490,16 @@
 
         return self._data[self._index]
 
+    def lookupNext(self):
+        """
+        get next token without moving pointer
+        """
+
+        if self.eof():
+            return None
+
+        return self._data[self._index]
+
     def next(self):
         """
         Return current token and go to next one
@@ -584,6 +602,27 @@
 
             self._splines.append(self._spline)
 
+        if len(self._spline['points']) > 0:
+            # Not sure bout specifications, but Illustrator could create
+            # last point at the same position, as start point (which was
+            # reached by MoveTo command) to set needed handle coords.
+            # It's also could use last point at last position to make path
+            # filled.
+
+            first = self._spline['points'][0]
+            if abs(first['x'] - x) < 1e-6 and abs(first['y'] - y) < 1e-6:
+                if handle_left is not None:
+                    first['handle_left'] = handle_left
+                    first['handle_left_type'] = 'FREE'
+
+                if handle_left_type != 'VECTOR':
+                    first['handle_left_type'] = handle_left_type
+
+                if self._data.eof() or self._data.lookupNext().lower() == 'm':
+                    self._spline['closed'] = True
+
+                return
+
         point = {'x': x,
                  'y': y,
 



More information about the Bf-extensions-cvs mailing list