add tests for multiline text with anchor

This commit is contained in:
nulano 2020-06-20 12:54:53 +02:00
parent a9b8dcba7d
commit 0838d8ea62
12 changed files with 42 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

View File

@ -40,18 +40,21 @@ class TestImageFont:
"textsize": 12, "textsize": 12,
"getters": (13, 16), "getters": (13, 16),
"mask": (107, 13), "mask": (107, 13),
"multiline-anchor": 6,
}, },
(">=2.7",): { (">=2.7",): {
"multiline": 6.2, "multiline": 6.2,
"textsize": 2.5, "textsize": 2.5,
"getters": (12, 16), "getters": (12, 16),
"mask": (108, 13), "mask": (108, 13),
"multiline-anchor": 4,
}, },
"Default": { "Default": {
"multiline": 0.5, "multiline": 0.5,
"textsize": 0.5, "textsize": 0.5,
"getters": (12, 16), "getters": (12, 16),
"mask": (108, 13), "mask": (108, 13),
"multiline-anchor": 4,
}, },
} }
@ -781,6 +784,45 @@ class TestImageFont:
with Image.open(path) as expected: with Image.open(path) as expected:
assert_image_similar(im, expected, 7) assert_image_similar(im, expected, 7)
@pytest.mark.parametrize(
"anchor,align",
(
# test horizontal anchors
("lm", "left"),
("lm", "center"),
("lm", "right"),
("mm", "left"),
("mm", "center"),
("mm", "right"),
("rm", "left"),
("rm", "center"),
("rm", "right"),
# test vertical anchors
("ma", "center"),
# ("mm", "center"), # duplicate
("md", "center"),
),
)
def test_anchor_multiline(self, anchor, align):
target = "Tests/images/test_anchor_multiline_%s_%s.png" % (anchor, align)
text = "a\nlong\ntext sample"
f = ImageFont.truetype(
"Tests/fonts/NotoSans-Regular.ttf", 48, layout_engine=self.LAYOUT_ENGINE
)
# test render
im = Image.new("RGB", (600, 400), "white")
d = ImageDraw.Draw(im)
d.line(((0, 200), (600, 200)), "gray")
d.line(((300, 0), (300, 400)), "gray")
d.multiline_text(
(300, 200), text, fill="black", anchor=anchor, font=f, align=align
)
with Image.open(target) as expected:
assert_image_similar(im, expected, self.metrics["multiline-anchor"])
def test_anchor_invalid(self): def test_anchor_invalid(self):
font = self.get_font() font = self.get_font()
im = Image.new("RGB", (100, 100), "white") im = Image.new("RGB", (100, 100), "white")