Skip to content

Commit 9de9fad

Browse files
authored
Merge pull request #56 from tekktrik/feature/ignore-comments-parsing
Ignore COMMENTS when parsing for FONTBOUNDINGBOX
2 parents ed99973 + 21b9c62 commit 9de9fad

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))
@@ -106,6 +105,10 @@ def _verify_bounding_box(self):
106105
"Source file does not have the FOUNTBOUNDINGBOX parameter"
107106
) from error
108107

108+
def _readline_file(self):
109+
line = self.file.readline()
110+
return str(line, "utf-8")
111+
109112
def get_bounding_box(self):
110113
"""Return the maximum glyph size as a 4-tuple of: width, height, x_offset, y_offset"""
111114
return self._boundingbox

0 commit comments

Comments
 (0)