@@ -39,8 +39,7 @@ def __init__(self, f, bitmap_class):
39
39
self .name = f
40
40
self .file .seek (0 )
41
41
self .bitmap_class = bitmap_class
42
- line = self .file .readline ()
43
- line = str (line , "utf-8" )
42
+ line = self ._readline_file ()
44
43
if not line or not line .startswith ("STARTFONT 2.1" ):
45
44
raise ValueError ("Unsupported file version" )
46
45
self ._verify_bounding_box ()
@@ -72,8 +71,7 @@ def ascent(self):
72
71
if self ._ascent is None :
73
72
self .file .seek (0 )
74
73
while True :
75
- line = self .file .readline ()
76
- line = str (line , "utf-8" )
74
+ line = self ._readline_file ()
77
75
if not line :
78
76
break
79
77
@@ -93,8 +91,9 @@ def _verify_bounding_box(self):
93
91
# Exception is when font file have a comment. Comments are three lines
94
92
# 10 lines is a safe bet
95
93
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 ()
98
97
if line .startswith ("FONTBOUNDINGBOX " ):
99
98
_ , x , y , x_offset , y_offset = line .split ()
100
99
self ._boundingbox = (int (x ), int (y ), int (x_offset ), int (y_offset ))
@@ -106,6 +105,10 @@ def _verify_bounding_box(self):
106
105
"Source file does not have the FOUNTBOUNDINGBOX parameter"
107
106
) from error
108
107
108
+ def _readline_file (self ):
109
+ line = self .file .readline ()
110
+ return str (line , "utf-8" )
111
+
109
112
def get_bounding_box (self ):
110
113
"""Return the maximum glyph size as a 4-tuple of: width, height, x_offset, y_offset"""
111
114
return self ._boundingbox
0 commit comments