diff --git a/Tests/images/default_font_freetype.png b/Tests/images/default_font_freetype.png index 65d9b18bb..e00bb5d85 100644 Binary files a/Tests/images/default_font_freetype.png and b/Tests/images/default_font_freetype.png differ diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index 048d1f351..7121530db 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -459,6 +459,9 @@ def test_default_font(): default_font = ImageFont.load_default() draw.text((10, 10), txt, font=default_font) + larger_default_font = ImageFont.load_default(size=14) + draw.text((10, 60), txt, font=larger_default_font) + # Assert assert_image_equal_tofile(im, "Tests/images/default_font_freetype.png") diff --git a/Tests/test_imagefontpil.py b/Tests/test_imagefontpil.py index 82cb9224f..c30463e81 100644 --- a/Tests/test_imagefontpil.py +++ b/Tests/test_imagefontpil.py @@ -2,6 +2,8 @@ import pytest from PIL import Image, ImageDraw, ImageFont, features +from .helper import assert_image_equal_tofile + pytestmark = pytest.mark.skipif( features.check_module("freetype2"), reason="PILfont superseded if FreeType is supported", @@ -22,6 +24,11 @@ def test_default_font(): assert_image_equal_tofile(im, "Tests/images/default_font.png") +def test_size_without_freetype(): + with pytest.raises(ImportError): + ImageFont.load_default(size=14) + + def test_unicode(): # should not segfault, should return UnicodeDecodeError # issue #2826 diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index 531ec8a17..7e69df8a7 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -855,7 +855,7 @@ def load_path(filename): raise OSError(msg) -def load_default(): +def load_default(size=None): """If FreeType support is available, load a version of Aileron Regular, https://dotcolon.net/font/aileron, with a more limited character set. @@ -865,7 +865,7 @@ def load_default(): :return: A font object. """ - if core.__class__.__name__ == "module": + if core.__class__.__name__ == "module" or size is not None: f = truetype( BytesIO( base64.b64decode( @@ -1093,6 +1093,7 @@ AAAAAAQAAAADa3tfFAAAAANAan9kAAAAA4QodoQ== """ ) ), + 10 if size is None else size, layout_engine=Layout.BASIC, ) else: