From d09dd860f4014d555e848a0d618864111cbd4974 Mon Sep 17 00:00:00 2001 From: Jonathan Neuhauser Date: Wed, 23 Oct 2024 22:11:18 +0200 Subject: [PATCH] Fix text decoration shorthand parsing --- inkex/properties.py | 17 ++++++------- tests/test_inkex_styles_complex.py | 38 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/inkex/properties.py b/inkex/properties.py index 2c7f1ad4..fa5dee5d 100644 --- a/inkex/properties.py +++ b/inkex/properties.py @@ -432,25 +432,26 @@ class _TextDecorationValueConverter(_ShorthandValueConverter): "text-decoration-style": all_properties[ "text-decoration-style" ].default_value, - "text-decoration-color": "currentcolor", + "text-decoration-color": _get_tokens_from_value("currentcolor"), "text-decoration-line": [], } - for cur in (i.serialize() for i in value): + for token, cur in list((i, i.serialize()) for i in value): if cur in ["underline", "overline", "line-through", "blink"]: - result["text-decoration-line"] += [cur] + result["text-decoration-line"].extend( + [token, tinycss2.ast.WhitespaceToken(0, 0, value=" ")] + ) elif cur in self.options["text-decoration-style"]: - result["text-decoration-style"] = cur - else: - result["text-decoration-color"] = cur + result["text-decoration-style"] = [token] + elif cur.strip(): + result["text-decoration-color"] = [token] if len(result["text-decoration-line"]) == 0: result["text-decoration-line"] = all_properties[ "text-decoration-line" ].default_value else: - # Text-decoration-line can have multiple values. - result["text-decoration-line"] = " ".join(result["text-decoration-line"]) + result["text-decoration-line"] = result["text-decoration-line"][:-1] return result diff --git a/tests/test_inkex_styles_complex.py b/tests/test_inkex_styles_complex.py index afac8608..1872ae79 100644 --- a/tests/test_inkex_styles_complex.py +++ b/tests/test_inkex_styles_complex.py @@ -232,6 +232,44 @@ class StyleInheritanceTests(TestCase): ] self.parse_style_and_compare(tests) + def test_text_decoration_shorthand(self): + """Test whether shorthand properties are applied correctly""" + tests: List[Tuple[str, dict]] = [ + ( + "text-decoration: ", + { + "text-decoration-style": "solid", + "text-decoration-line": "none", + "text-decoration-color": "currentcolor", + }, + ), + ( + "text-decoration: red wavy underline", + { + "text-decoration-style": "wavy", + "text-decoration-line": "underline", + "text-decoration-color": "red", + }, + ), + ( + "text-decoration: red wavy underline overline blue", + { + "text-decoration-style": "wavy", + "text-decoration-line": "underline overline", + "text-decoration-color": "blue", + }, + ), + ( + "text-decoration: blubb dotted overline", + { + "text-decoration-style": "dotted", + "text-decoration-line": "overline", + "text-decoration-color": "blubb", + }, + ), + ] + self.parse_style_and_compare(tests) + def test_shorthand_overwrites(self): """Test whether shorthands correctly follow precedence: only overwrite rules which are defined before and not important""" -- GitLab