* fix currentColor
* fix pip inkex import
* fix color block extension
pull/2895/head
Kaalleen 2024-05-11 08:14:40 +02:00 zatwierdzone przez GitHub
rodzic 19b59aa2f4
commit bf42ef00ca
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
17 zmienionych plików z 39 dodań i 42 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -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)

Wyświetl plik

@ -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

Wyświetl plik

@ -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)

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -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,

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -1,7 +1,7 @@
import threading
from ..exceptions import InkstitchException
from ..debug import debug
from ..debug.debug import debug
class ExitThread(InkstitchException):

Wyświetl plik

@ -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