This commit is contained in:
Dragon Fire
2024-04-21 18:07:24 -04:00
parent 7af6eeb5f2
commit 91dbe04387
+23 -25
View File
@@ -220,34 +220,32 @@ module.exports = class CanvasUtil {
for (let j = 0; j < words.length; j++) { for (let j = 0; j < words.length; j++) {
const word = words[j]; const word = words[j];
if (ctx.measureText(`${currentLine} ${word}`).width <= maxWidth) { if (ctx.measureText(`${currentLine} ${word}`).width <= maxWidth) {
currentLine += `${currentLine === '' ? '' : ' '} ${word}`; currentLine += `${currentLine === '' ? '' : ' '}${word}`;
} else { } else if (ctx.measureText(word).width > maxWidth) {
if (ctx.measureText(word).width > maxWidth) { const chunks = [];
const chunks = []; let currentChunk = '';
let currentChunk = ''; for (let k = 0; k < word.length; k++) {
for (let k = 0; k < word.length; k++) { const char = word[k];
const char = word[k]; if (ctx.measureText(`${currentChunk}${char}`).width <= maxWidth) {
if (ctx.measureText(`${currentChunk}${char}`).width <= maxWidth) { currentChunk += char;
currentChunk += char; } else {
} else {
chunks.push(currentChunk);
currentChunk = char;
}
}
if (currentChunk !== '') {
chunks.push(currentChunk); chunks.push(currentChunk);
currentChunk = char;
} }
for (let k = 0; k < chunks.length; k++) {
if (ctx.measureText(`${currentLine} ${chunks[k]}`).width > maxWidth) {
lines.push(currentLine.trim());
currentLine = '';
}
currentLine += `${currentLine === '' ? '' : ' '}${chunks[k]}`;
}
} else {
lines.push(currentLine.trim());
currentLine = word;
} }
if (currentChunk !== '') {
chunks.push(currentChunk);
}
for (let k = 0; k < chunks.length; k++) {
if (ctx.measureText(`${currentLine} ${chunks[k]}`).width > maxWidth) {
lines.push(currentLine.trim());
currentLine = '';
}
currentLine += `${currentLine === '' ? '' : ' '}${chunks[k]}`;
}
} else {
lines.push(currentLine.trim());
currentLine = word;
} }
} }
if (currentLine !== '') { if (currentLine !== '') {