diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2024-05-11 08:14:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-11 08:14:40 +0200 |
| commit | bf42ef00ca315e78c0069c01d97517e3786f2135 (patch) | |
| tree | 100619af8d29613a47fb0cb08414afdc270cf6d7 | |
| parent | 19b59aa2f4e94d7ac32e37aaa74aed7f99340859 (diff) | |
Update inkex (#2892)
* fix currentColor
* fix pip inkex import
* fix color block extension
| -rw-r--r-- | inkstitch.py | 2 | ||||
| -rw-r--r-- | lib/debug/__init__.py | 7 | ||||
| -rw-r--r-- | lib/debug/utils.py | 2 | ||||
| -rw-r--r-- | lib/elements/element.py | 7 | ||||
| -rw-r--r-- | lib/elements/fill_stitch.py | 9 | ||||
| -rw-r--r-- | lib/elements/satin_column.py | 2 | ||||
| -rw-r--r-- | lib/extensions/gradient_blocks.py | 32 | ||||
| -rw-r--r-- | lib/extensions/print_pdf.py | 2 | ||||
| -rw-r--r-- | lib/gui/simulator.py | 2 | ||||
| -rw-r--r-- | lib/stitch_plan/lock_stitch.py | 2 | ||||
| -rw-r--r-- | lib/stitches/auto_fill.py | 2 | ||||
| -rw-r--r-- | lib/stitches/guided_fill.py | 2 | ||||
| -rw-r--r-- | lib/stitches/meander_fill.py | 2 | ||||
| -rw-r--r-- | lib/tiles.py | 2 | ||||
| -rw-r--r-- | lib/utils/smoothing.py | 2 | ||||
| -rw-r--r-- | lib/utils/threading.py | 2 | ||||
| -rw-r--r-- | requirements.txt | 2 |
17 files changed, 39 insertions, 42 deletions
diff --git a/inkstitch.py b/inkstitch.py index 95226594..aa0d82b3 100644 --- a/inkstitch.py +++ b/inkstitch.py @@ -110,7 +110,7 @@ if debug_type != 'none': # activate logging for svg # we need to import only after possible modification of sys.path, we disable here flake8 E402 -from lib.debug import debug # noqa: E402 # import global variable debug - don't import whole module +from lib.debug.debug import debug # noqa: E402 # import global variable debug - don't import whole module debug.enable() # perhaps it would be better to find a more relevant name; in fact, it's about logging and svg creation. # log startup info diff --git a/lib/debug/__init__.py b/lib/debug/__init__.py index 8093e6a0..3973c45a 100644 --- a/lib/debug/__init__.py +++ b/lib/debug/__init__.py @@ -2,10 +2,3 @@ # # Copyright (c) 2010 Authors # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. - - -# this enable: -# from .debug import debug -# from ..debug import debug -from .debug import debug - diff --git a/lib/debug/utils.py b/lib/debug/utils.py index 9618d173..10d840d9 100644 --- a/lib/debug/utils.py +++ b/lib/debug/utils.py @@ -5,7 +5,7 @@ # this file is without: import inkex # - we need dump argv and sys.path as is on startup from inkscape -# - later sys.path may be modified that influences importing inkex (see prefere_pip_inkex) +# - later sys.path may be modified that influences importing inkex (see prefer_pip_inkex) import os import sys diff --git a/lib/elements/element.py b/lib/elements/element.py index c4e1d640..5c463c53 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -11,7 +11,7 @@ import numpy as np from inkex import bezier, BaseElement from ..commands import find_commands -from ..debug import debug +from ..debug.debug import debug from ..exceptions import InkstitchException, format_uncaught_exception from ..i18n import _ from ..marker import get_marker_elements_cache_key_data @@ -169,9 +169,12 @@ class EmbroideryElement(object): return self.node.specified_style() def get_style(self, style_name, default=None): - style = self._get_specified_style().get(style_name, default) + element_style = self._get_specified_style() + style = element_style.get(style_name, default) if style == 'none': style = None + elif style == 'currentColor': + style = element_style(style_name) return style @property diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index 47155ce0..6bf52d95 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -7,7 +7,7 @@ import math import re import numpy as np -from inkex import Transform +from inkex import LinearGradient, Transform from shapely import geometry as shgeo from shapely.errors import GEOSException from shapely.ops import nearest_points @@ -588,9 +588,10 @@ class FillStitch(EmbroideryElement): @property def gradient(self): - color = self.color[5:-1] - xpath = f'.//svg:defs/svg:linearGradient[@id="{color}"]' - return self.node.getroottree().getroot().findone(xpath) + gradient = self.node.get_computed_style("fill") + if isinstance(gradient, LinearGradient): + return gradient + return None @property @param('fill_underlay', _('Underlay'), type='toggle', group=_('Fill Underlay'), default=True) diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index 9cf7bc73..6acb2f52 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -14,7 +14,7 @@ from shapely import affinity as shaffinity from shapely import geometry as shgeo from shapely.ops import nearest_points -from ..debug import debug +from ..debug.debug import debug from ..i18n import _ from ..metadata import InkStitchMetadata from ..stitch_plan import StitchGroup diff --git a/lib/extensions/gradient_blocks.py b/lib/extensions/gradient_blocks.py index f94582f0..d0eca4a4 100644 --- a/lib/extensions/gradient_blocks.py +++ b/lib/extensions/gradient_blocks.py @@ -5,7 +5,8 @@ from math import degrees, pi -from inkex import DirectedLineSegment, PathElement, Transform, errormsg +from inkex import (DirectedLineSegment, LinearGradient, PathElement, Transform, + errormsg) from shapely import geometry as shgeo from shapely.affinity import rotate from shapely.geometry import Point @@ -42,7 +43,7 @@ class GradientBlocks(CommandsExtension): if not self.get_elements(): return - elements = [element for element in self.elements if (isinstance(element, FillStitch) and self.has_gradient_color(element))] + elements = [element for element in self.elements if isinstance(element, FillStitch) and isinstance(element.gradient, LinearGradient)] if not elements: errormsg(_("Please select at least one object with a gradient fill.")) return @@ -97,21 +98,22 @@ class GradientBlocks(CommandsExtension): block.set('inkstitch:fill_underlay_row_spacing_mm', end_row_spacing) parent.insert(index, block) - if previous_color == color: - current = FillStitch(block) - previous = FillStitch(previous_element) - nearest = nearest_points(current.shape, previous.shape) - pos_current = self._get_command_postion(current, nearest[0]) - pos_previous = self._get_command_postion(previous, nearest[1]) - add_commands(current, ['fill_end'], pos_current) - add_commands(previous, ['fill_start'], pos_previous) + self._add_block_commands(block, previous_element) previous_color = color previous_element = block parent.remove(element.node) - def has_gradient_color(self, element): - return element.color.startswith('url') and "linearGradient" in element.color + def _add_block_commands(self, block, previous_element): + current = FillStitch(block) + previous = FillStitch(previous_element) + if previous.shape.is_empty: + return + nearest = nearest_points(current.shape, previous.shape) + pos_current = self._get_command_postion(current, nearest[0]) + pos_previous = self._get_command_postion(previous, nearest[1]) + add_commands(current, ['fill_end'], pos_current) + add_commands(previous, ['fill_start'], pos_previous) def _get_command_postion(self, fill, point): center = fill.shape.centroid @@ -129,9 +131,7 @@ class GradientBlocks(CommandsExtension): def gradient_shapes_and_attributes(element, shape, unit_multiplier): # e.g. url(#linearGradient872) -> linearGradient872 - color = element.color[5:-1] - xpath = f'.//svg:defs/svg:linearGradient[@id="{color}"]' - gradient = element.node.getroottree().getroot().findone(xpath) + gradient = element.gradient gradient.apply_transform() point1 = (float(gradient.get('x1')), float(gradient.get('y1'))) point2 = (float(gradient.get('x2')), float(gradient.get('y2'))) @@ -170,7 +170,7 @@ def gradient_shapes_and_attributes(element, shape, unit_multiplier): # does this gradient line split the shape offset_outside_shape = len(polygon.geoms) == 1 for poly in polygon.geoms: - if isinstance(poly, shgeo.Polygon) and element.shape_is_valid(poly): + if isinstance(poly, shgeo.Polygon) and poly.is_valid: if poly.intersects(offset_line): if previous_color: polygons.append(poly) diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py index 640a168b..257d746a 100644 --- a/lib/extensions/print_pdf.py +++ b/lib/extensions/print_pdf.py @@ -22,7 +22,7 @@ from lxml import etree from werkzeug.serving import make_server from .base import InkstitchExtension -from ..debug import debug +from ..debug.debug import debug from ..i18n import _, get_languages from ..i18n import translation as inkstitch_translation from ..stitch_plan import stitch_groups_to_stitch_plan diff --git a/lib/gui/simulator.py b/lib/gui/simulator.py index a8e917b4..e0808d6f 100644 --- a/lib/gui/simulator.py +++ b/lib/gui/simulator.py @@ -11,7 +11,7 @@ import wx from numpy import split from wx.lib.intctrl import IntCtrl -from lib.debug import debug +from lib.debug.debug import debug from lib.utils import get_resource_dir from lib.utils.settings import global_settings from lib.utils.threading import ExitThread diff --git a/lib/stitch_plan/lock_stitch.py b/lib/stitch_plan/lock_stitch.py index 788e6377..e05764de 100644 --- a/lib/stitch_plan/lock_stitch.py +++ b/lib/stitch_plan/lock_stitch.py @@ -4,7 +4,7 @@ from math import degrees from inkex import DirectedLineSegment, Path from shapely.geometry import LineString -from ..debug import debug +from ..debug.debug import debug from ..i18n import _ from ..svg import PIXELS_PER_MM from ..utils import string_to_floats diff --git a/lib/stitches/auto_fill.py b/lib/stitches/auto_fill.py index 159a869b..85543cea 100644 --- a/lib/stitches/auto_fill.py +++ b/lib/stitches/auto_fill.py @@ -16,7 +16,7 @@ from shapely.ops import snap from shapely.strtree import STRtree -from ..debug import debug +from ..debug.debug import debug from ..stitch_plan import Stitch from ..svg import PIXELS_PER_MM from ..utils import cache diff --git a/lib/stitches/guided_fill.py b/lib/stitches/guided_fill.py index 1b564bcb..f170f024 100644 --- a/lib/stitches/guided_fill.py +++ b/lib/stitches/guided_fill.py @@ -10,7 +10,7 @@ from shapely.ops import linemerge, nearest_points, unary_union from lib.utils import prng -from ..debug import debug +from ..debug.debug import debug from ..stitch_plan import Stitch from ..utils.geometry import Point as InkstitchPoint from ..utils.geometry import (ensure_geometry_collection, diff --git a/lib/stitches/meander_fill.py b/lib/stitches/meander_fill.py index 94e38e1f..77a899c9 100644 --- a/lib/stitches/meander_fill.py +++ b/lib/stitches/meander_fill.py @@ -5,7 +5,7 @@ from shapely.geometry import LineString, MultiPoint, Point from shapely.ops import nearest_points from .. import tiles -from ..debug import debug +from ..debug.debug import debug from ..i18n import _ from ..utils.clamp_path import clamp_path_to_polygon from ..utils.geometry import Point as InkStitchPoint diff --git a/lib/tiles.py b/lib/tiles.py index 00d837b3..30b1b2ed 100644 --- a/lib/tiles.py +++ b/lib/tiles.py @@ -8,7 +8,7 @@ import networkx as nx from shapely.geometry import LineString, MultiLineString from shapely.prepared import prep -from .debug import debug +from .debug.debug import debug from .i18n import _ from .svg import apply_transforms from .utils import Point, cache, get_bundled_dir, guess_inkscape_config_path diff --git a/lib/utils/smoothing.py b/lib/utils/smoothing.py index 49771b6c..0300f6f1 100644 --- a/lib/utils/smoothing.py +++ b/lib/utils/smoothing.py @@ -33,7 +33,7 @@ def smooth_path(path, smoothness=1.0): Returns: A list of Points. """ - from ..debug import debug + from ..debug.debug import debug if smoothness == 0: # s of exactly zero seems to indicate a default level of smoothing diff --git a/lib/utils/threading.py b/lib/utils/threading.py index f774dcbe..2a95e857 100644 --- a/lib/utils/threading.py +++ b/lib/utils/threading.py @@ -1,7 +1,7 @@ import threading from ..exceptions import InkstitchException -from ..debug import debug +from ..debug.debug import debug class ExitThread(InkstitchException): diff --git a/requirements.txt b/requirements.txt index 9c85b0f0..5fe6c915 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ ./pyembroidery # get up to date inkex version (Febuary 10, 2024) -inkex @ git+https://gitlab.com/inkscape/extensions.git@8d51d7449d73096382c2f39e726eddc4f9bbcfc4 +inkex @ git+https://gitlab.com/inkscape/extensions.git@618fe5e1e431d4b28a078660bf17afc65335fe39 # for linux user it may be tricky to install wxPython from sources # prebuilt packages: https://wxpython.org/pages/downloads/index.html |
