Skip to content

Commit f005b78

Browse files
authored
Merge pull request #33 from EmbroidePy/tatarize-cli-help
Some updates for the CLI.
2 parents aede666 + 1e28035 commit f005b78

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

pyembroidery/EmbMatrix.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def inverse(self):
3333
def post_scale(self, sx=1, sy=None, x=0, y=0):
3434
if sy is None:
3535
sy = sx
36+
if x is None:
37+
x = 0
38+
if y is None:
39+
y = 0
3640
if x == 0 and y == 0:
3741
self.m = self.matrix_multiply(self.m, self.get_scale(sx, sy))
3842
else:
@@ -44,6 +48,10 @@ def post_translate(self, tx, ty):
4448
self.m = self.matrix_multiply(self.m, self.get_translate(tx, ty))
4549

4650
def post_rotate(self, theta, x=0, y=0):
51+
if x is None:
52+
x = 0
53+
if y is None:
54+
y = 0
4755
if x == 0 and y == 0:
4856
self.m = self.matrix_multiply(self.m, self.get_rotate(theta))
4957
else:
@@ -90,6 +98,13 @@ def point_in_matrix_space(self, v0, v1=None):
9098
v0 * m[1] + v1 * m[4] + 1 * m[7]
9199
]
92100

101+
def apply(self, v):
102+
m = self.m
103+
nx = v[0] * m[0] + v[1] * m[3] + 1 * m[6]
104+
ny = v[0] * m[1] + v[1] * m[4] + 1 * m[7]
105+
v[0] = nx
106+
v[1] = ny
107+
93108
@staticmethod
94109
def get_identity():
95110
return \

pyembroidery/EmbPattern.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ def translate(self, dx, dy):
233233
stitch[0] += dx
234234
stitch[1] += dy
235235

236+
def transform(self, matrix):
237+
for stitch in self.stitches:
238+
matrix.apply(stitch)
239+
236240
def fix_color_count(self):
237241
"""Ensure the there are threads for all color blocks."""
238242
thread_index = 0

pyembroidery/PesReader.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .PecReader import read_pec
21
from .EmbThread import EmbThread
2+
from .PecReader import read_pec
33
from .ReadHelper import read_string_8, read_int_8, read_int_32le, read_int_24be, read_int_16le
44

55

@@ -18,19 +18,37 @@ def read(f, out, settings=None):
1818
# Metadata started appearing in V4
1919
# Threads appeared in V5.
2020
# We quickly abort if there's any complex items in the header.
21-
# "#PES0100", "#PES0090" "#PES0080" "#PES0070", "#PES0040",
22-
# "#PES0030", "#PES0022", "#PES0020"
23-
if pes_string == "#PES0060":
21+
if pes_string == "PES0100":
22+
out.metadata("version", 10)
23+
elif pes_string == "#PES0090":
24+
out.metadata("version", 9)
25+
elif pes_string == "#PES0080":
26+
out.metadata("version", 8)
27+
elif pes_string == "#PES0070":
28+
out.metadata("version", 7)
29+
elif pes_string == "#PES0060":
30+
out.metadata("version", 6)
2431
read_pes_header_version_6(f, out, loaded_thread_values)
2532
elif pes_string == "#PES0050":
33+
out.metadata("version", 5)
2634
read_pes_header_version_5(f, out, loaded_thread_values)
2735
elif pes_string == "#PES0055":
36+
out.metadata("version", 5.5)
2837
read_pes_header_version_5(f, out, loaded_thread_values)
2938
elif pes_string == "#PES0056":
39+
out.metadata("version", 5.6)
3040
read_pes_header_version_5(f, out, loaded_thread_values)
3141
elif pes_string == "#PES0040":
42+
out.metadata("version", 4)
3243
read_pes_header_version_4(f, out)
44+
elif pes_string == "#PES0030":
45+
out.metadata("version", 3)
46+
elif pes_string == "#PES0022":
47+
out.metadata("version", 2.2)
48+
elif pes_string == "#PES0020":
49+
out.metadata("version", 2)
3350
elif pes_string == "#PES0001":
51+
out.metadata("version", 1)
3452
read_pes_header_version_1(f, out)
3553
else:
3654
pass # Header is unrecognised.

pyembroidery/PesWriter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
def write(pattern, f, settings=None):
2323
if settings is not None:
24-
version = settings.get("pes version", VERSION_1)
24+
version = float(settings.get("pes version", VERSION_1))
2525
truncated = settings.get("truncated", False)
2626
else:
2727
version = VERSION_1

pyembroidery/PyEmbroidery.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,14 @@ def convert(filename_from, filename_to, settings=None):
396396

397397

398398
def get_extension_by_filename(filename):
399-
"""extracts he extension from a filename"""
399+
"""extracts the extension from a filename"""
400400
return os.path.splitext(filename)[1][1:]
401401

402402

403403
def read_embroidery(reader, f, settings=None, pattern=None):
404404
"""Reads fileobject or filename with reader."""
405+
if reader is None:
406+
return None
405407
if pattern is None:
406408
pattern = EmbPattern()
407409
if isinstance(f, str):
@@ -482,6 +484,8 @@ def read(filename, settings=None, pattern=None):
482484

483485

484486
def write_embroidery(writer, pattern, stream, settings=None):
487+
if pattern is None:
488+
return
485489
if settings is None:
486490
settings = {}
487491
else:

0 commit comments

Comments
 (0)