Skip to content

Commit

Permalink
fix: 超出文本
Browse files Browse the repository at this point in the history
  • Loading branch information
XasYer committed Jan 11, 2025
1 parent b914e02 commit 66d63b4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion models/canvas/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export function toImage (canvas) {
*/
export function shortenText (ctx, text, maxWidth, replace = '...') {
if (!text) return ''
maxWidth -= ctx.measureText(replace).width
if (ctx.measureText(text).width < maxWidth) return text
maxWidth -= ctx.measureText(replace).width
while (ctx.measureText(text).width > maxWidth) {
text = text.slice(0, -1)
}
Expand Down

0 comments on commit 66d63b4

Please sign in to comment.