MCPcopy Create free account
hub / github.com/TurtleTrace2026/TurtleTrace / wrapText

Function wrapText

src/utils/shareUtils.ts:72–97  ·  view source on GitHub ↗
(
  ctx: CanvasRenderingContext2D,
  text: string,
  x: number,
  y: number,
  maxWidth: number,
  lineHeight: number
)

Source from the content-addressed store, hash-verified

70
71// 绘制文字(自动换行)
72function 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// 绘制标签
100function drawTag(ctx: CanvasRenderingContext2D, text: string, x: number, y: number, bgColor: string, textColor: string) {

Callers 1

generateShareImageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected