Skip to content

Commit

Permalink
Merge pull request #171 from EmbroidePy/tbf-write-flip
Browse files Browse the repository at this point in the history
TBF Write Flipped
  • Loading branch information
tatarize authored Mar 27, 2024
2 parents ee465a5 + 3415d93 commit c16d1b4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
12 changes: 6 additions & 6 deletions pyembroidery/TbfWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,22 @@ def write(pattern, f, settings=None):

if data == STITCH:
cmd = 0x80
f.write(bytes(bytearray([dx & 0xFF, dy & 0xFF, cmd])))
f.write(bytes(bytearray([dx & 0xFF, -dy & 0xFF, cmd])))
elif data == JUMP:
cmd = 0x90
f.write(bytes(bytearray([dx & 0xFF, dy & 0xFF, cmd])))
f.write(bytes(bytearray([dx & 0xFF, -dy & 0xFF, cmd])))
elif data == STOP:
cmd = 0x40
f.write(bytes(bytearray([dx & 0xFF, dy & 0xFF, cmd])))
f.write(bytes(bytearray([dx & 0xFF, -dy & 0xFF, cmd])))
elif data == TRIM:
cmd = 0x86
f.write(bytes(bytearray([dx & 0xFF, dy & 0xFF, cmd])))
f.write(bytes(bytearray([dx & 0xFF, -dy & 0xFF, cmd])))
elif data == NEEDLE_SET:
cmd = 0x81
f.write(bytes(bytearray([dx & 0xFF, dy & 0xFF, cmd])))
f.write(bytes(bytearray([dx & 0xFF, -dy & 0xFF, cmd])))
elif data == END:
cmd = 0x8F
f.write(bytes(bytearray([dx & 0xFF, dy & 0xFF, cmd])))
f.write(bytes(bytearray([dx & 0xFF, -dy & 0xFF, cmd])))
break
# Terminal character.
f.write(b"\x1a")
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pyembroidery",
version="1.5.0",
version="1.5.1",
author="Tatarize",
author_email="tatarize@gmail.com",
description="Embroidery IO library",
Expand All @@ -22,6 +22,7 @@
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
'Topic :: Software Development :: Libraries :: Python Modules'
Expand Down
17 changes: 17 additions & 0 deletions test/test_convert_tbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,23 @@ def test_needles_convert_tbf_to_u01(self):
self.addCleanup(os.remove, file1)
self.addCleanup(os.remove, file2)

def test_tbf_flipped(self):
"""
Test whether tbf is flipped on subsequent loads. This creates a pattern. Saves/loads, then save/loads.
These patterns should be the same but a bug in 1.5.0 was flipping TBF patterns on write.
"""
pattern = get_fractal_pattern()
file1 = "fractal1.tbf"
file2 = "fractal2.tbf"
pattern.write(file1)
f1 = read_tbf(file1)
f1.write(file2)
f2 = read_tbf(file2)
for i in range(len(f1.stitches)):
self.assertEqual(f1.stitches[i], f2.stitches[i])
self.addCleanup(os.remove, file1)
self.addCleanup(os.remove, file2)

def test_needle_tbf_range(self):
file1 = "test_range8.tbf"
file2 = "test_range8.ct0"
Expand Down

0 comments on commit c16d1b4

Please sign in to comment.