From 3e9e95b00aa88226c8d4b2b6e600a98a751e1e5a Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 27 Feb 2015 14:50:54 +1100 Subject: [PATCH] Changed truetype() to prefer .ttf extensions --- PIL/ImageFont.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/PIL/ImageFont.py b/PIL/ImageFont.py index 61c552b1d..92722a7fe 100644 --- a/PIL/ImageFont.py +++ b/PIL/ImageFont.py @@ -283,12 +283,21 @@ def truetype(font=None, size=10, index=0, encoding="", filename=None): os.path.expanduser('~/Library/Fonts/')] ext = os.path.splitext(ttf_filename)[1] + firstFontWithADifferentExtension = None for dir in dirs: for walkroot, walkdir, walkfilenames in os.walk(dir): for walkfilename in walkfilenames: - if (ext and walkfilename == ttf_filename) or (not ext and os.path.splitext(walkfilename)[0] == ttf_filename): + if ext and walkfilename == ttf_filename: fontpath = os.path.join(walkroot, walkfilename) return FreeTypeFont(fontpath, size, index, encoding) + elif not ext and os.path.splitext(walkfilename)[0] == ttf_filename: + fontpath = os.path.join(walkroot, walkfilename) + if os.path.splitext(fontpath)[1] == '.ttf': + return FreeTypeFont(fontpath, size, index, encoding) + if not ext and firstFontWithADifferentExtension == None: + firstFontWithADifferentExtension = fontpath + if firstFontWithADifferentExtension: + return FreeTypeFont(firstFontWithADifferentExtension, size, index, encoding) raise