summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLex Neva <lexelby@users.noreply.github.com>2020-08-18 16:16:34 -0400
committerGitHub <noreply@github.com>2020-08-18 16:16:34 -0400
commitcc5273006cc7fd80291939ec9ea88fc2ad67417d (patch)
tree01a354dccdcb1a5dfce76fa9769233b6d43aac87
parente5e16edc0d07f5f8f2b9f28209cbc3049be0988f (diff)
parentc22035cf27a9f11f64397fec8ba03f54cc144668 (diff)
Merge pull request #736 from inkstitch/kaalleen/link-transforms
transforms on links
-rw-r--r--lib/elements/clone.py40
-rw-r--r--lib/elements/element.py4
-rw-r--r--lib/svg/path.py3
-rw-r--r--lib/svg/tags.py1
4 files changed, 42 insertions, 6 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()
diff --git a/lib/svg/path.py b/lib/svg/path.py
index 817c2972..cc4b8cbb 100644
--- a/lib/svg/path.py
+++ b/lib/svg/path.py
@@ -1,6 +1,7 @@
import cubicsuperpath
import inkex
import simpletransform
+from tags import SVG_GROUP_TAG, SVG_LINK_TAG
from .units import get_viewbox_transform
@@ -22,7 +23,7 @@ def compose_parent_transforms(node, mat):
if trans:
mat = simpletransform.composeTransform(simpletransform.parseTransform(trans), mat)
if node.getparent() is not None:
- if node.getparent().tag == inkex.addNS('g', 'svg'):
+ if node.getparent().tag in [SVG_GROUP_TAG, SVG_LINK_TAG]:
mat = compose_parent_transforms(node.getparent(), mat)
return mat
diff --git a/lib/svg/tags.py b/lib/svg/tags.py
index 66014c30..810924a6 100644
--- a/lib/svg/tags.py
+++ b/lib/svg/tags.py
@@ -14,6 +14,7 @@ SVG_TEXT_TAG = inkex.addNS('text', 'svg')
SVG_TSPAN_TAG = inkex.addNS('tspan', 'svg')
SVG_DEFS_TAG = inkex.addNS('defs', 'svg')
SVG_GROUP_TAG = inkex.addNS('g', 'svg')
+SVG_LINK_TAG = inkex.addNS('a', 'svg')
SVG_SYMBOL_TAG = inkex.addNS('symbol', 'svg')
SVG_USE_TAG = inkex.addNS('use', 'svg')
SVG_IMAGE_TAG = inkex.addNS('image', 'svg')