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];
|
||||
if (ctx.measureText(`${currentLine} ${word}`).width <= maxWidth) {
|
||||
currentLine += `${currentLine === '' ? '' : ' '}${word}`;
|
||||
} else if (ctx.measureText(word).width > maxWidth) {
|
||||
if (shouldChunk) {
|
||||
const chunks = [];
|
||||
let currentChunk = '';
|
||||
for (let k = 0; k < word.length; k++) {
|
||||
const char = word[k];
|
||||
if (ctx.measureText(`${currentChunk}${char}`).width <= maxWidth) {
|
||||
currentChunk += char;
|
||||
} else {
|
||||
chunks.push(currentChunk);
|
||||
currentChunk = char;
|
||||
}
|
||||
}
|
||||
if (currentChunk !== '') {
|
||||
} else if (ctx.measureText(word).width > maxWidth && shouldChunk) {
|
||||
const chunks = [];
|
||||
let currentChunk = '';
|
||||
for (let k = 0; k < word.length; k++) {
|
||||
const char = word[k];
|
||||
if (ctx.measureText(`${currentChunk}${char}`).width <= maxWidth) {
|
||||
currentChunk += char;
|
||||
} else {
|
||||
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]}`;
|
||||
currentChunk = char;
|
||||
}
|
||||
} else {
|
||||
if (currentLine !== '') 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());
|
||||
if (currentLine !== '') lines.push(currentLine.trim());
|
||||
currentLine = word;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user