fix and add tests
(cherry picked from commit 0b711f10d0490863976699c051f2027b6799d501) (+1 squashed commits) Squashed commits: [9d4e6c17] fix tests
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 963 B After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 777 B After Width: | Height: | Size: 804 B |
Before Width: | Height: | Size: 605 B After Width: | Height: | Size: 720 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 810 B After Width: | Height: | Size: 800 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
|
@ -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")
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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],
|
||||
)
|
||||
|
||||
|
|