Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiline text drawing and height calculation #5751

Closed
wants to merge 2 commits into from

Conversation

FeeeeK
Copy link

@FeeeeK FeeeeK commented Oct 9, 2021

Fixes #1646 .

Changes proposed in this pull request:

  • Fixed size calculation and drawing of multiline text

Example

from PIL import Image, ImageDraw, ImageFont

font = ImageFont.truetype("tnr.ttf", size=80, encoding="unic")
text = "{{{{\n}}}}"

size = font.getsize_multiline(text)
print(size) # (152, 132) / (152, 168)
image = Image.new("RGB", size, color="#FFF")
draw = ImageDraw.Draw(image)
draw.multiline_text((0, 0), text, "#000", font)
image.save("a.png")

Then / Now

a a

@FeeeeK
Copy link
Author

FeeeeK commented Oct 9, 2021

Most tests fail because they are not designed to account for these changes, for example before the height of the blank line was equal to the height of A string, although font.getsize() returns (0, 0).
Most of the test images need to be changed to fix this.

@nulano
Copy link
Contributor

nulano commented Oct 9, 2021

So your proposal is to revert #1573? This will reintroduce the #1540 issue.

@FeeeeK
Copy link
Author

FeeeeK commented Oct 9, 2021

Haven't seen this before. In this case, I don't know what can be done.

@FeeeeK FeeeeK closed this Oct 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiline text line height not being calculated correctly
2 participants