Skip to content

Commit

Permalink
Clarify variable names in BdfFontFile
Browse files Browse the repository at this point in the history
Co-authored-by: Yay295 <Yay295@users.noreply.github.com>
  • Loading branch information
akx and Yay295 committed Feb 24, 2023
1 parent 879e77a commit f52bbf8
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/PIL/BdfFontFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,25 @@ def bdf_char(f):
bitmap.append(s[:-1])
bitmap = b"".join(bitmap)

[x, y, l, d] = [int(p) for p in props["BBX"].split()]
[dx, dy] = [int(p) for p in props["DWIDTH"].split()]
# The word BBX followed by the width in x (BBw), height in y (BBh),
# and x and y displacement (BBox, BBoy) 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 units.
dx, dy = [int(p) for p in props["DWIDTH"].split()]

bbox = (
(dx, dy),
(x_disp, -y_disp - height, width + x_disp, -y_disp),
(0, 0, width, height),
)

try:
im = Image.frombytes("1", (x, y), bitmap, "hex", "1")
im = Image.frombytes("1", (width, height), bitmap, "hex", "1")
except ValueError:
# deal with zero-width characters
im = Image.new("1", (x, y))
im = Image.new("1", (width, height))

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

Expand Down

0 comments on commit f52bbf8

Please sign in to comment.