update test_font_pcf to use getbbox

This commit is contained in:
nulano 2022-05-25 18:23:37 +01:00
parent c854bf8d1c
commit f34a6460ef
No known key found for this signature in database
GPG Key ID: B650CDF63B705766
2 changed files with 12 additions and 4 deletions

View File

@ -68,12 +68,16 @@ def test_textsize(request, tmp_path):
tempname = save_font(request, tmp_path) tempname = save_font(request, tmp_path)
font = ImageFont.load(tempname) font = ImageFont.load(tempname)
for i in range(255): for i in range(255):
(dx, dy) = font.getsize(chr(i)) (ox, oy, dx, dy) = font.getbbox(chr(i))
assert ox == 0
assert oy == 0
assert dy == 20 assert dy == 20
assert dx in (0, 10) assert dx in (0, 10)
assert font.getlength(chr(i)) == dx
for i in range(len(message)): for i in range(len(message)):
msg = message[: i + 1] msg = message[: i + 1]
assert font.getsize(msg) == (len(msg) * 10, 20) assert font.getlength(msg) == len(msg) * 10
assert font.getbbox(msg) == (0, 0, len(msg) * 10, 20)
def _test_high_characters(request, tmp_path, message): def _test_high_characters(request, tmp_path, message):

View File

@ -101,13 +101,17 @@ def _test_textsize(request, tmp_path, encoding):
tempname = save_font(request, tmp_path, encoding) tempname = save_font(request, tmp_path, encoding)
font = ImageFont.load(tempname) font = ImageFont.load(tempname)
for i in range(255): for i in range(255):
(dx, dy) = font.getsize(bytearray([i])) (ox, oy, dx, dy) = font.getbbox(bytearray([i]))
assert ox == 0
assert oy == 0
assert dy == 20 assert dy == 20
assert dx in (0, 10) assert dx in (0, 10)
assert font.getlength(bytearray([i])) == dx
message = charsets[encoding]["message"].encode(encoding) message = charsets[encoding]["message"].encode(encoding)
for i in range(len(message)): for i in range(len(message)):
msg = message[: i + 1] msg = message[: i + 1]
assert font.getsize(msg) == (len(msg) * 10, 20) assert font.getlength(msg) == len(msg) * 10
assert font.getbbox(msg) == (0, 0, len(msg) * 10, 20)
def test_textsize_iso8859_1(request, tmp_path): def test_textsize_iso8859_1(request, tmp_path):