mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-04 21:50:54 +03:00
Merge pull request #6971 from akx/clarify-variable-names
Clarify some local variable names
This commit is contained in:
commit
6df3ad6f2d
|
@ -64,16 +64,27 @@ def bdf_char(f):
|
||||||
bitmap.append(s[:-1])
|
bitmap.append(s[:-1])
|
||||||
bitmap = b"".join(bitmap)
|
bitmap = b"".join(bitmap)
|
||||||
|
|
||||||
[x, y, l, d] = [int(p) for p in props["BBX"].split()]
|
# The word BBX
|
||||||
[dx, dy] = [int(p) for p in props["DWIDTH"].split()]
|
# followed by the width in x (BBw), height in y (BBh),
|
||||||
|
# and x and y displacement (BBxoff0, BByoff0)
|
||||||
|
# of the lower left corner from the origin of the character.
|
||||||
|
width, height, x_disp, y_disp = [int(p) for p in props["BBX"].split()]
|
||||||
|
|
||||||
bbox = (dx, dy), (l, -d - y, x + l, -d), (0, 0, x, y)
|
# The word DWIDTH
|
||||||
|
# followed by the width in x and y of the character in device pixels.
|
||||||
|
dwx, dwy = [int(p) for p in props["DWIDTH"].split()]
|
||||||
|
|
||||||
|
bbox = (
|
||||||
|
(dwx, dwy),
|
||||||
|
(x_disp, -y_disp - height, width + x_disp, -y_disp),
|
||||||
|
(0, 0, width, height),
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
im = Image.frombytes("1", (x, y), bitmap, "hex", "1")
|
im = Image.frombytes("1", (width, height), bitmap, "hex", "1")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# deal with zero-width characters
|
# deal with zero-width characters
|
||||||
im = Image.new("1", (x, y))
|
im = Image.new("1", (width, height))
|
||||||
|
|
||||||
return id, int(props["ENCODING"]), bbox, im
|
return id, int(props["ENCODING"]), bbox, im
|
||||||
|
|
||||||
|
|
|
@ -765,17 +765,17 @@ class Image:
|
||||||
|
|
||||||
bufsize = max(65536, self.size[0] * 4) # see RawEncode.c
|
bufsize = max(65536, self.size[0] * 4) # see RawEncode.c
|
||||||
|
|
||||||
data = []
|
output = []
|
||||||
while True:
|
while True:
|
||||||
l, s, d = e.encode(bufsize)
|
bytes_consumed, errcode, data = e.encode(bufsize)
|
||||||
data.append(d)
|
output.append(data)
|
||||||
if s:
|
if errcode:
|
||||||
break
|
break
|
||||||
if s < 0:
|
if errcode < 0:
|
||||||
msg = f"encoder error {s} in tobytes"
|
msg = f"encoder error {errcode} in tobytes"
|
||||||
raise RuntimeError(msg)
|
raise RuntimeError(msg)
|
||||||
|
|
||||||
return b"".join(data)
|
return b"".join(output)
|
||||||
|
|
||||||
def tobitmap(self, name="image"):
|
def tobitmap(self, name="image"):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -530,20 +530,20 @@ def _encode_tile(im, fp, tile, bufsize, fh, exc=None):
|
||||||
encoder.setimage(im.im, b)
|
encoder.setimage(im.im, b)
|
||||||
if encoder.pushes_fd:
|
if encoder.pushes_fd:
|
||||||
encoder.setfd(fp)
|
encoder.setfd(fp)
|
||||||
l, s = encoder.encode_to_pyfd()
|
errcode = encoder.encode_to_pyfd()[1]
|
||||||
else:
|
else:
|
||||||
if exc:
|
if exc:
|
||||||
# compress to Python file-compatible object
|
# compress to Python file-compatible object
|
||||||
while True:
|
while True:
|
||||||
l, s, d = encoder.encode(bufsize)
|
errcode, data = encoder.encode(bufsize)[1:]
|
||||||
fp.write(d)
|
fp.write(data)
|
||||||
if s:
|
if errcode:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# slight speedup: compress to real file object
|
# slight speedup: compress to real file object
|
||||||
s = encoder.encode_to_file(fh, bufsize)
|
errcode = encoder.encode_to_file(fh, bufsize)
|
||||||
if s < 0:
|
if errcode < 0:
|
||||||
msg = f"encoder error {s} when writing image file"
|
msg = f"encoder error {errcode} when writing image file"
|
||||||
raise OSError(msg) from exc
|
raise OSError(msg) from exc
|
||||||
finally:
|
finally:
|
||||||
encoder.cleanup()
|
encoder.cleanup()
|
||||||
|
|
|
@ -86,9 +86,22 @@ class PcfFontFile(FontFile.FontFile):
|
||||||
|
|
||||||
for ch, ix in enumerate(encoding):
|
for ch, ix in enumerate(encoding):
|
||||||
if ix is not None:
|
if ix is not None:
|
||||||
x, y, l, r, w, a, d, f = metrics[ix]
|
(
|
||||||
glyph = (w, 0), (l, d - y, x + l, d), (0, 0, x, y), bitmaps[ix]
|
xsize,
|
||||||
self.glyph[ch] = glyph
|
ysize,
|
||||||
|
left,
|
||||||
|
right,
|
||||||
|
width,
|
||||||
|
ascent,
|
||||||
|
descent,
|
||||||
|
attributes,
|
||||||
|
) = metrics[ix]
|
||||||
|
self.glyph[ch] = (
|
||||||
|
(width, 0),
|
||||||
|
(left, descent - ysize, xsize + left, descent),
|
||||||
|
(0, 0, xsize, ysize),
|
||||||
|
bitmaps[ix],
|
||||||
|
)
|
||||||
|
|
||||||
def _getformat(self, tag):
|
def _getformat(self, tag):
|
||||||
format, size, offset = self.toc[tag]
|
format, size, offset = self.toc[tag]
|
||||||
|
@ -206,9 +219,11 @@ class PcfFontFile(FontFile.FontFile):
|
||||||
mode = "1"
|
mode = "1"
|
||||||
|
|
||||||
for i in range(nbitmaps):
|
for i in range(nbitmaps):
|
||||||
x, y, l, r, w, a, d, f = metrics[i]
|
xsize, ysize = metrics[i][:2]
|
||||||
b, e = offsets[i], offsets[i + 1]
|
b, e = offsets[i : i + 2]
|
||||||
bitmaps.append(Image.frombytes("1", (x, y), data[b:e], "raw", mode, pad(x)))
|
bitmaps.append(
|
||||||
|
Image.frombytes("1", (xsize, ysize), data[b:e], "raw", mode, pad(xsize))
|
||||||
|
)
|
||||||
|
|
||||||
return bitmaps
|
return bitmaps
|
||||||
|
|
||||||
|
|
|
@ -1845,13 +1845,13 @@ def _save(im, fp, filename):
|
||||||
e.setimage(im.im, (0, 0) + im.size)
|
e.setimage(im.im, (0, 0) + im.size)
|
||||||
while True:
|
while True:
|
||||||
# undone, change to self.decodermaxblock:
|
# undone, change to self.decodermaxblock:
|
||||||
l, s, d = e.encode(16 * 1024)
|
errcode, data = e.encode(16 * 1024)[1:]
|
||||||
if not _fp:
|
if not _fp:
|
||||||
fp.write(d)
|
fp.write(data)
|
||||||
if s:
|
if errcode:
|
||||||
break
|
break
|
||||||
if s < 0:
|
if errcode < 0:
|
||||||
msg = f"encoder error {s} when writing image file"
|
msg = f"encoder error {errcode} when writing image file"
|
||||||
raise OSError(msg)
|
raise OSError(msg)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user