diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index 0d423aab7..3dcbf18d2 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -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." + ) diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index 805c8fff9..58bf46a32 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -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