1
1
from .glyph_cache import GlyphCache
2
+ from displayio import Glyph
2
3
3
4
class BDF (GlyphCache ):
4
5
def __init__ (self , f , bitmap_class ):
@@ -29,16 +30,14 @@ def load_glyphs(self, code_points):
29
30
metadata = True
30
31
character = False
31
32
code_point = None
32
- rounded_x = 1
33
33
bytes_per_row = 1
34
34
desired_character = False
35
35
current_info = None
36
36
current_y = 0
37
+ rounded_x = 1
37
38
total_remaining = len (code_points )
38
39
39
40
x , _ , _ , _ = self .get_bounding_box ()
40
- # create a scratch bytearray to load pixels into
41
- scratch_row = memoryview (bytearray ((((x - 1 )// 32 )+ 1 ) * 4 ))
42
41
43
42
self .file .seek (0 )
44
43
while True :
@@ -58,7 +57,16 @@ def load_glyphs(self, code_points):
58
57
elif line .startswith (b"ENDCHAR" ):
59
58
character = False
60
59
if desired_character :
61
- self ._glyphs [code_point ] = current_info
60
+ bounds = current_info ["bounds" ]
61
+ shift = current_info ["shift" ]
62
+ self ._glyphs [code_point ] = Glyph (current_info ["bitmap" ],
63
+ 0 ,
64
+ bounds [0 ],
65
+ bounds [1 ],
66
+ bounds [2 ],
67
+ bounds [3 ],
68
+ shift [0 ],
69
+ shift [1 ])
62
70
if total_remaining == 0 :
63
71
return
64
72
desired_character = False
@@ -99,10 +107,19 @@ def load_glyphs(self, code_points):
99
107
elif character :
100
108
if desired_character :
101
109
bits = int (line .strip (), 16 )
110
+ width = current_info ["bounds" ][0 ]
111
+ start = current_y * width
112
+ x = 0
102
113
for i in range (rounded_x ):
103
114
val = (bits >> ((rounded_x - i - 1 )* 8 )) & 0xFF
104
- scratch_row [i ] = val
105
- current_info ["bitmap" ]._load_row (current_y , scratch_row [:bytes_per_row ])
115
+ for j in range (7 ,- 1 ,- 1 ):
116
+ if x >= width :
117
+ break
118
+ bit = 0
119
+ if val & (1 << j ) != 0 :
120
+ bit = 1
121
+ current_info ["bitmap" ][start + x ] = bit
122
+ x += 1
106
123
current_y += 1
107
124
elif metadata :
108
125
#print(lineno, line.strip())
0 commit comments