summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLex Neva <lexelby@users.noreply.github.com>2019-08-11 16:26:54 -0400
committerGitHub <noreply@github.com>2019-08-11 16:26:54 -0400
commitb05cc4a031fb4dace2eded97a3e44e86e2f79fe8 (patch)
tree3c2e1490a2b4a38e0c0b02682b76c0b50de2e383
parent077f7ea72ba38790bf030d3181c44787fef953b6 (diff)
parentdafc3b97822ac0e929655bfa73590209e3350c47 (diff)
Merge pull request #509 from inkstitch/lexelby/input-fixes
input: read STOP commands too
-rw-r--r--lib/extensions/input.py19
-rw-r--r--lib/output.py2
-rw-r--r--lib/stitch_plan/stitch_plan.py20
-rw-r--r--lib/svg/rendering.py29
m---------pyembroidery0
5 files changed, 51 insertions, 19 deletions
diff --git a/lib/extensions/input.py b/lib/extensions/input.py
index a82cdfca..957d355c 100644
--- a/lib/extensions/input.py
+++ b/lib/extensions/input.py
@@ -13,25 +13,30 @@ class Input(object):
def affect(self, args):
embroidery_file = args[0]
pattern = pyembroidery.read(embroidery_file)
- pattern = pattern.get_pattern_interpolate_trim(3)
stitch_plan = StitchPlan()
color_block = None
for raw_stitches, thread in pattern.get_as_colorblocks():
color_block = stitch_plan.new_color_block(thread)
- trim_after = False
for x, y, command in raw_stitches:
if command == pyembroidery.STITCH:
- if trim_after:
- color_block.add_stitch(trim=True)
- trim_after = False
color_block.add_stitch(x * PIXELS_PER_MM / 10.0, y * PIXELS_PER_MM / 10.0)
- if len(color_block) > 0 and command == pyembroidery.TRIM:
- trim_after = True
+ if len(color_block) > 0:
+ if command == pyembroidery.TRIM:
+ color_block.add_stitch(trim=True)
+ elif command == pyembroidery.STOP:
+ color_block.add_stitch(stop=True)
+ color_block = stitch_plan.new_color_block(thread)
stitch_plan.delete_empty_color_blocks()
+ if stitch_plan.last_color_block:
+ if stitch_plan.last_color_block.last_stitch:
+ if stitch_plan.last_color_block.last_stitch.stop:
+ # ending with a STOP command is redundant, so remove it
+ del stitch_plan.last_color_block[-1]
+
extents = stitch_plan.extents
svg = etree.Element("svg", nsmap=inkex.NSS, attrib={
"width": str(extents[0] * 2),
diff --git a/lib/output.py b/lib/output.py
index 0958a6a2..21622765 100644
--- a/lib/output.py
+++ b/lib/output.py
@@ -98,7 +98,7 @@ def write_embroidery_file(file_path, stitch_plan, svg, settings={}):
settings['explicit_trim'] = False
try:
- pyembroidery.write(pattern, file_path.encode("UTF-8"), settings)
+ pyembroidery.write(pattern, file_path, settings)
except IOError as e:
# L10N low-level file error. %(error)s is (hopefully?) translated by
# the user's system automatically.
diff --git a/lib/stitch_plan/stitch_plan.py b/lib/stitch_plan/stitch_plan.py
index b621ef07..ac6b3b8d 100644
--- a/lib/stitch_plan/stitch_plan.py
+++ b/lib/stitch_plan/stitch_plan.py
@@ -169,6 +169,12 @@ class ColorBlock(object):
def __repr__(self):
return "ColorBlock(%s, %s)" % (self.color, self.stitches)
+ def __getitem__(self, item):
+ return self.stitches[item]
+
+ def __delitem__(self, item):
+ del self.stitches[item]
+
def has_color(self):
return self._color is not None
@@ -210,6 +216,20 @@ class ColorBlock(object):
else:
return False
+ @property
+ def trim_after(self):
+ # If there's a STOP, it will be at the end. We still want to return
+ # True.
+ for stitch in reversed(self.stitches):
+ if stitch.stop or stitch.jump:
+ continue
+ elif stitch.trim:
+ return True
+ else:
+ break
+
+ return False
+
def filter_duplicate_stitches(self):
if not self.stitches:
return
diff --git a/lib/svg/rendering.py b/lib/svg/rendering.py
index 532748bf..074380a7 100644
--- a/lib/svg/rendering.py
+++ b/lib/svg/rendering.py
@@ -147,11 +147,11 @@ def color_block_to_point_lists(color_block):
point_lists.append([])
continue
- if not stitch.jump and not stitch.color_change:
+ if not stitch.jump and not stitch.color_change and not stitch.stop:
point_lists[-1].append(stitch.as_tuple())
# filter out empty point lists
- point_lists = [p for p in point_lists if p]
+ point_lists = [p for p in point_lists if len(p) > 1]
return point_lists
@@ -169,9 +169,6 @@ def get_correction_transform(svg):
def color_block_to_realistic_stitches(color_block, svg, destination):
for point_list in color_block_to_point_lists(color_block):
- if not point_list:
- continue
-
color = color_block.color.visible_on_white.darker.to_hex_str()
start = point_list[0]
for point in point_list[1:]:
@@ -190,21 +187,23 @@ def color_block_to_realistic_stitches(color_block, svg, destination):
def color_block_to_paths(color_block, svg, destination):
+ # If we try to import these above, we get into a mess of circular
+ # imports.
+ from ..commands import add_commands
+ from ..elements.stroke import Stroke
+
# We could emit just a single path with one subpath per point list, but
# emitting multiple paths makes it easier for the user to manipulate them.
first = True
+ path = None
for point_list in color_block_to_point_lists(color_block):
if first:
first = False
else:
- # If we try to import these above, we get into a mess of circular
- # imports.
- from ..commands import add_commands
- from ..elements.stroke import Stroke
add_commands(Stroke(destination[-1]), ["trim"])
color = color_block.color.visible_on_white.to_hex_str()
- destination.append(inkex.etree.Element(
+ path = inkex.etree.Element(
SVG_PATH_TAG,
{'style': simplestyle.formatStyle(
{'stroke': color,
@@ -213,7 +212,15 @@ def color_block_to_paths(color_block, svg, destination):
'd': "M" + " ".join(" ".join(str(coord) for coord in point) for point in point_list),
'transform': get_correction_transform(svg),
'embroider_manual_stitch': 'true'
- }))
+ })
+ destination.append(path)
+
+ if path is not None:
+ if color_block.trim_after:
+ add_commands(Stroke(path), ["trim"])
+
+ if color_block.stop_after:
+ add_commands(Stroke(path), ["stop"])
def render_stitch_plan(svg, stitch_plan, realistic=False):
diff --git a/pyembroidery b/pyembroidery
-Subproject dc5b1abf871d5d0117bd7b7461f12a7a8af6338
+Subproject ce7771276aaaadaa184db5fd2ac19610d894107