From 3b2c7ba1a9caa87e2a7b09af2e0af2c9221063d9 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Sat, 25 Apr 2020 14:22:17 +0200 Subject: fix parse style (#667) --- lib/elements/element.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'lib/elements') diff --git a/lib/elements/element.py b/lib/elements/element.py index 04f15b6e..f39280fc 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -2,7 +2,7 @@ import sys from copy import deepcopy import cubicsuperpath -import simplestyle +import tinycss2 from cspsubdiv import cspsubdiv from ..commands import find_commands @@ -133,20 +133,25 @@ class EmbroideryElement(object): def set_param(self, name, value): self.node.set("embroider_%s" % name, str(value)) + @property @cache + def style(self): + declarations = tinycss2.parse_declaration_list(self.node.get("style", "")) + style = {declaration.lower_name: declaration.value[0].serialize() for declaration in declarations} + + return style + def get_style(self, style_name, default=None): - style = simplestyle.parseStyle(self.node.get("style")) - if (style_name not in style): - return default - value = style[style_name] - if value == 'none': - return None - return value + style = self.style.get(style_name) + # Style not found, let's see if it is set as a separate attribute + if style is None: + style = self.node.get(style_name, default) + if style == 'none': + style = None + return style - @cache def has_style(self, style_name): - style = simplestyle.parseStyle(self.node.get("style")) - return style_name in style + return style_name in self.style @property @cache @@ -160,7 +165,7 @@ class EmbroideryElement(object): @property @cache def stroke_width(self): - width = self.get_style("stroke-width", "1") + width = self.get_style("stroke-width", None) if width is None: return 1.0 -- cgit v1.2.3