mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-03 13:14:27 +03:00
simplify code, make test more generic
This commit is contained in:
parent
fc3930cc4c
commit
18bd77bbc0
Binary file not shown.
Before Width: | Height: | Size: 2.9 KiB |
BIN
Tests/images/text_float_coord.png
Normal file
BIN
Tests/images/text_float_coord.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
BIN
Tests/images/text_float_coord_1_alt.png
Normal file
BIN
Tests/images/text_float_coord_1_alt.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 807 B |
|
@ -958,22 +958,29 @@ class TestImageFont:
|
|||
d = ImageDraw.Draw(im)
|
||||
d.text((10, 10), txt, font=ttf, fill="#fa6", embedded_color=True)
|
||||
|
||||
assert_image_similar_tofile(im, "Tests/images/standard_embedded.png", 6.2)
|
||||
assert_image_similar_tofile(im, "Tests/images/standard_embedded.png", 3.1)
|
||||
|
||||
def test_multiline_centered_embedded_color(self):
|
||||
txt = "Hello\nWorld!"
|
||||
@pytest.mark.parametrize("fontmode", ("1", "L", "RGBA"))
|
||||
def test_float_coord(self, fontmode):
|
||||
txt = "Hello World!"
|
||||
ttf = ImageFont.truetype(FONT_PATH, 40, layout_engine=self.LAYOUT_ENGINE)
|
||||
ttf.getbbox(txt)
|
||||
|
||||
im = Image.new("RGB", (160, 96), "white")
|
||||
im = Image.new("RGB", (300, 64), "white")
|
||||
d = ImageDraw.Draw(im)
|
||||
d.multiline_text(
|
||||
(10, 10), txt, font=ttf, fill="#fa6", align="center", embedded_color=True
|
||||
)
|
||||
if fontmode == "1":
|
||||
d.fontmode = "1"
|
||||
|
||||
assert_image_similar_tofile(
|
||||
im, "Tests/images/standard_embedded_multiline_centered.png", 6.2
|
||||
)
|
||||
embedded_color = fontmode == "RGBA"
|
||||
d.text((9.5, 9.5), txt, font=ttf, fill="#fa6", embedded_color=embedded_color)
|
||||
try:
|
||||
assert_image_similar_tofile(im, "Tests/images/text_float_coord.png", 3.9)
|
||||
except AssertionError:
|
||||
if fontmode == "1" and self.LAYOUT_ENGINE == ImageFont.Layout.BASIC:
|
||||
assert_image_similar_tofile(
|
||||
im, "Tests/images/text_float_coord_1_alt.png", 1
|
||||
)
|
||||
else:
|
||||
raise
|
||||
|
||||
def test_cbdt(self):
|
||||
try:
|
||||
|
|
|
@ -482,9 +482,8 @@ class ImageDraw:
|
|||
# extract mask and set text alpha
|
||||
color, mask = mask, mask.getband(3)
|
||||
color.fillband(3, (ink >> 24) & 0xFF)
|
||||
coord = tuple(int(c) for c in coord)
|
||||
coord2 = coord[0] + mask.size[0], coord[1] + mask.size[1]
|
||||
self.im.paste(color, coord + coord2, mask)
|
||||
x, y = (int(c) for c in coord)
|
||||
self.im.paste(color, (x, y, x + mask.size[0], y + mask.size[1]), mask)
|
||||
else:
|
||||
self.draw.draw_bitmap(coord, mask, ink)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user