kopia lustrzana https://github.com/inkstitch/inkstitch
Autosatin: more efforts to keep the stroke width consistant (#3563)
* autosatin: more efforts to keep the stroke width consistant * allow users to use autosatin to add a running stitch from starting point to the start when only one satin is selectedpull/3568/head dev-build-kaalleen-build-fix-girepository
rodzic
51952d1f2a
commit
393a4af504
|
@ -8,14 +8,17 @@ from itertools import chain
|
|||
|
||||
import inkex
|
||||
import networkx as nx
|
||||
from inkex.units import convert_unit
|
||||
from shapely import geometry as shgeo
|
||||
from shapely import set_precision
|
||||
from shapely.geometry import Point as ShapelyPoint
|
||||
from shapely.ops import substring
|
||||
|
||||
from ..commands import add_commands
|
||||
from ..elements import SatinColumn, Stroke
|
||||
from ..i18n import _
|
||||
from ..svg import PIXELS_PER_MM, generate_unique_id, line_strings_to_csp
|
||||
from ..svg import (PIXELS_PER_MM, generate_unique_id, get_correction_transform,
|
||||
line_strings_to_csp)
|
||||
from ..svg.tags import (INKSCAPE_LABEL, INKSTITCH_ATTRIBS, ORIGINAL_D,
|
||||
PATH_EFFECT)
|
||||
from ..utils import Point as InkstitchPoint
|
||||
|
@ -87,6 +90,9 @@ class SatinSegment(object):
|
|||
if self.reverse:
|
||||
satin = satin.reverse()
|
||||
|
||||
stroke_width = convert_stroke_width(self.original_satin)
|
||||
satin.node.style['stroke-width'] = stroke_width
|
||||
|
||||
satin = satin.apply_transform()
|
||||
|
||||
_ensure_even_repeats(satin)
|
||||
|
@ -251,7 +257,8 @@ class RunningStitch(object):
|
|||
d = str(inkex.paths.CubicSuperPath(line_strings_to_csp([self.path])))
|
||||
node.set("d", d)
|
||||
|
||||
dasharray = inkex.Style("stroke-dasharray:0.5,0.5;")
|
||||
stroke_width = convert_stroke_width(self.original_element)
|
||||
dasharray = inkex.Style(f"stroke-width:{stroke_width};stroke-dasharray:1,0.2;")
|
||||
style = inkex.Style(self.original_element.node.get('style', '')) + dasharray
|
||||
node.set("style", str(style))
|
||||
if self.running_stitch_length != '':
|
||||
|
@ -351,6 +358,29 @@ def auto_satin(elements, preserve_order=False, starting_point=None, ending_point
|
|||
other.
|
||||
"""
|
||||
|
||||
if len(elements) == 1 and ending_point is None and starting_point is not None:
|
||||
# they just used this method to lazily create running stitch to start the satin
|
||||
# generate a line from starting point to the actual start of the satin
|
||||
satin = elements[0]
|
||||
parent = satin.node.getparent()
|
||||
index = parent.index(satin.node)
|
||||
|
||||
project = satin.center_line.project(ShapelyPoint(starting_point))
|
||||
path = substring(satin.center_line, project, 0)
|
||||
|
||||
run = RunningStitch(path, satin)
|
||||
run_element = run.to_element()
|
||||
|
||||
transform = get_correction_transform(satin.node, False)
|
||||
run_element.node.set('transform', transform)
|
||||
run_element.node.apply_transform()
|
||||
|
||||
stroke_width = convert_stroke_width(satin)
|
||||
run_element.node.style['stroke-width'] = stroke_width
|
||||
|
||||
parent.insert(index, run_element.node)
|
||||
return
|
||||
|
||||
# save these for create_new_group() call below
|
||||
if parent is None:
|
||||
parent = elements[-1].node.getparent()
|
||||
|
@ -393,6 +423,12 @@ def auto_satin(elements, preserve_order=False, starting_point=None, ending_point
|
|||
return new_elements
|
||||
|
||||
|
||||
def convert_stroke_width(element):
|
||||
document_unit = element.node.getroottree().getroot().document_unit
|
||||
stroke_width = convert_unit(element.stroke_width, document_unit)
|
||||
return stroke_width
|
||||
|
||||
|
||||
def build_graph(elements, preserve_order=False):
|
||||
if preserve_order:
|
||||
graph = nx.DiGraph()
|
||||
|
|
Ładowanie…
Reference in New Issue