Skip to content

Commit ceeaa3b

Browse files
committed
Be able to load a Face from a non-ASCII path on Windows
1 parent 83bf5d3 commit ceeaa3b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

freetype/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,9 +1182,19 @@ def __init__( self, path_or_stream, index = 0 ):
11821182
if hasattr(path_or_stream, "read"):
11831183
error = self._init_from_memory(library, face, index, path_or_stream.read())
11841184
else:
1185-
try:
1186-
error = self._init_from_file(library, face, index, path_or_stream)
1187-
except UnicodeError:
1185+
open_from_memory = False
1186+
1187+
if platform.system() == "Windows" and not path_or_stream.isascii():
1188+
# FreeType cannot load fonts with non-ASCII characters on Windows
1189+
# See: https://gitlab.freedesktop.org/freetype/freetype/-/issues/1098
1190+
open_from_memory = True
1191+
else:
1192+
try:
1193+
error = self._init_from_file(library, face, index, path_or_stream)
1194+
except UnicodeError:
1195+
open_from_memory = True
1196+
1197+
if open_from_memory:
11881198
with open(path_or_stream, mode="rb") as f:
11891199
filebody = f.read()
11901200
error = self._init_from_memory(library, face, index, filebody)

0 commit comments

Comments
 (0)