mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Fix
This commit is contained in:
+20
-25
@@ -221,35 +221,30 @@ module.exports = class CanvasUtil {
|
|||||||
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 if (ctx.measureText(word).width > maxWidth) {
|
} else if (ctx.measureText(word).width > maxWidth && shouldChunk) {
|
||||||
if (shouldChunk) {
|
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 {
|
}
|
||||||
if (currentLine !== '') lines.push(currentLine.trim());
|
if (currentChunk !== '') {
|
||||||
currentLine = word;
|
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 {
|
} else {
|
||||||
lines.push(currentLine.trim());
|
if (currentLine !== '') lines.push(currentLine.trim());
|
||||||
currentLine = word;
|
currentLine = word;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user