Use fractional coordinates when drawing text#6722
Merged
hugovk merged 3 commits intopython-pillow:mainfrom Nov 16, 2022
Merged
Conversation
Closed
hugovk
approved these changes
Nov 15, 2022
Member
hugovk
left a comment
There was a problem hiding this comment.
Shall we mention the new argument in the release notes?
Member
Author
|
Sure. You can see the release notes at https://pillow--6722.org.readthedocs.build/en/6722/releasenotes/9.4.0.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #3977
That issue attempts to draw two halves of a word separately, expecting them to occupy the same pixels as the complete word. The example given there is "par" and "adise" vs "paradise".
#4959 helped by adding
textlength, but did not resolve the issue completely. After switching totextlength, there was still a difference.The ImageDraw text operation essentially has two parts - it generates a
maskfrom the text characters with no awareness of the text position, and then pastes that mask onto the image at the relevant position. I had a thought - what if the position did matter, and text characters were rendered differently if they started halfway through a pixel?With this PR, I have added a
startargument togetmaskandgetmask2.produces "a", "d", "s" and "e" in the same location, but a different "i" for the first line compared to the second.
Changing ImageDraw's
textmethod to pass through the fractional coordinates of the text resolves the issue, allowing "par" and "adise" to fill the same pixels as "paradise".To try and future proof the API, I have set
startto be a tuple, so that both horizontal and vertical starting positions can be specified.