diff options
| -rw-r--r-- | lib/elements/element.py | 29 | ||||
| -rw-r--r-- | requirements.txt | 1 |
2 files changed, 18 insertions, 12 deletions
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 diff --git a/requirements.txt b/requirements.txt index 5ab6f5fb..f058e892 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,6 +10,7 @@ jinja2>2.9 requests colormath stringcase +tinycss2 # We're not ready for flask 1.0 yet. Logging changed, among othe things. flask==0.* |
