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

Fixed bugs in calculating text size #3864

Merged
merged 2 commits into from Jun 19, 2019
Merged

Conversation

radarhere
Copy link
Member

Resolves #3745

Copy link
Member

@hugovk hugovk left a 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;
Copy link
Member

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?

Copy link
Member Author

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.

@radarhere
Copy link
Member Author

With English characters, each subsequent character ends horizontally after all of the previous ones. Pillow has a variable x, and it moves it forward with each character. Pillow presumes the last x is the maximum x value.

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.

Copy link
Member

@hugovk hugovk left a 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.

@hugovk hugovk merged commit 26182dd into python-pillow:master Jun 19, 2019
@radarhere radarhere deleted the size branch June 19, 2019 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Text clipping arabic fonts
2 participants