Handle pathlib.Path in FreeTypeFont

This commit is contained in:
Andrew Murray 2023-11-27 23:03:10 +11:00
parent f9c7bd8611
commit ae7958fa8d
2 changed files with 7 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import re
import shutil
import sys
from io import BytesIO
from pathlib import Path
import pytest
from packaging.version import parse as parse_version
@ -76,8 +77,9 @@ def _render(font, layout_engine):
return img
def test_font_with_name(layout_engine):
_render(FONT_PATH, layout_engine)
@pytest.mark.parametrize("font", (FONT_PATH, Path(FONT_PATH)))
def test_font_with_name(layout_engine, font):
_render(font, layout_engine)
def test_font_with_filelike(layout_engine):

View File

@ -31,6 +31,7 @@ import sys
import warnings
from enum import IntEnum
from io import BytesIO
from pathlib import Path
from . import Image
from ._util import is_directory, is_path
@ -213,6 +214,8 @@ class FreeTypeFont:
)
if is_path(font):
if isinstance(font, Path):
font = str(font)
if sys.platform == "win32":
font_bytes_path = font if isinstance(font, bytes) else font.encode()
try: