mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-06 21:40:09 +03:00
Remove some code duplication
This commit is contained in:
parent
b36ffcbe9a
commit
0907ab0ccf
|
@ -207,7 +207,8 @@ def truetype(font=None, size=10, index=0, encoding="", filename=None):
|
||||||
|
|
||||||
:param filename: A truetype font file. Under Windows, if the file
|
:param filename: A truetype font file. Under Windows, if the file
|
||||||
is not found in this filename, the loader also looks in
|
is not found in this filename, the loader also looks in
|
||||||
Windows :file:`fonts/` directory.
|
Windows :file:`fonts/` and Linux :file:`XDG_DATA_DIRS`
|
||||||
|
directories.
|
||||||
:param size: The requested size, in points.
|
:param size: The requested size, in points.
|
||||||
:param index: Which font face to load (default is first available face).
|
:param index: Which font face to load (default is first available face).
|
||||||
:param encoding: Which font encoding to use (default is Unicode). Common
|
:param encoding: Which font encoding to use (default is Unicode). Common
|
||||||
|
@ -227,20 +228,18 @@ def truetype(font=None, size=10, index=0, encoding="", filename=None):
|
||||||
try:
|
try:
|
||||||
return FreeTypeFont(font, size, index, encoding)
|
return FreeTypeFont(font, size, index, encoding)
|
||||||
except IOError:
|
except IOError:
|
||||||
|
dir = None
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
# check the windows font repository
|
# check the windows font repository
|
||||||
# NOTE: must use uppercase WINDIR, to work around bugs in
|
# NOTE: must use uppercase WINDIR, to work around bugs in
|
||||||
# 1.5.2's os.environ.get()
|
# 1.5.2's os.environ.get()
|
||||||
windir = os.environ.get("WINDIR")
|
dir = os.environ.get("WINDIR")
|
||||||
if windir:
|
|
||||||
filename = os.path.join(windir, "fonts", font)
|
|
||||||
return FreeTypeFont(filename, size, index, encoding)
|
|
||||||
elif sys.platform == "linux":
|
elif sys.platform == "linux":
|
||||||
# check the linux font repository
|
# check the Linux font repository
|
||||||
lindir = os.environ.get("XDG_DATA_DIRS")
|
dir = os.environ.get("XDG_DATA_DIRS")
|
||||||
if lindir:
|
if dir:
|
||||||
filename = os.path.join(lindir, "fonts", font)
|
filename = os.path.join(dir, "fonts", font)
|
||||||
return FreeTypeFont(filename, size, index, encoding)
|
return FreeTypeFont(filename, size, index, encoding)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user