[Bf-extensions-cvs] [4cb833e8] blender-v2.93-release: Fix for T87654: SVG import parse error

Erik Abrahamsson noreply at git.blender.org
Thu Apr 22 12:49:36 CEST 2021


Commit: 4cb833e84acfd2be5fa08ce75118ce9cb60643b8
Author: Erik Abrahamsson
Date:   Thu Apr 22 12:42:23 2021 +0200
Branches: blender-v2.93-release
https://developer.blender.org/rBA4cb833e84acfd2be5fa08ce75118ce9cb60643b8

Fix for T87654: SVG import parse error

Fix for SVG data when there is no space between some arguments in the arc command.
See T87654 for example files.

See https://www.w3.org/TR/SVG2/paths.html#TheDProperty for arguments to the elliptical arc curve commands.

Maniphest Tasks: T87654

Differential Revision: https://developer.blender.org/D11027

===================================================================

M	io_curve_svg/import_svg.py

===================================================================

diff --git a/io_curve_svg/import_svg.py b/io_curve_svg/import_svg.py
index ceb24420..b2f42b57 100644
--- a/io_curve_svg/import_svg.py
+++ b/io_curve_svg/import_svg.py
@@ -173,7 +173,7 @@ def SVGParseTransform(transform):
     """
 
     m = Matrix()
-    r = re.compile('\s*([A-z]+)\s*\((.*?)\)')
+    r = re.compile(r'\s*([A-z]+)\s*\((.*?)\)')
 
     for match in r.finditer(transform):
         func = match.group(1)
@@ -195,7 +195,7 @@ def SVGGetMaterial(color, context):
     """
 
     materials = context['materials']
-    rgb_re = re.compile('^\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,(\d+)\s*\)\s*$')
+    rgb_re = re.compile(r'^\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,(\d+)\s*\)\s*$')
 
     if color in materials:
         return materials[color]
@@ -405,6 +405,7 @@ class SVGPathData:
 
         spaces = ' ,\t'
         commands = {'m', 'l', 'h', 'v', 'c', 's', 'q', '', 't', 'a', 'z'}
+        current_command = ''
         tokens = []
 
         i = 0
@@ -416,8 +417,22 @@ class SVGPathData:
                 pass
             elif c.lower() in commands:
                 tokens.append(c)
+                current_command = c
+                arg_index = 1
             elif c in ['-', '.'] or c.isdigit():
-                token, last_char = read_float(d, i)
+                # Special case for 'a/A' commands.
+                # Arguments 4 and 5 are either 0 or 1 and might not
+                # be separated from the next argument with space or comma.
+                if current_command.lower() == 'a':
+                    if arg_index % 7 in [4,5]:
+                        token = d[i]
+                        last_char = i + 1
+                    else:
+                        token, last_char = read_float(d, i)
+                else:
+                    token, last_char = read_float(d, i)
+
+                arg_index += 1
                 tokens.append(token)
 
                 # in most cases len(token) and (last_char - i) are the same



More information about the Bf-extensions-cvs mailing list