-
Notifications
You must be signed in to change notification settings - Fork 490
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
Text rendering with word wrap and RTL often clips #664
Comments
This corrects the defect. Addition of 5 lines to Text.js:
Remove from Text.js
|
Additionally, it is possible for this defect to manifest for LTR languages as well. The final word-wrapped line will not end in a space (unless the original text has an extraneous space at the end) when words are split by spaces. The defective code assumes every line, including the final line, ends in a space. Thus if the final word wrapped line is the widest line, it could also be clipped by the width of a space. |
Thanks. So what's a text string I could reproduce this with? |
I'm checking with the copyright owners over that. I think if I provide you the raw text, font size and the word wrap width constraint you should be able to reproduce it. |
When the word wrapping routine splits text into words by spaces, each line's string (except possibly the last line) has a trailing space. Each line is then measured, and the width of a space is removed from the line length to account for that trailing space (necessary for accurate Center or Right alignment). For LTR languages, the trailing space for the widest line(s) are actually clipped off by the right side of the context's rectangle because of this. Since spaces are not visible, this is not an issue.
For a RTL language the trailing space is actually drawn on the left. Since text rendering is positioned by the left edge, the subtraction of the width of a space from the width of the line may result in the right side of the text clipped by the width of the space.
Fix: Instead of measuring lines of word wrapped split text with trailing space included, then subtracting the width of a space, simply trim the trailing space of each word wrapped line from the string.
The text was updated successfully, but these errors were encountered: