Raise ValueError when trying to save without bitmap

This commit is contained in:
Andrew Murray 2023-12-27 12:32:35 +11:00
parent 85818cd616
commit 6e97dd5cec
2 changed files with 15 additions and 0 deletions

12
Tests/test_fontfile.py Normal file
View File

@ -0,0 +1,12 @@
from __future__ import annotations
import pytest
from PIL import FontFile
def test_save(tmp_path):
tempname = str(tmp_path / "temp.pil")
font = FontFile.FontFile()
with pytest.raises(ValueError):
font.save(tempname)

View File

@ -118,6 +118,9 @@ class FontFile:
self.compile()
# font data
if not self.bitmap:
msg = "No bitmap created"
raise ValueError(msg)
self.bitmap.save(os.path.splitext(filename)[0] + ".pbm", "PNG")
# font metrics