mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-27 20:43:43 +03:00
Handle pathlib.Path in FreeTypeFont
This commit is contained in:
parent
f9c7bd8611
commit
ae7958fa8d
|
@ -4,6 +4,7 @@ import re
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from packaging.version import parse as parse_version
|
from packaging.version import parse as parse_version
|
||||||
|
@ -76,8 +77,9 @@ def _render(font, layout_engine):
|
||||||
return img
|
return img
|
||||||
|
|
||||||
|
|
||||||
def test_font_with_name(layout_engine):
|
@pytest.mark.parametrize("font", (FONT_PATH, Path(FONT_PATH)))
|
||||||
_render(FONT_PATH, layout_engine)
|
def test_font_with_name(layout_engine, font):
|
||||||
|
_render(font, layout_engine)
|
||||||
|
|
||||||
|
|
||||||
def test_font_with_filelike(layout_engine):
|
def test_font_with_filelike(layout_engine):
|
||||||
|
|
|
@ -31,6 +31,7 @@ import sys
|
||||||
import warnings
|
import warnings
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
from ._util import is_directory, is_path
|
from ._util import is_directory, is_path
|
||||||
|
@ -213,6 +214,8 @@ class FreeTypeFont:
|
||||||
)
|
)
|
||||||
|
|
||||||
if is_path(font):
|
if is_path(font):
|
||||||
|
if isinstance(font, Path):
|
||||||
|
font = str(font)
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
font_bytes_path = font if isinstance(font, bytes) else font.encode()
|
font_bytes_path = font if isinstance(font, bytes) else font.encode()
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user