File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -396,13 +396,17 @@ def __init__(self, font_name='font5x8.bin'):
396396        # Note that only fonts up to 8 pixels tall are currently supported. 
397397        try :
398398            self ._font  =  open (self .font_name , 'rb' )
399+             self .font_width , self .font_height  =  struct .unpack ('BB' , self ._font .read (2 ))
400+             # simple font file validation check based on expected file size 
401+             if  2  +  256  *  self .font_width  !=  os .stat (font_name )[6 ]:
402+                 raise  RuntimeError ("Invalid font file: "  +  font_name )
399403        except  OSError :
400404            print ("Could not find font file" , font_name )
401405            raise 
402-         self . font_width ,  self . font_height   =   struct . unpack ( 'BB' ,  self . _font . read ( 2 )) 
403-         # simple font file validation check based  on expected file size 
404-         if   2   +   256   *   self . font_width   !=   os . stat ( font_name )[ 6 ]: 
405-             raise   RuntimeError ( "Invalid font file: "   +   font_name ) 
406+         except   OverflowError : 
407+              # os.stat can throw this  on boards without long int support 
408+              # just hope the font file is valid and press on 
409+             pass 
406410
407411    def  deinit (self ):
408412        """Close the font file as cleanup.""" 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments