Browse Source

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)
pull/1935/head
tpcarlson GitHub 3 years ago
parent
commit
d38b3ed982
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions
  1. +1
    -1
      helper.py

+ 1
- 1
helper.py View File

@@ -350,7 +350,7 @@ def panel_to_components(tree):
if not color: if not color:
style = el.get('style') style = el.get('style')
if 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) color = color_match.group(1)
if not color: if not color:
eprint(f"Cannot get color of component: {el}") eprint(f"Cannot get color of component: {el}")


Loading…
Cancel
Save