summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/output.py3
-rw-r--r--tests/test_output.py53
2 files changed, 56 insertions, 0 deletions
diff --git a/lib/output.py b/lib/output.py
index a16b4018..1b9c62a4 100644
--- a/lib/output.py
+++ b/lib/output.py
@@ -87,6 +87,9 @@ def write_embroidery_file(file_path, stitch_plan, svg, settings={}):
# This forces a jump at the start of the design and after each trim,
# even if we're close enough not to need one.
"full_jump": True,
+
+ # defaults to False in pyembroidery (see https://github.com/EmbroidePy/pyembroidery/issues/188)
+ "trims": True,
})
if not file_path.endswith(('.col', '.edr', '.inf')):
diff --git a/tests/test_output.py b/tests/test_output.py
new file mode 100644
index 00000000..476b73c7
--- /dev/null
+++ b/tests/test_output.py
@@ -0,0 +1,53 @@
+from inkex.tester import TestCase
+from inkex import SvgDocumentElement, Rectangle
+from inkex.tester.svg import svg
+
+from lib.svg.tags import INKSTITCH_ATTRIBS
+from lib import output
+from lib.stitch_plan.stitch_plan import StitchPlan, stitch_groups_to_stitch_plan
+from lib.elements.utils import node_to_elements
+
+
+class OutputTest(TestCase):
+ def _get_output(self, svg: SvgDocumentElement, format: str) -> bytes:
+ # TODO: support SVGs with more than one element
+ # (turn InkstitchExtension.elements_to_stitch_groups into a function so we can use it here?)
+ assert len(svg) == 1
+ [element] = node_to_elements(svg[0])
+ stitch_groups = element.embroider(None)
+ stitch_plan = stitch_groups_to_stitch_plan(stitch_groups)
+ path = self.temp_file(suffix=f".{format}")
+ output.write_embroidery_file(path, stitch_plan, svg)
+ with open(path, "rb") as f:
+ return f.read()
+
+ def test_jef_output_does_not_change(self):
+ root: SvgDocumentElement = svg()
+ rect = root.add(
+ Rectangle(
+ attrib={
+ "width": "10",
+ "height": "10",
+ }
+ )
+ )
+ output1 = self._get_output(root, "jef")
+ output2 = self._get_output(root, "jef")
+ assert output1 == output2
+
+ def test_jef_output_includes_trims(self):
+ root: SvgDocumentElement = svg()
+ rect = root.add(
+ Rectangle(
+ attrib={
+ "width": "10",
+ "height": "10",
+ }
+ )
+ )
+ output1 = self._get_output(root, "jef")
+
+ rect.attrib[INKSTITCH_ATTRIBS["trim_after"]] = "true"
+
+ output2 = self._get_output(root, "jef")
+ assert output1 != output2