Skip to content

Commit 37cf9bf

Browse files
committed
Update for displayio.Glyph
1 parent 38dd83f commit 37cf9bf

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

adafruit_bitmap_font/bdf.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import gc
22
from .glyph_cache import GlyphCache
3+
from displayio import Glyph
34

45
class BDF(GlyphCache):
56
def __init__(self, f, bitmap_class):
@@ -30,16 +31,14 @@ def load_glyphs(self, code_points):
3031
metadata = True
3132
character = False
3233
code_point = None
33-
rounded_x = 1
3434
bytes_per_row = 1
3535
desired_character = False
3636
current_info = None
3737
current_y = 0
38+
rounded_x = 1
3839
total_remaining = len(code_points)
3940

4041
x, _, _, _ = self.get_bounding_box()
41-
# create a scratch bytearray to load pixels into
42-
scratch_row = memoryview(bytearray((((x-1)//32)+1) * 4))
4342

4443
self.file.seek(0)
4544
while True:
@@ -59,7 +58,16 @@ def load_glyphs(self, code_points):
5958
elif line.startswith(b"ENDCHAR"):
6059
character = False
6160
if desired_character:
62-
self._glyphs[code_point] = current_info
61+
bounds = current_info["bounds"]
62+
shift = current_info["shift"]
63+
self._glyphs[code_point] = Glyph(current_info["bitmap"],
64+
0,
65+
bounds[0],
66+
bounds[1],
67+
bounds[2],
68+
bounds[3],
69+
shift[0],
70+
shift[1])
6371
gc.collect()
6472
if total_remaining == 0:
6573
return
@@ -101,10 +109,19 @@ def load_glyphs(self, code_points):
101109
elif character:
102110
if desired_character:
103111
bits = int(line.strip(), 16)
112+
width = current_info["bounds"][0]
113+
start = current_y * width
114+
x = 0
104115
for i in range(rounded_x):
105116
val = (bits >> ((rounded_x-i-1)*8)) & 0xFF
106-
scratch_row[i] = val
107-
current_info["bitmap"]._load_row(current_y, scratch_row[:bytes_per_row])
117+
for j in range(7,-1,-1):
118+
if x >= width:
119+
break
120+
bit = 0
121+
if val & (1 << j) != 0:
122+
bit = 1
123+
current_info["bitmap"][start + x] = bit
124+
x += 1
108125
current_y += 1
109126
elif metadata:
110127
#print(lineno, line.strip())

0 commit comments

Comments
 (0)