11from  .glyph_cache  import  GlyphCache 
2+ from  displayio  import  Glyph 
23
34class  BDF (GlyphCache ):
45    def  __init__ (self , f , bitmap_class ):
@@ -29,16 +30,14 @@ def load_glyphs(self, code_points):
2930        metadata  =  True 
3031        character  =  False 
3132        code_point  =  None 
32-         rounded_x  =  1 
3333        bytes_per_row  =  1 
3434        desired_character  =  False 
3535        current_info  =  None 
3636        current_y  =  0 
37+         rounded_x  =  1 
3738        total_remaining  =  len (code_points )
3839
3940        x , _ , _ , _  =  self .get_bounding_box ()
40-         # create a scratch bytearray to load pixels into 
41-         scratch_row  =  memoryview (bytearray ((((x - 1 )// 32 )+ 1 ) *  4 ))
4241
4342        self .file .seek (0 )
4443        while  True :
@@ -58,7 +57,16 @@ def load_glyphs(self, code_points):
5857            elif  line .startswith (b"ENDCHAR" ):
5958                character  =  False 
6059                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 ])
6270                    if  total_remaining  ==  0 :
6371                        return 
6472                desired_character  =  False 
@@ -99,10 +107,19 @@ def load_glyphs(self, code_points):
99107            elif  character :
100108                if  desired_character :
101109                    bits  =  int (line .strip (), 16 )
110+                     width  =  current_info ["bounds" ][0 ]
111+                     start  =  current_y  *  width 
112+                     x  =  0 
102113                    for  i  in  range (rounded_x ):
103114                        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 
106123                    current_y  +=  1 
107124            elif  metadata :
108125                #print(lineno, line.strip()) 
0 commit comments