diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-02-26 23:51:47 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-02-26 23:51:47 +0300 |
commit | 70289fdb3784779766cf2f65d98ae065c1e63351 (patch) | |
tree | 030a605a9caf2e546287347141568b31da60cf76 /io_curve_svg/import_svg.py | |
parent | 2be8deaac483f25b70632800468baddd2f92537b (diff) |
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).
Diffstat (limited to 'io_curve_svg/import_svg.py')
-rw-r--r-- | io_curve_svg/import_svg.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/io_curve_svg/import_svg.py b/io_curve_svg/import_svg.py index 4cf5052b..f3f89508 100644 --- a/io_curve_svg/import_svg.py +++ b/io_curve_svg/import_svg.py @@ -407,6 +407,10 @@ def SVGParseStyles(node, context): 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 @@ def SVGParseStyles(node, context): 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 @@ class SVGPathData: 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 @@ class SVGPathParser: 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, |