diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2020-05-02 15:00:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-02 15:00:42 +0200 |
| commit | a67eace2cd992617d26f28a475be7c0fd6e2f198 (patch) | |
| tree | 8469296c2e9733d69fb13cfefb56a494f70e2858 /lib | |
| parent | 8994982d70921791fe2d095743212963fb4657a6 (diff) | |
inherit styles (#673)
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/elements/element.py | 25 | ||||
| -rw-r--r-- | lib/stitches/auto_satin.py | 3 |
2 files changed, 18 insertions, 10 deletions
diff --git a/lib/elements/element.py b/lib/elements/element.py index 83e3978f..62f600d6 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -147,25 +147,34 @@ class EmbroideryElement(object): param = INKSTITCH_ATTRIBS[name] self.node.set(param, str(value)) - @property @cache - def style(self): - declarations = tinycss2.parse_declaration_list(self.node.get("style", "")) + def parse_style(self, node=None): + if node is None: + node = self.node + 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): + style = self.parse_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) + style = style.get(style_name) or parent.get(style_name) + parent = parent.getparent() return style def get_style(self, style_name, default=None): - 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) + style = self._get_style_raw(style_name) or default if style == 'none': style = None return style def has_style(self, style_name): - return style_name in self.style + return self._get_style_raw(style_name) is not None @property @cache diff --git a/lib/stitches/auto_satin.py b/lib/stitches/auto_satin.py index 9edff53c..112c714b 100644 --- a/lib/stitches/auto_satin.py +++ b/lib/stitches/auto_satin.py @@ -210,7 +210,6 @@ class RunningStitch(object): self.path = path_or_stroke self.original_element = original_element - self.style = original_element.node.get('style', '') self.running_stitch_length = \ original_element.node.get(INKSTITCH_ATTRIBS['running_stitch_length_mm'], '') or \ original_element.node.get(INKSTITCH_ATTRIBS['center_walk_underlay_stitch_length_mm'], '') or \ @@ -221,7 +220,7 @@ class RunningStitch(object): node.set("d", cubicsuperpath.formatPath( line_strings_to_csp([self.path]))) - style = simplestyle.parseStyle(self.style) + style = self.original_element.parse_style() style['stroke-dasharray'] = "0.5,0.5" style = simplestyle.formatStyle(style) node.set("style", style) |
