-
Notifications
You must be signed in to change notification settings - Fork 208
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
fix: abnormal word breaking in text #1896
Conversation
WalkthroughThis pull request addresses a bug related to abnormal word breaking in text rendering. The fix involves changing the word break judgment to real-time measurement to obtain line width, utilizing the existing cache to avoid performance degradation. Changes
|
) { | ||
return text.split('').reduce((sum: number, c) => { | ||
if (!cache[c]) throw Error('cannot count the word without cache'); | ||
return sum + cache[c]; | ||
return sum + calcWidthWithCache(c); |
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.
The previous implementation threw an error when a character's width was not found in the cache. The new implementation calculates the width in real-time, which resolves the issue of missing cache entries and prevents exceptions.
有相关 issue 吗? |
DI S2 那边反馈的,没有提 issue,测试过程中发现的 |
也可以留一个 issue,有一些脱敏的截图之类,方便知道解决了什么问题。 GitHub 中有两个工具,一个是 issue,是明确有问题的 todo 事项,一个是 discussion,用于讨论、交流、答疑。只不过我们一般把 issue 用作答疑了。 |
@@ -588,11 +588,10 @@ export class TextService { | |||
|
|||
private sumTextWidthByCache( | |||
text: string, | |||
cache: { [key in string]: number }, | |||
calcWidthWithCache: (txt: string) => number, |
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.
这个会改变缓存命中率,导致部分场景性能降低吗?
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.
性能应该不会有明显的影响,只是在文本换行阈值附近 1-5 个字符不会命中缓存的差异
* fix: abnormal word breaking in text (#1896) * Version Packages (#1898) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
🤔 This is a ...
🔗 Related issue link
fixed #1897
💡 Background and solution
When processing text line breaks, in the initial implementation of measuring text width character by character, the line width will be directly obtained from the cache when encountering a word break, because each character is already in the cache; in the improved line break strategy, the width of the entire line of text will be measured near the line break threshold to determine the final more accurate line break character position, which means that the width of each single character may not be in the cache, which causes the exception to be thrown
This can be done by changing the word break judgment of the text to real-time measurement to obtain the line width. (This will not cause a serious performance reduction, because we use the existing cache)
📝 Changelog
☑️ Self Check before Merge