diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2021-07-25 07:24:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-25 07:24:34 +0200 |
| commit | 2f35a4a192eb6aa3b68b715da6c1ba984084e0e5 (patch) | |
| tree | 7a28d41ff83730e3bf53ee65b315783497503cec /lib/elements | |
| parent | 36815f977d7236311e9b345c33fbc74390766385 (diff) | |
Fix Style Issues (#1154)
Co-authored-by: Lex Neva <github.com@lexneva.name>
Diffstat (limited to 'lib/elements')
| -rw-r--r-- | lib/elements/element.py | 37 |
1 files changed, 5 insertions, 32 deletions
diff --git a/lib/elements/element.py b/lib/elements/element.py index 9b894d89..670b05d8 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -7,15 +7,13 @@ import sys from copy import deepcopy import inkex -import tinycss2 from inkex import bezier from ..commands import find_commands from ..i18n import _ from ..svg import (PIXELS_PER_MM, apply_transforms, convert_length, get_node_transform) -from ..svg.tags import (EMBROIDERABLE_TAGS, INKSCAPE_LABEL, INKSTITCH_ATTRIBS, - SVG_GROUP_TAG, SVG_LINK_TAG, SVG_USE_TAG) +from ..svg.tags import INKSCAPE_LABEL, INKSTITCH_ATTRIBS from ..utils import Point, cache @@ -165,37 +163,12 @@ class EmbroideryElement(object): self.node.set(param, str(value)) @cache - def parse_style(self, node=None): - if node is None: - node = self.node - element_style = node.get("style", "") - if element_style is None: - return None - declarations = tinycss2.parse_declaration_list(node.get("style", "")) - style = {declaration.lower_name: declaration.value[0].serialize() for declaration in declarations} - return style - - @cache - def _get_style_raw(self, style_name): - if self.node is None: - return None - if self.node.tag not in [SVG_GROUP_TAG, SVG_LINK_TAG, SVG_USE_TAG] and self.node.tag not in EMBROIDERABLE_TAGS: - return None - - style = self.parse_style() - if style: - style = style.get(style_name) or self.node.get(style_name) - parent = self.node.getparent() - # style not found, get inherited style elements - while not style and parent is not None: - style = self.parse_style(parent) - if style: - style = style.get(style_name) or parent.get(style_name) - parent = parent.getparent() - return style + def _get_specified_style(self): + # We want to cache this, because it's quite expensive to generate. + return self.node.specified_style() def get_style(self, style_name, default=None): - style = self._get_style_raw(style_name) or default + style = self._get_specified_style().get(style_name, default) if style == 'none': style = None return style |
