From d38b3ed9828980b0ab12e18e699e337df81ff80c Mon Sep 17 00:00:00 2001 From: tpcarlson Date: Sat, 26 Feb 2022 16:44:38 +0000 Subject: [PATCH] Fix fill matching in helper.py Previously, helper.py's colour-matching regex would match greedily any non-whitespace (\S), which caused styles written out by Inkscape to fail to be parsed correctly. Instead, match for whitespace with \s. As an example, in a REPL: import re style = "font-variation-settings:normal;opacity:1;fill:#ff00ff;fill-opacity:1;stop-color:#000000;stop-opacity:1" color_match = re.search(r'fill:\s*(#[0-9a-fA-F]{6})',style) print (color_match.group(1)) (Prints #ff00ff - correct) vs. import re style = "font-variation-settings:normal;opacity:1;fill:#ff00ff;fill-opacity:1;stop-color:#000000;stop-opacity:1" color_match = re.search(r'fill:\S*(#[0-9a-fA-F]{6})',style) print (color_match.group(1)) (Prints #000000 - incorrect) --- helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper.py b/helper.py index 63bb1927..fd662356 100755 --- a/helper.py +++ b/helper.py @@ -350,7 +350,7 @@ def panel_to_components(tree): if not color: style = el.get('style') if style: - color_match = re.search(r'fill:\S*(#[0-9a-fA-F]{6})', style) + color_match = re.search(r'fill:\s*(#[0-9a-fA-F]{6})', style) color = color_match.group(1) if not color: eprint(f"Cannot get color of component: {el}")