1
1
import gc
2
2
from .glyph_cache import GlyphCache
3
+ from displayio import Glyph
3
4
4
5
class BDF (GlyphCache ):
5
6
def __init__ (self , f , bitmap_class ):
@@ -30,16 +31,14 @@ def load_glyphs(self, code_points):
30
31
metadata = True
31
32
character = False
32
33
code_point = None
33
- rounded_x = 1
34
34
bytes_per_row = 1
35
35
desired_character = False
36
36
current_info = None
37
37
current_y = 0
38
+ rounded_x = 1
38
39
total_remaining = len (code_points )
39
40
40
41
x , _ , _ , _ = self .get_bounding_box ()
41
- # create a scratch bytearray to load pixels into
42
- scratch_row = memoryview (bytearray ((((x - 1 )// 32 )+ 1 ) * 4 ))
43
42
44
43
self .file .seek (0 )
45
44
while True :
@@ -59,7 +58,16 @@ def load_glyphs(self, code_points):
59
58
elif line .startswith (b"ENDCHAR" ):
60
59
character = False
61
60
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 ])
63
71
gc .collect ()
64
72
if total_remaining == 0 :
65
73
return
@@ -101,10 +109,19 @@ def load_glyphs(self, code_points):
101
109
elif character :
102
110
if desired_character :
103
111
bits = int (line .strip (), 16 )
112
+ width = current_info ["bounds" ][0 ]
113
+ start = current_y * width
114
+ x = 0
104
115
for i in range (rounded_x ):
105
116
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
108
125
current_y += 1
109
126
elif metadata :
110
127
#print(lineno, line.strip())
0 commit comments