mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Restored charsets dictionary
This commit is contained in:
parent
a09e056a4c
commit
2521ec4732
|
@ -15,22 +15,22 @@ from .helper import (
|
||||||
|
|
||||||
fontname = "Tests/fonts/ter-x20b.pcf"
|
fontname = "Tests/fonts/ter-x20b.pcf"
|
||||||
|
|
||||||
charsets: dict[str, tuple[int, str, str]] = {
|
charsets: dict[str, dict[str, int | str]] = {
|
||||||
"iso8859-1": (
|
"iso8859-1": {
|
||||||
223,
|
"glyph_count": 223,
|
||||||
"hello, world",
|
"message": "hello, world",
|
||||||
"Tests/images/test_draw_pbm_ter_en_target.png",
|
"image1": "Tests/images/test_draw_pbm_ter_en_target.png",
|
||||||
),
|
},
|
||||||
"iso8859-2": (
|
"iso8859-2": {
|
||||||
223,
|
"glyph_count": 223,
|
||||||
"witaj świecie",
|
"message": "witaj świecie",
|
||||||
"Tests/images/test_draw_pbm_ter_pl_target.png",
|
"image1": "Tests/images/test_draw_pbm_ter_pl_target.png",
|
||||||
),
|
},
|
||||||
"cp1250": (
|
"cp1250": {
|
||||||
250,
|
"glyph_count": 250,
|
||||||
"witaj świecie",
|
"message": "witaj świecie",
|
||||||
"Tests/images/test_draw_pbm_ter_pl_target.png",
|
"image1": "Tests/images/test_draw_pbm_ter_pl_target.png",
|
||||||
),
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ def save_font(
|
||||||
font = PcfFontFile.PcfFontFile(test_file, encoding)
|
font = PcfFontFile.PcfFontFile(test_file, encoding)
|
||||||
assert isinstance(font, FontFile.FontFile)
|
assert isinstance(font, FontFile.FontFile)
|
||||||
# check the number of characters in the font
|
# check the number of characters in the font
|
||||||
assert len([_f for _f in font.glyph if _f]) == charsets[encoding][0]
|
assert len([_f for _f in font.glyph if _f]) == charsets[encoding]["glyph_count"]
|
||||||
|
|
||||||
tempname = str(tmp_path / "temp.pil")
|
tempname = str(tmp_path / "temp.pil")
|
||||||
|
|
||||||
|
@ -81,9 +81,14 @@ def test_draw(
|
||||||
font = ImageFont.load(tempname)
|
font = ImageFont.load(tempname)
|
||||||
im = Image.new("L", (150, 30), "white")
|
im = Image.new("L", (150, 30), "white")
|
||||||
draw = ImageDraw.Draw(im)
|
draw = ImageDraw.Draw(im)
|
||||||
message = charsets[encoding][1].encode(encoding)
|
|
||||||
draw.text((0, 0), message, "black", font=font)
|
message = charsets[encoding]["message"]
|
||||||
assert_image_similar_tofile(im, charsets[encoding][2], 0)
|
assert isinstance(message, str)
|
||||||
|
draw.text((0, 0), message.encode(encoding), "black", font=font)
|
||||||
|
|
||||||
|
expected_path = charsets[encoding]["image1"]
|
||||||
|
assert isinstance(expected_path, str)
|
||||||
|
assert_image_similar_tofile(im, expected_path, 0)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("encoding", ("iso8859-1", "iso8859-2", "cp1250"))
|
@pytest.mark.parametrize("encoding", ("iso8859-1", "iso8859-2", "cp1250"))
|
||||||
|
@ -99,8 +104,10 @@ def test_textsize(
|
||||||
assert dy == 20
|
assert dy == 20
|
||||||
assert dx in (0, 10)
|
assert dx in (0, 10)
|
||||||
assert font.getlength(bytearray([i])) == dx
|
assert font.getlength(bytearray([i])) == dx
|
||||||
message = charsets[encoding][1].encode(encoding)
|
message = charsets[encoding]["message"]
|
||||||
for i in range(len(message)):
|
assert isinstance(message, str)
|
||||||
msg = message[: i + 1]
|
message_bytes = message.encode(encoding)
|
||||||
|
for i in range(len(message_bytes)):
|
||||||
|
msg = message_bytes[: i + 1]
|
||||||
assert font.getlength(msg) == len(msg) * 10
|
assert font.getlength(msg) == len(msg) * 10
|
||||||
assert font.getbbox(msg) == (0, 0, len(msg) * 10, 20)
|
assert font.getbbox(msg) == (0, 0, len(msg) * 10, 20)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user