diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2024-06-30 22:49:18 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-30 22:49:18 +0200 |
| commit | e52886a64a4e76c3fdc49df95c85655da3c4f7f4 (patch) | |
| tree | 88a4edee630df0947553ced79fb6eb9dc510ccea /lib/extensions | |
| parent | 7c06dee44ac7951a5db406eb829100a5bc3e5887 (diff) | |
Various fixes (#3028)
* several thread palette extension fixes
* fix svg tartan when original shape is invalid
* tartan stroke spaces
* style
* fix tartan color substituion at pattern start
* ripple: do not render too small paths
* use less space for params warning headline
* fix clone shape path
* zip export template fix (typo)
* add realistic stitch plan output warning (help tab)
Diffstat (limited to 'lib/extensions')
| -rw-r--r-- | lib/extensions/apply_palette.py | 12 | ||||
| -rw-r--r-- | lib/extensions/generate_palette.py | 5 | ||||
| -rw-r--r-- | lib/extensions/palette_split_text.py | 12 | ||||
| -rw-r--r-- | lib/extensions/palette_to_text.py | 12 | ||||
| -rw-r--r-- | lib/extensions/stroke_to_lpe_satin.py | 2 | ||||
| -rw-r--r-- | lib/extensions/tartan.py | 13 |
6 files changed, 40 insertions, 16 deletions
diff --git a/lib/extensions/apply_palette.py b/lib/extensions/apply_palette.py index ce6c8f5c..cd8c4c94 100644 --- a/lib/extensions/apply_palette.py +++ b/lib/extensions/apply_palette.py @@ -3,7 +3,7 @@ # Copyright (c) 2024 Authors # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. -from ..elements import FillStitch +from ..elements import Clone, FillStitch from ..threads import ThreadCatalog, ThreadColor from .base import InkstitchExtension @@ -29,6 +29,16 @@ class ApplyPalette(InkstitchExtension): # Iterate through the color blocks to apply colors for element in self.elements: + if isinstance(element, Clone): + # clones use the color of their source element + continue + elif hasattr(element, 'gradient') and element.gradient is not None: + # apply colors to each gradient stop + for i, gradient_style in enumerate(element.gradient.stop_styles): + color = gradient_style['stop-color'] + gradient_style['stop-color'] = palette.nearest_color(ThreadColor(color)).to_hex_str() + continue + nearest_color = palette.nearest_color(ThreadColor(element.color)) if isinstance(element, FillStitch): element.node.style['fill'] = nearest_color.to_hex_str() diff --git a/lib/extensions/generate_palette.py b/lib/extensions/generate_palette.py index f5d7661c..b87bc179 100644 --- a/lib/extensions/generate_palette.py +++ b/lib/extensions/generate_palette.py @@ -62,7 +62,10 @@ class GeneratePalette(InkstitchExtension): def _get_color_from_elements(self, elements): colors = [] for element in elements: - if 'fill' not in element.style.keys() or not isinstance(element, inkex.TextElement): # type(element) != inkex.TextElement: + if element.TAG == 'g': + colors.extend(self._get_color_from_elements(element.getchildren())) + continue + if 'fill' not in element.style.keys() or not isinstance(element, inkex.TextElement): continue color = inkex.Color(element.style['fill']).to_rgb() diff --git a/lib/extensions/palette_split_text.py b/lib/extensions/palette_split_text.py index 19b70782..67549f4f 100644 --- a/lib/extensions/palette_split_text.py +++ b/lib/extensions/palette_split_text.py @@ -3,10 +3,13 @@ # Copyright (c) 2022 Authors # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. +from tempfile import TemporaryDirectory + import inkex from ..i18n import _ from .base import InkstitchExtension +from .utils.inkex_command import inkscape class PaletteSplitText(InkstitchExtension): @@ -30,7 +33,14 @@ class PaletteSplitText(InkstitchExtension): transform = text.transform text.pop('transform') - bbox = text.get_inkscape_bbox() + # the inkex command `bbox = text.get_inkscape_bbox()` is causing problems for our pyinstaller bundled + # releases, this code block is taken from inkex/elements/_text + with TemporaryDirectory(prefix="inkscape-command") as tmpdir: + svg_file = inkex.command.write_svg(text.root, tmpdir, "input.svg") + bbox = inkscape(svg_file, "-X", "-Y", "-W", "-H", query_id=text.get_id()) + bbox = list(map(text.root.viewport_to_unit, bbox.splitlines())) + bbox = inkex.BoundingBox.new_xywh(*bbox[1:]) + x = bbox.left y = bbox.bottom height = bbox.height / (len(lines)) diff --git a/lib/extensions/palette_to_text.py b/lib/extensions/palette_to_text.py index db0c50cf..729c92fc 100644 --- a/lib/extensions/palette_to_text.py +++ b/lib/extensions/palette_to_text.py @@ -8,6 +8,7 @@ import os import inkex from ..i18n import _ +from ..svg.tags import INKSCAPE_GROUPMODE, INKSCAPE_LABEL from ..threads.palette import ThreadPalette from .base import InkstitchExtension @@ -31,11 +32,15 @@ class PaletteToText(InkstitchExtension): inkex.errormsg(_("Cannot read palette: invalid GIMP palette header")) return - current_layer = self.svg.get_current_layer() + layer = inkex.Group(attrib={ + 'id': '__inkstitch_palette__', + INKSCAPE_LABEL: _('Thread Palette') + f': {thread_palette.name}', + INKSCAPE_GROUPMODE: 'layer', + }) + self.svg.append(layer) x = 0 y = 0 - pos = 0 for color in thread_palette: line = "%s %s" % (color.name, color.number) element = inkex.TextElement() @@ -43,10 +48,9 @@ class PaletteToText(InkstitchExtension): element.style = "fill:%s;font-size:4px;" % color.to_hex_str() element.set('x', x) element.set('y', str(y)) - current_layer.insert(pos, element) + layer.append(element) y = float(y) + 5 - pos += 1 if __name__ == '__main__': diff --git a/lib/extensions/stroke_to_lpe_satin.py b/lib/extensions/stroke_to_lpe_satin.py index 3f6e87a2..a71bbb71 100644 --- a/lib/extensions/stroke_to_lpe_satin.py +++ b/lib/extensions/stroke_to_lpe_satin.py @@ -171,7 +171,7 @@ class SatinPattern: def get_path(self, add_rungs, min_width, max_width, length, to_unit): # scale the pattern path to fit the unit of the current svg - scale_factor = scale_factor = 1 / inkex.units.convert_unit('1mm', f'{to_unit}') + scale_factor = 1 / inkex.units.convert_unit('1mm', f'{to_unit}') pattern_path = inkex.Path(self.path).transform(inkex.Transform(f'scale({scale_factor})'), True) # create a path element diff --git a/lib/extensions/tartan.py b/lib/extensions/tartan.py index 8c3c8c5f..3acb659c 100644 --- a/lib/extensions/tartan.py +++ b/lib/extensions/tartan.py @@ -28,11 +28,8 @@ class Tartan(InkstitchExtension): def get_tartan_elements(self): if self.svg.selection: - self._get_elements() - - def _get_elements(self): - for node in self.svg.selection: - self.get_selection(node) + for node in self.svg.selection: + self.get_selection(node) def get_selection(self, node): if node.TAG == 'g' and not node.get_id().startswith('inkstitch-tartan'): @@ -40,13 +37,13 @@ class Tartan(InkstitchExtension): self.get_selection(child_node) else: node = self.get_outline(node) - if node.tag in EMBROIDERABLE_TAGS and node.style('fill'): + if node.tag in EMBROIDERABLE_TAGS and node.style('fill') is not None: self.elements.add(node) def get_outline(self, node): # existing tartans are marked through their outline element # we have either selected the element itself or some other element within a tartan group - if node.get(INKSTITCH_TARTAN, None): + if node.get(INKSTITCH_TARTAN, None) is not None: return node if node.get_id().startswith('inkstitch-tartan'): for element in node.iterchildren(EMBROIDERABLE_TAGS): @@ -55,7 +52,7 @@ class Tartan(InkstitchExtension): for group in node.iterancestors(SVG_GROUP_TAG): if group.get_id().startswith('inkstitch-tartan'): for element in group.iterchildren(EMBROIDERABLE_TAGS): - if element.get(INKSTITCH_TARTAN, None): + if element.get(INKSTITCH_TARTAN, None) is not None: return element # if we don't find an existing tartan, return node return node |
