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

This commit is contained in:
Charles Law 2014-12-26 15:10:52 -08:00 committed by Charles Law
parent 4d2dd3ee7b
commit 17d720aebc

View File

@ -251,6 +251,14 @@ 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 in ('linux', 'linux2'):
lindirs = os.environ.get("XDG_DATA_DIRS", "").split(":")
for lindir in lindirs:
parentpath = os.path.join(lindir, "fonts")
for walkroot, walkdir, walkfilenames in os.walk(parentpath):
if ttf_filename in walkfilenames:
filepath = os.path.join(walkroot, ttf_filename)
return FreeTypeFont(filepath, size, index, encoding)
elif sys.platform == 'darwin':
macdirs = ['/Library/Fonts/', '/System/Library/Fonts/', os.path.expanduser('~/Library/Fonts/')]
for macdir in macdirs: