MCPcopy Create free account
hub / github.com/027xiguapi/code-box / textComputer

Function textComputer

utils/makerQRPost.ts:60–81  ·  view source on GitHub ↗
(
    text: string,
    style: string,
    width: number,
    ctx: CanvasRenderingContext2D
  )

Source from the content-addressed store, hash-verified

58
59 // 文本换行处理
60 const textComputer = (
61 text: string,
62 style: string,
63 width: number,
64 ctx: CanvasRenderingContext2D
65 ): string[] => {
66 if (text.replace(/\s/g, "").length === 0) {
67 return []
68 }
69 ctx.font = style
70 let temp = 0
71 const row: string[] = []
72 for (let i = 0; i <= text.length; i++) {
73 if (ctx.measureText(text.substring(temp, i)).width >= width) {
74 row.push(text.substring(temp, i - 1))
75 temp = i - 1
76 } else if (i === text.length) {
77 row.push(text.substring(temp, i))
78 }
79 }
80 return row
81 }
82
83 // 绘制文本
84 const textWriter = (

Callers 1

makerQRPostFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected