* shift the design to the origin
* don't include a bunch of extra END instructions at the end of a DST
pull/29/head
Lex Neva 2018-01-20 21:58:48 -05:00
rodzic a7a7c6cc92
commit 9c87b73e5b
1 zmienionych plików z 15 dodań i 3 usunięć

Wyświetl plik

@ -123,6 +123,12 @@ def get_flags(stitch):
return flags
def write_embroidery_file(file_path, stitches):
# Embroidery machines don't care about our canvas size, so we relocate the
# design to the origin. It might make sense to center it about the origin
# instead.
min_x = min(stitch.x for stitch in stitches)
min_y = min(stitch.y for stitch in stitches)
pattern = libembroidery.embPattern_create()
threads = {}
@ -141,12 +147,18 @@ def write_embroidery_file(file_path, stitches):
last_color = stitch.color
flags = get_flags(stitch)
libembroidery.embPattern_addStitchAbs(pattern, stitch.x, -stitch.y, flags, 0)
libembroidery.embPattern_addStitchAbs(pattern, stitch.x - min_x, stitch.y - min_y, flags, 0)
if flags & libembroidery.JUMP:
# I'm not sure this is right, but this is how the old version did it.
libembroidery.embPattern_addStitchAbs(pattern, stitch.x, -stitch.y, flags & ~libembroidery.JUMP, 0)
libembroidery.embPattern_addStitchAbs(pattern, stitch.x - min_x, stitch.y - min_y, flags & ~libembroidery.JUMP, 0)
libembroidery.embPattern_addStitchAbs(pattern, stitch.x, -stitch.y, libembroidery.END, 0)
libembroidery.embPattern_addStitchAbs(pattern, stitch.x - min_x, stitch.y - min_y, libembroidery.END, 0)
# convert from pixels to millimeters
libembroidery.embPattern_scale(pattern, 1/PIXELS_PER_MM)
# SVG and embroidery disagree on the direction of the Y axis
libembroidery.embPattern_flipVertical(pattern)
libembroidery.embPattern_write(pattern, file_path)