Skip to content

Commit 6ae6e07

Browse files
committed
bdf: Add ascent, descent properties
This will be used by a future version of adafruit_display_text to avoid needing to load glyphs from the font to guess these values.
1 parent e15c7d1 commit 6ae6e07

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

adafruit_bitmap_font/bdf.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,41 @@ def __init__(self, f, bitmap_class):
6363
self.point_size = None
6464
self.x_resolution = None
6565
self.y_resolution = None
66+
self._ascent = None
67+
self._descent = None
68+
69+
@property
70+
def descent(self):
71+
"""The number of pixels below the baseline of a typical descender"""
72+
if self._descent is None:
73+
self.file.seek(0)
74+
while True:
75+
line = self.file.readline()
76+
if not line:
77+
break
78+
79+
if line.startswith(b"FONT_DESCENT "):
80+
self._descent = int(line.split()[1])
81+
break
82+
83+
return self._descent
84+
85+
@property
86+
def ascent(self):
87+
"""The number of pixels above the baseline of a typical ascender"""
88+
if self._ascent is None:
89+
self.file.seek(0)
90+
while True:
91+
line = self.file.readline()
92+
line = str(line, "utf-8")
93+
if not line:
94+
break
95+
96+
if line.startswith("FONT_ASCENT "):
97+
self._ascent = int(line.split()[1])
98+
break
99+
100+
return self._ascent
66101

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

0 commit comments

Comments
 (0)