( ctx: CanvasRenderingContext2D, text: string, x: number, y: number, maxWidth: number, lineHeight: number )
| 70 | |
| 71 | // 绘制文字(自动换行) |
| 72 | function wrapText( |
| 73 | ctx: CanvasRenderingContext2D, |
| 74 | text: string, |
| 75 | x: number, |
| 76 | y: number, |
| 77 | maxWidth: number, |
| 78 | lineHeight: number |
| 79 | ): number { |
| 80 | const chars = text.split('') |
| 81 | let line = '' |
| 82 | let currentY = y |
| 83 | |
| 84 | for (let i = 0; i < chars.length; i++) { |
| 85 | const testLine = line + chars[i] |
| 86 | const metrics = ctx.measureText(testLine) |
| 87 | if (metrics.width > maxWidth && i > 0) { |
| 88 | ctx.fillText(line, x, currentY) |
| 89 | line = chars[i] |
| 90 | currentY += lineHeight |
| 91 | } else { |
| 92 | line = testLine |
| 93 | } |
| 94 | } |
| 95 | ctx.fillText(line, x, currentY) |
| 96 | return currentY + lineHeight |
| 97 | } |
| 98 | |
| 99 | // 绘制标签 |
| 100 | function drawTag(ctx: CanvasRenderingContext2D, text: string, x: number, y: number, bgColor: string, textColor: string) { |
no outgoing calls
no test coverage detected