Partial Fix #370: look for osx fonts in common places

This commit is contained in:
Charles Law 2014-12-26 15:12:21 -08:00 committed by Charles Law
parent 707b43f14d
commit 4d2dd3ee7b

View File

@ -239,6 +239,10 @@ def truetype(font=None, size=10, index=0, encoding="", filename=None):
try:
return FreeTypeFont(font, size, index, encoding)
except IOError:
if font.endswith(".ttf"):
ttf_filename = font
else:
ttf_filename = "%s.ttf" % font
if sys.platform == "win32":
# check the windows font repository
# NOTE: must use uppercase WINDIR, to work around bugs in
@ -247,6 +251,12 @@ def truetype(font=None, size=10, index=0, encoding="", filename=None):
if windir:
filename = os.path.join(windir, "fonts", font)
return FreeTypeFont(filename, size, index, encoding)
elif sys.platform == 'darwin':
macdirs = ['/Library/Fonts/', '/System/Library/Fonts/', os.path.expanduser('~/Library/Fonts/')]
for macdir in macdirs:
filepath = os.path.join(macdir, ttf_filename)
if os.path.exists(filepath):
return FreeTypeFont(filepath, size, index, encoding)
raise