fix: the text wrapping position is not accurate #1876
Merged
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.
🤔 This is a ...
🔗 Related issue link
#1833
💡 Background and solution
Measuring text is an expensive operation, so G internally calculates the overall text width on a character-by-character basis and caches it when calculating line breaks. Due to the complexity of text rendering, this results in a larger result than measuring the entire text at once, resulting in less precise line break locations.
However, we cannot simply adjust the character-by-character strategy to measure the entire text, which will cause serious performance problems in scenarios with a long text.
On the other hand, we can combine the two strategies, use the character-by-character and cache strategies to calculate a rough line break position, and then use the measurement of the entire text near the threshold to get the precise result. Usually, the difference in the position calculated by the two different strategies is within 1-3 characters, so the performance consumption is acceptable, and more importantly, it brings better visual effects.
Before
After
📝 Changelog
☑️ Self Check before Merge