Merge pull request #6035 from nulano/raqm-warn

This commit is contained in:
Hugo van Kemenade 2022-02-09 14:34:33 +02:00 committed by GitHub
commit 8b7c37dc0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -1022,3 +1022,16 @@ def test_oom(test_file):
font = ImageFont.truetype(BytesIO(f.read()))
with pytest.raises(Image.DecompressionBombError):
font.getmask("Test Text")
def test_raqm_missing_warning(monkeypatch):
monkeypatch.setattr(ImageFont.core, "HAVE_RAQM", False)
with pytest.warns(UserWarning) as record:
font = ImageFont.truetype(
FONT_PATH, FONT_SIZE, layout_engine=ImageFont.LAYOUT_RAQM
)
assert font.layout_engine == ImageFont.LAYOUT_BASIC
assert str(record[-1].message) == (
"Raqm layout was requested, but Raqm is not available. "
"Falling back to basic layout."
)

View File

@ -169,6 +169,12 @@ class FreeTypeFont:
if core.HAVE_RAQM:
layout_engine = LAYOUT_RAQM
elif layout_engine == LAYOUT_RAQM and not core.HAVE_RAQM:
import warnings
warnings.warn(
"Raqm layout was requested, but Raqm is not available. "
"Falling back to basic layout."
)
layout_engine = LAYOUT_BASIC
self.layout_engine = layout_engine