mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-05 12:23:18 +03:00
Do not justify last line
This commit is contained in:
parent
cccc07269a
commit
b955cee725
BIN
Tests/images/multiline_text_justify_last_line.png
Normal file
BIN
Tests/images/multiline_text_justify_last_line.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.4 KiB |
|
@ -267,16 +267,19 @@ def test_render_multiline_text_align(
|
||||||
assert_image_similar_tofile(im, f"Tests/images/multiline_text{ext}.png", 0.01)
|
assert_image_similar_tofile(im, f"Tests/images/multiline_text{ext}.png", 0.01)
|
||||||
|
|
||||||
|
|
||||||
def test_render_multiline_text_align_justify_single_word(
|
def test_render_multiline_text_align_justify_last_line(
|
||||||
font: ImageFont.FreeTypeFont,
|
font: ImageFont.FreeTypeFont,
|
||||||
) -> None:
|
) -> None:
|
||||||
im = Image.new("RGB", (185, 65))
|
im = Image.new("RGB", (280, 60))
|
||||||
draw = ImageDraw.Draw(im)
|
draw = ImageDraw.Draw(im)
|
||||||
draw.multiline_text(
|
draw.multiline_text(
|
||||||
(0, 0), "hey you\nyou are awesome\nthis", font=font, align="justify"
|
(0, 0),
|
||||||
|
"hey you you are awesome\nthis\nlooks awkward",
|
||||||
|
font=font,
|
||||||
|
align="justify",
|
||||||
)
|
)
|
||||||
|
|
||||||
assert_image_equal_tofile(im, "Tests/images/multiline_text_justify_single_word.png")
|
assert_image_equal_tofile(im, "Tests/images/multiline_text_justify_last_line.png")
|
||||||
|
|
||||||
|
|
||||||
def test_unknown_align(font: ImageFont.FreeTypeFont) -> None:
|
def test_unknown_align(font: ImageFont.FreeTypeFont) -> None:
|
||||||
|
|
|
@ -770,7 +770,7 @@ class ImageDraw:
|
||||||
msg = 'align must be "left", "center", "right" or "justify"'
|
msg = 'align must be "left", "center", "right" or "justify"'
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
if align == "justify" and width_difference != 0:
|
if align == "justify" and width_difference != 0 and idx != len(lines) - 1:
|
||||||
words = line.split(" " if isinstance(text, str) else b" ")
|
words = line.split(" " if isinstance(text, str) else b" ")
|
||||||
if len(words) > 1:
|
if len(words) > 1:
|
||||||
word_widths = [
|
word_widths = [
|
||||||
|
|
Loading…
Reference in New Issue
Block a user