summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaalleen <reni@allenka.de>2020-06-04 19:15:16 +0200
committerKaalleen <reni@allenka.de>2020-06-04 19:15:16 +0200
commitc22035cf27a9f11f64397fec8ba03f54cc144668 (patch)
treee9c3fa46bc89d4da0e2263d3c9b2c37c1b00eb45
parent7d44992aea6f6f8f5ada83a1ff6767e2b66f4d5a (diff)
clone style
-rw-r--r--lib/elements/clone.py40
-rw-r--r--lib/elements/element.py4
2 files changed, 39 insertions, 5 deletions
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))]
diff --git a/lib/elements/element.py b/lib/elements/element.py
index 70d49278..fe1491d8 100644
--- a/lib/elements/element.py
+++ b/lib/elements/element.py
@@ -11,7 +11,7 @@ from ..i18n import _
from ..svg import PIXELS_PER_MM, apply_transforms, convert_length, get_doc_size
from ..svg.tags import (EMBROIDERABLE_TAGS, INKSCAPE_LABEL, INKSTITCH_ATTRIBS,
SVG_CIRCLE_TAG, SVG_ELLIPSE_TAG, SVG_GROUP_TAG,
- SVG_OBJECT_TAGS, SVG_RECT_TAG)
+ SVG_OBJECT_TAGS, SVG_RECT_TAG, SVG_LINK_TAG)
from ..utils import cache
from .svg_objects import circle_to_path, ellipse_to_path, rect_to_path
@@ -161,7 +161,7 @@ class EmbroideryElement(object):
@cache
def _get_style_raw(self, style_name):
- if self.node.tag != SVG_GROUP_TAG and self.node.tag not in EMBROIDERABLE_TAGS:
+ if self.node.tag not in [SVG_GROUP_TAG, SVG_LINK_TAG] and self.node.tag not in EMBROIDERABLE_TAGS:
return None
style = self.parse_style()