diff options
| author | Kaalleen <reni@allenka.de> | 2022-01-29 09:53:50 +0100 |
|---|---|---|
| committer | Kaalleen <reni@allenka.de> | 2022-05-04 19:04:44 +0200 |
| commit | 82216b184c669d6dea26672e5c0771146e62ca39 (patch) | |
| tree | 4ce9324418a71557c24c445afe1e0e388d4985c3 /lib/patterns.py | |
| parent | 95a933161616e5860862435d4b999db49b8e50a5 (diff) | |
remove some pattern and marker mixups and some style issues
Diffstat (limited to 'lib/patterns.py')
| -rw-r--r-- | lib/patterns.py | 50 |
1 files changed, 5 insertions, 45 deletions
diff --git a/lib/patterns.py b/lib/patterns.py index 7ec4d082..1650523c 100644 --- a/lib/patterns.py +++ b/lib/patterns.py @@ -3,25 +3,17 @@ # Copyright (c) 2010 Authors # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. -import inkex from shapely import geometry as shgeo +from .marker import get_marker_elements from .stitch_plan import Stitch -from .svg.tags import EMBROIDERABLE_TAGS from .utils import Point -def is_pattern(node): - if node.tag not in EMBROIDERABLE_TAGS: - return False - style = node.get('style') or '' - return "marker-start:url(#inkstitch-pattern-marker)" in style - - def apply_patterns(patches, node): - patterns = get_patterns(node, "#inkstitch-pattern-marker") - _apply_fill_patterns(patterns['fill_patterns'], patches) - _apply_stroke_patterns(patterns['stroke_patterns'], patches) + patterns = get_marker_elements(node, "pattern") + _apply_fill_patterns(patterns['fill'], patches) + _apply_stroke_patterns(patterns['stroke'], patches) def _apply_stroke_patterns(patterns, patches): @@ -32,8 +24,7 @@ def _apply_stroke_patterns(patterns, patches): patch_points.append(stitch) if i == len(patch.stitches) - 1: continue - intersection_points = _get_pattern_points( - stitch, patch.stitches[i+1], pattern) + intersection_points = _get_pattern_points(stitch, patch.stitches[i+1], pattern) for point in intersection_points: patch_points.append(Stitch(point, tags=('pattern_point',))) patch.stitches = patch_points @@ -65,37 +56,6 @@ def _apply_fill_patterns(patterns, patches): patch.stitches = patch_points -def get_patterns(node, marker_id, get_fills=True, get_strokes=True): - from .elements import EmbroideryElement - from .elements.auto_fill import auto_fill - from .elements.stroke import Stroke - - fills = [] - strokes = [] - xpath = "./parent::svg:g/*[contains(@style, 'marker-start:url("+marker_id+")')]" - patterns = node.xpath(xpath, namespaces=inkex.NSS) - for pattern in patterns: - if pattern.tag not in EMBROIDERABLE_TAGS: - continue - - element = EmbroideryElement(pattern) - fill = element.get_style('fill') - stroke = element.get_style('stroke') - - if fill is not None: - fill_pattern = Stroke(pattern).paths - linear_rings = [shgeo.LinearRing(path) for path in fill_pattern] - for ring in linear_rings: - fills.append(shgeo.Polygon(ring)) - - if get_strokes and stroke is not None: - stroke_pattern = Stroke(pattern).paths - line_strings = [shgeo.LineString(path) for path in stroke_pattern] - strokes.append(shgeo.MultiLineString(line_strings)) - - return {'fill_patterns': fills, 'stroke_patterns': strokes} - - def _get_pattern_points(first, second, pattern): points = [] intersection = shgeo.LineString([first, second]).intersection(pattern) |
