Skip to content

Commit 6df3ad6

Browse files
authored
Merge pull request #6971 from akx/clarify-variable-names
Clarify some local variable names
2 parents 7d8a08b + bbbaf3c commit 6df3ad6

File tree

5 files changed

+57
-31
lines changed

5 files changed

+57
-31
lines changed

src/PIL/BdfFontFile.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,27 @@ def bdf_char(f):
6464
bitmap.append(s[:-1])
6565
bitmap = b"".join(bitmap)
6666

67-
[x, y, l, d] = [int(p) for p in props["BBX"].split()]
68-
[dx, dy] = [int(p) for p in props["DWIDTH"].split()]
69-
70-
bbox = (dx, dy), (l, -d - y, x + l, -d), (0, 0, x, y)
67+
# The word BBX
68+
# followed by the width in x (BBw), height in y (BBh),
69+
# and x and y displacement (BBxoff0, BByoff0)
70+
# of the lower left corner from the origin of the character.
71+
width, height, x_disp, y_disp = [int(p) for p in props["BBX"].split()]
72+
73+
# The word DWIDTH
74+
# followed by the width in x and y of the character in device pixels.
75+
dwx, dwy = [int(p) for p in props["DWIDTH"].split()]
76+
77+
bbox = (
78+
(dwx, dwy),
79+
(x_disp, -y_disp - height, width + x_disp, -y_disp),
80+
(0, 0, width, height),
81+
)
7182

7283
try:
73-
im = Image.frombytes("1", (x, y), bitmap, "hex", "1")
84+
im = Image.frombytes("1", (width, height), bitmap, "hex", "1")
7485
except ValueError:
7586
# deal with zero-width characters
76-
im = Image.new("1", (x, y))
87+
im = Image.new("1", (width, height))
7788

7889
return id, int(props["ENCODING"]), bbox, im
7990

src/PIL/Image.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -765,17 +765,17 @@ def tobytes(self, encoder_name="raw", *args):
765765

766766
bufsize = max(65536, self.size[0] * 4) # see RawEncode.c
767767

768-
data = []
768+
output = []
769769
while True:
770-
l, s, d = e.encode(bufsize)
771-
data.append(d)
772-
if s:
770+
bytes_consumed, errcode, data = e.encode(bufsize)
771+
output.append(data)
772+
if errcode:
773773
break
774-
if s < 0:
775-
msg = f"encoder error {s} in tobytes"
774+
if errcode < 0:
775+
msg = f"encoder error {errcode} in tobytes"
776776
raise RuntimeError(msg)
777777

778-
return b"".join(data)
778+
return b"".join(output)
779779

780780
def tobitmap(self, name="image"):
781781
"""

src/PIL/ImageFile.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,20 +530,20 @@ def _encode_tile(im, fp, tile, bufsize, fh, exc=None):
530530
encoder.setimage(im.im, b)
531531
if encoder.pushes_fd:
532532
encoder.setfd(fp)
533-
l, s = encoder.encode_to_pyfd()
533+
errcode = encoder.encode_to_pyfd()[1]
534534
else:
535535
if exc:
536536
# compress to Python file-compatible object
537537
while True:
538-
l, s, d = encoder.encode(bufsize)
539-
fp.write(d)
540-
if s:
538+
errcode, data = encoder.encode(bufsize)[1:]
539+
fp.write(data)
540+
if errcode:
541541
break
542542
else:
543543
# slight speedup: compress to real file object
544-
s = encoder.encode_to_file(fh, bufsize)
545-
if s < 0:
546-
msg = f"encoder error {s} when writing image file"
544+
errcode = encoder.encode_to_file(fh, bufsize)
545+
if errcode < 0:
546+
msg = f"encoder error {errcode} when writing image file"
547547
raise OSError(msg) from exc
548548
finally:
549549
encoder.cleanup()

src/PIL/PcfFontFile.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,22 @@ def __init__(self, fp, charset_encoding="iso8859-1"):
8686

8787
for ch, ix in enumerate(encoding):
8888
if ix is not None:
89-
x, y, l, r, w, a, d, f = metrics[ix]
90-
glyph = (w, 0), (l, d - y, x + l, d), (0, 0, x, y), bitmaps[ix]
91-
self.glyph[ch] = glyph
89+
(
90+
xsize,
91+
ysize,
92+
left,
93+
right,
94+
width,
95+
ascent,
96+
descent,
97+
attributes,
98+
) = metrics[ix]
99+
self.glyph[ch] = (
100+
(width, 0),
101+
(left, descent - ysize, xsize + left, descent),
102+
(0, 0, xsize, ysize),
103+
bitmaps[ix],
104+
)
92105

93106
def _getformat(self, tag):
94107
format, size, offset = self.toc[tag]
@@ -206,9 +219,11 @@ def _load_bitmaps(self, metrics):
206219
mode = "1"
207220

208221
for i in range(nbitmaps):
209-
x, y, l, r, w, a, d, f = metrics[i]
210-
b, e = offsets[i], offsets[i + 1]
211-
bitmaps.append(Image.frombytes("1", (x, y), data[b:e], "raw", mode, pad(x)))
222+
xsize, ysize = metrics[i][:2]
223+
b, e = offsets[i : i + 2]
224+
bitmaps.append(
225+
Image.frombytes("1", (xsize, ysize), data[b:e], "raw", mode, pad(xsize))
226+
)
212227

213228
return bitmaps
214229

src/PIL/TiffImagePlugin.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,13 +1845,13 @@ def _save(im, fp, filename):
18451845
e.setimage(im.im, (0, 0) + im.size)
18461846
while True:
18471847
# undone, change to self.decodermaxblock:
1848-
l, s, d = e.encode(16 * 1024)
1848+
errcode, data = e.encode(16 * 1024)[1:]
18491849
if not _fp:
1850-
fp.write(d)
1851-
if s:
1850+
fp.write(data)
1851+
if errcode:
18521852
break
1853-
if s < 0:
1854-
msg = f"encoder error {s} when writing image file"
1853+
if errcode < 0:
1854+
msg = f"encoder error {errcode} when writing image file"
18551855
raise OSError(msg)
18561856

18571857
else:

0 commit comments

Comments
 (0)