fix and add tests

(cherry picked from commit 0b711f10d0490863976699c051f2027b6799d501) (+1 squashed commits)

Squashed commits:

[9d4e6c17] fix tests
This commit is contained in:
nulano 2020-09-01 23:29:06 +02:00
parent ea582a19e3
commit 54e067779b
16 changed files with 11 additions and 9 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 963 B

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 777 B

After

Width:  |  Height:  |  Size: 804 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 605 B

After

Width:  |  Height:  |  Size: 720 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 810 B

After

Width:  |  Height:  |  Size: 800 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -1039,7 +1039,7 @@ def test_stroke_descender():
draw.text((10, 0), "y", "#f00", font, stroke_width=2, stroke_fill="#0f0")
# Assert
assert_image_similar_tofile(im, "Tests/images/imagedraw_stroke_descender.png", 6.76)
assert_image_similar_tofile(im, "Tests/images/imagedraw_stroke_descender.png", 6.78)
@skip_unless_feature("freetype2")

View File

@ -343,7 +343,7 @@ class TestImageFont:
mask = transposed_font.getmask(text)
# Assert
assert mask.size == (13, 108)
assert mask.size in ((13, 107), (13, 108))
def test_unrotated_transposed_font_get_mask(self):
# Arrange
@ -356,7 +356,7 @@ class TestImageFont:
mask = transposed_font.getmask(text)
# Assert
assert mask.size == (108, 13)
assert mask.size in ((107, 13), (108, 13))
def test_free_type_font_get_name(self):
# Arrange
@ -400,7 +400,7 @@ class TestImageFont:
mask = font.getmask(text)
# Assert
assert mask.size == (108, 13)
assert mask.size in ((107, 13), (108, 13))
def test_load_path_not_found(self):
# Arrange
@ -471,7 +471,8 @@ class TestImageFont:
d = ImageDraw.Draw(img)
d.text((10, 10), text, font=ttf)
assert_image_similar_tofile(img, target, self.metrics["multiline"])
# fails with 14.7
assert_image_similar_tofile(img, target, 6.2)
def _test_fake_loading_font(self, monkeypatch, path_to_fake, fontname):
# Make a copy of FreeTypeFont so we can patch the original
@ -703,10 +704,10 @@ class TestImageFont:
font.set_variation_by_name("Bold")
font = ImageFont.truetype("Tests/fonts/AdobeVFPrototype.ttf", 36)
self._check_text(font, "Tests/images/variation_adobe.png", 11)
self._check_text(font, "Tests/images/variation_adobe.png", 11.2)
for name in ["Bold", b"Bold"]:
font.set_variation_by_name(name)
self._check_text(font, "Tests/images/variation_adobe_name.png", 11)
self._check_text(font, "Tests/images/variation_adobe_name.png", 11.3)
font = ImageFont.truetype("Tests/fonts/TINY5x3GX.ttf", 36)
self._check_text(font, "Tests/images/variation_tiny.png", 40)
@ -728,7 +729,7 @@ class TestImageFont:
font = ImageFont.truetype("Tests/fonts/AdobeVFPrototype.ttf", 36)
font.set_variation_by_axes([500, 50])
self._check_text(font, "Tests/images/variation_adobe_axes.png", 5.1)
self._check_text(font, "Tests/images/variation_adobe_axes.png", 5.8)
font = ImageFont.truetype("Tests/fonts/TINY5x3GX.ttf", 36)
font.set_variation_by_axes([100])

View File

@ -259,9 +259,10 @@ class FreeTypeFont:
:return: (width, height)
"""
# vertical offset is added for historical reasons, see discussion in #4789
size, offset = self.font.getsize(text, False, direction, features, language)
return (
size[0] + stroke_width * 2 + offset[0],
size[0] + stroke_width * 2,
size[1] + stroke_width * 2 + offset[1],
)