Preserve line spacing backwards compatibility

This commit is contained in:
Andrew Murray 2023-04-10 18:47:58 +10:00
parent fa6cd4a195
commit bc0bf5efea
3 changed files with 7 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -1220,8 +1220,8 @@ def test_textbbox_stroke():
# Act / Assert
assert draw.textbbox((2, 2), "A", font, stroke_width=2) == (0, 4, 16, 20)
assert draw.textbbox((2, 2), "A", font, stroke_width=4) == (-2, 2, 18, 22)
assert draw.textbbox((2, 2), "ABC\nAaaa", font, stroke_width=2) == (0, 4, 52, 42)
assert draw.textbbox((2, 2), "ABC\nAaaa", font, stroke_width=4) == (-2, 2, 54, 46)
assert draw.textbbox((2, 2), "ABC\nAaaa", font, stroke_width=2) == (0, 4, 52, 44)
assert draw.textbbox((2, 2), "ABC\nAaaa", font, stroke_width=4) == (-2, 2, 54, 50)
@skip_unless_feature("freetype2")

View File

@ -431,7 +431,11 @@ class ImageDraw:
return text.split(split_character)
def _multiline_spacing(self, font, spacing, stroke_width):
return self.textbbox((0, 0), "A", font, stroke_width=stroke_width)[3] + spacing
return (
self.textbbox((0, 0), "A", font, stroke_width=stroke_width)[3]
+ stroke_width
+ spacing
)
def text(
self,