day36
OGPを1種類作成した。なんかこんな感じで長さ計りつつcanvasでの文字の折返しに対応した。もっといい方法あるんだろうか。
const lines: string[] = []
let line = ''
for (let i = 0; i < str.length; i++) {
line += str.substr(i, 1)
const metrix = ctx.measureText(line)
if (metrix.width > width) {
lines.push(line.substr(0, line.length - 1))
line = line.substr(line.length - 1, 1)
}
}
if (line.length > 0) {
lines.push(line)
}
return lines