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
Fixed bugs in calculating text size #3864
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include a summary in PRs of what is changed and why. It makes them easier to review. Thanks!
@@ -630,7 +630,7 @@ font_getsize(FontObject* self, PyObject* args) | |||
|
|||
|
|||
for (x = i = 0; i < count; i++) { | |||
int index, error; | |||
int index, error, offset, x_advanced; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for moving these declarations before use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x_advanced
is new, not moved. I'm happy to move the declarations down if you like, I'm just going with the convention established in the code - I moved the offset
declaration up because it is no longer inside a conditional block.
With English characters, each subsequent character ends horizontally after all of the previous ones. Pillow has a variable From the issue, there are two characters - the backwards S at the bottom, and the line at the top. The backwards S ends horizontally after the line at the top - the horizontal clipping occurs because Pillow stops the size after the line at the top. So instead, check each character to see if it has the maximum x value. The first diagram at https://www.freetype.org/freetype2/docs/tutorial/step2.html is helpful in understanding the glyph properties. With regards to changing the vertical clipping, I presume that Pillow is not correctly processing the fact that the line at the top does not start at the baseline - there is a gap. Flipping the signs when applying the offset fixes this problem, with the only affect on existing tests being that a text string is moved vertically up. Let me know if anything is still unclear. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please resolve the merge conflicts and let's merge.
Resolves #3745