issue warning if Raqm layout is requested, but Raqm is not available

This commit is contained in:
nulano 2022-02-07 23:57:35 +00:00
parent f018518e24
commit a278e0aa65
No known key found for this signature in database
GPG Key ID: B650CDF63B705766
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