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

JS:canvas动态获取绘制文字的宽度 CanvasRenderingContext2D.measureText() #84

Open
smileyby opened this issue May 25, 2021 · 0 comments
Labels

Comments

@smileyby
Copy link
Owner

场景:项目海报生成的同一行文字,字体大小不同,根据设计稿给定位置绘制后会发生重叠
需要检测前一串文字的长度,动态计算后面文字的位置
方案:CanvasRenderingContext2D.measureText() 这个方法完美解决,而且兼容性还棒棒哒
参考:https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/measureText

@smileyby smileyby added the JavaScript ☀️ JavaScript label May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant