@@ -143,21 +143,23 @@ def __init__(self, font=None, size=10, index=0, encoding="", layout_engine=None)
143143 def load_from_bytes (f ):
144144 self .font_bytes = f .read ()
145145 self .font = core .getfont (
146- "" , size , index , encoding , self .font_bytes , layout_engine )
146+ "" , size , index , encoding , self .font_bytes , layout_engine
147+ )
147148
148149 if isPath (font ):
149150 if sys .platform == "win32" :
150151 font_bytes_path = font if isinstance (font , bytes ) else font .encode ()
151152 try :
152- font_bytes_path .decode (' ascii' )
153+ font_bytes_path .decode (" ascii" )
153154 except UnicodeDecodeError :
154155 # FreeType cannot load fonts with non-ASCII characters on Windows
155156 # So load it into memory first
156- with open (font , 'rb' ) as f :
157+ with open (font , "rb" ) as f :
157158 load_from_bytes (f )
158159 return
159- self .font = core .getfont (font , size , index , encoding ,
160- layout_engine = layout_engine )
160+ self .font = core .getfont (
161+ font , size , index , encoding , layout_engine = layout_engine
162+ )
161163 else :
162164 load_from_bytes (font )
163165
@@ -483,8 +485,10 @@ def truetype(font=None, size=10, index=0, encoding="", layout_engine=None):
483485 :return: A font object.
484486 :exception IOError: If the file could not be read.
485487 """
488+
486489 def freetype (font ):
487490 return FreeTypeFont (font , size , index , encoding , layout_engine )
491+
488492 try :
489493 return freetype (font )
490494 except IOError :
@@ -519,13 +523,11 @@ def freetype(font):
519523 for walkfilename in walkfilenames :
520524 if ext and walkfilename == ttf_filename :
521525 return freetype (os .path .join (walkroot , walkfilename ))
522- elif (not ext and
523- os .path .splitext (walkfilename )[0 ] == ttf_filename ):
526+ elif not ext and os .path .splitext (walkfilename )[0 ] == ttf_filename :
524527 fontpath = os .path .join (walkroot , walkfilename )
525- if os .path .splitext (fontpath )[1 ] == ' .ttf' :
528+ if os .path .splitext (fontpath )[1 ] == " .ttf" :
526529 return freetype (fontpath )
527- if not ext \
528- and first_font_with_a_different_extension is None :
530+ if not ext and first_font_with_a_different_extension is None :
529531 first_font_with_a_different_extension = fontpath
530532 if first_font_with_a_different_extension :
531533 return freetype (first_font_with_a_different_extension )
0 commit comments