-
Notifications
You must be signed in to change notification settings - Fork 199
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: 使用离屏 Canvas 测量文本, 提高宽度计算的准确性 close #3018 #3053
base: next
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
你好 @lijinke666,非常感谢你的贡献. Hello, @lijinke666, Thanks for your contribution. In order to make the code more robust, please add the corresponding unit tests, and update the docs if there are API changes. |
Walkthrough此 PR 解决了使用 Changes
|
@@ -784,7 +784,7 @@ export abstract class SpreadSheet extends EE { | |||
return null; | |||
} | |||
|
|||
const ctx = this.getCanvasElement()?.getContext('2d')!; | |||
const ctx = getOffscreenCanvas()?.getContext('2d')!; |
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.
使用 getOffscreenCanvas
获取上下文可能会导致在某些情况下无法正确获取 Canvas 上下文。建议确保 getOffscreenCanvas
返回的对象始终存在并且是有效的 Canvas 元素。
Size Change: +4 B (0%) Total Size: 619 kB
ℹ️ View Unchanged
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## next #3053 +/- ##
==========================================
Coverage 75.77% 75.77%
==========================================
Files 257 51 -206
Lines 11994 1490 -10504
Branches 2464 284 -2180
==========================================
- Hits 9088 1129 -7959
+ Misses 1398 210 -1188
+ Partials 1508 151 -1357 ☔ View full report in Codecov by Sentry. |
👀 PR includes
🐛 Bugfix
📝 Description
G
的Canvas
, 由于 context 会被污染, 从而导致measureText
的值不准, 需要使用有一个干净 ctx 的离屏 Canvas开启
textWrap
的文本, 由于是逐字计算, 会导致单行文本是否展示省略号不太准确, 尤其是纯数字, 如:11111111
背景见: antvis/G#1876
🖼️ Screenshot
🔗 Related issue link
🔍 Self-Check before the merge