Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Ignore COMMENT lines when looking for FONTBOUNDINGBOX
  • Loading branch information
tekktrik committed Jan 18, 2022
commit 84396c9dfdd7b463690e4b22b023be134c3d5e00
15 changes: 9 additions & 6 deletions adafruit_bitmap_font/bdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ def __init__(self, f, bitmap_class):
self.name = f
self.file.seek(0)
self.bitmap_class = bitmap_class
line = self.file.readline()
line = str(line, "utf-8")
line = self._readline_file()
if not line or not line.startswith("STARTFONT 2.1"):
raise ValueError("Unsupported file version")
self._verify_bounding_box()
Expand Down Expand Up @@ -72,8 +71,7 @@ def ascent(self):
if self._ascent is None:
self.file.seek(0)
while True:
line = self.file.readline()
line = str(line, "utf-8")
line = self._readline_file()
if not line:
break

Expand All @@ -93,8 +91,9 @@ def _verify_bounding_box(self):
# Exception is when font file have a comment. Comments are three lines
# 10 lines is a safe bet
for _ in range(11):
line = self.file.readline()
line = str(line, "utf-8")
line = self._readline_file()
while line.startswith("COMMENT "):
line = self._readline_file()
if line.startswith("FONTBOUNDINGBOX "):
_, x, y, x_offset, y_offset = line.split()
self._boundingbox = (int(x), int(y), int(x_offset), int(y_offset))
Expand All @@ -105,6 +104,10 @@ def _verify_bounding_box(self):
raise Exception(
"Source file does not have the FOUNTBOUNDINGBOX parameter"
) from error

def _readline_file(self):
line = self.file.readline()
return str(line, "utf-8")

def get_bounding_box(self):
"""Return the maximum glyph size as a 4-tuple of: width, height, x_offset, y_offset"""
Expand Down