Skip to content

Commit 84396c9

Browse files
committed
Ignore COMMENT lines when looking for FONTBOUNDINGBOX
1 parent a932fa7 commit 84396c9

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

adafruit_bitmap_font/bdf.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ def __init__(self, f, bitmap_class):
3939
self.name = f
4040
self.file.seek(0)
4141
self.bitmap_class = bitmap_class
42-
line = self.file.readline()
43-
line = str(line, "utf-8")
42+
line = self._readline_file()
4443
if not line or not line.startswith("STARTFONT 2.1"):
4544
raise ValueError("Unsupported file version")
4645
self._verify_bounding_box()
@@ -72,8 +71,7 @@ def ascent(self):
7271
if self._ascent is None:
7372
self.file.seek(0)
7473
while True:
75-
line = self.file.readline()
76-
line = str(line, "utf-8")
74+
line = self._readline_file()
7775
if not line:
7876
break
7977

@@ -93,8 +91,9 @@ def _verify_bounding_box(self):
9391
# Exception is when font file have a comment. Comments are three lines
9492
# 10 lines is a safe bet
9593
for _ in range(11):
96-
line = self.file.readline()
97-
line = str(line, "utf-8")
94+
line = self._readline_file()
95+
while line.startswith("COMMENT "):
96+
line = self._readline_file()
9897
if line.startswith("FONTBOUNDINGBOX "):
9998
_, x, y, x_offset, y_offset = line.split()
10099
self._boundingbox = (int(x), int(y), int(x_offset), int(y_offset))
@@ -105,6 +104,10 @@ def _verify_bounding_box(self):
105104
raise Exception(
106105
"Source file does not have the FOUNTBOUNDINGBOX parameter"
107106
) from error
107+
108+
def _readline_file(self):
109+
line = self.file.readline()
110+
return str(line, "utf-8")
108111

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

0 commit comments

Comments
 (0)