From c22035cf27a9f11f64397fec8ba03f54cc144668 Mon Sep 17 00:00:00 2001 From: Kaalleen Date: Thu, 4 Jun 2020 19:15:16 +0200 Subject: clone style --- lib/elements/clone.py | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'lib/elements/clone.py') diff --git a/lib/elements/clone.py b/lib/elements/clone.py index 0e7a5d63..b8046d2d 100644 --- a/lib/elements/clone.py +++ b/lib/elements/clone.py @@ -8,8 +8,9 @@ from ..commands import is_command, is_command_symbol from ..i18n import _ from ..svg.path import get_node_transform from ..svg.svg import find_elements -from ..svg.tags import (EMBROIDERABLE_TAGS, INKSTITCH_ATTRIBS, - SVG_POLYLINE_TAG, SVG_USE_TAG, XLINK_HREF) +from ..svg.tags import (EMBROIDERABLE_TAGS, INKSTITCH_ATTRIBS, SVG_GROUP_TAG, + SVG_LINK_TAG, SVG_POLYLINE_TAG, SVG_USE_TAG, + XLINK_HREF) from ..utils import cache from .auto_fill import AutoFill from .element import EmbroideryElement, param @@ -77,7 +78,7 @@ class Clone(EmbroideryElement): return [SatinColumn(node)] else: elements = [] - if element.get_style("fill", 'black') and not element.get_style('fill-opacity', 1) == "0": + if element.get_style("fill", "black") and not element.get_style("fill-opacity", 1) == "0": if element.get_boolean_param("auto_fill", True): elements.append(AutoFill(node)) else: @@ -107,6 +108,21 @@ class Clone(EmbroideryElement): transform = get_node_transform(self.node) applyTransformToNode(transform, clone) + # apply style + stroke_style = self.get_clone_style('stroke', self.node) + if not stroke_style: + stroke_style = self.get_clone_style('stroke', source_node) + fill_style = self.node.get('fill') + if not fill_style: + fill_style = self.get_clone_style('fill', source_node, "#000000") + fill_opacity = self.node.get('fill-opacity') + if not fill_opacity: + fill_opacity = self.get_clone_style('fill-opacity', source_node, "1") + style = "fill:%s;fill-opacity:%s;" % (fill_style, fill_opacity) + if stroke_style: + style += "stroke:%s;" % stroke_style + clone.set('style', style) + # set fill angle. Use either # a. a custom set fill angle # b. calculated rotation for the cloned fill element to look exactly as it's source @@ -133,6 +149,24 @@ class Clone(EmbroideryElement): return patches + def _get_clone_style_raw(self, style_name, node): + 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: + if parent.tag not in [SVG_GROUP_TAG, SVG_LINK_TAG]: + parent = parent.getparent() + continue + style = self.parse_style(parent) + style = style.get(style_name) or parent.get(style_name) + parent = parent.getparent() + return style + + def get_clone_style(self, style_name, node, default=None): + style = self._get_clone_style_raw(style_name, node) or default + return style + def center(self, source_node): xmin, xmax, ymin, ymax = computeBBox([source_node]) point = [(xmax-((xmax-xmin)/2)), (ymax-((ymax-ymin)/2))] -- cgit v1.2.3