|
|
@ -359,7 +359,8 @@ export const wrapText = (text: string, font: FontString, maxWidth: number) => {
|
|
|
|
// This means its newline so push it
|
|
|
|
// This means its newline so push it
|
|
|
|
if (words.length === 1 && words[0] === "") {
|
|
|
|
if (words.length === 1 && words[0] === "") {
|
|
|
|
lines.push(words[0]);
|
|
|
|
lines.push(words[0]);
|
|
|
|
} else {
|
|
|
|
return; // continue
|
|
|
|
|
|
|
|
}
|
|
|
|
let currentLine = "";
|
|
|
|
let currentLine = "";
|
|
|
|
let currentLineWidthTillNow = 0;
|
|
|
|
let currentLineWidthTillNow = 0;
|
|
|
|
|
|
|
|
|
|
|
@ -375,10 +376,12 @@ export const wrapText = (text: string, font: FontString, maxWidth: number) => {
|
|
|
|
currentLine = "";
|
|
|
|
currentLine = "";
|
|
|
|
currentLineWidthTillNow = 0;
|
|
|
|
currentLineWidthTillNow = 0;
|
|
|
|
while (words[index].length > 0) {
|
|
|
|
while (words[index].length > 0) {
|
|
|
|
const currentChar = words[index][0];
|
|
|
|
const currentChar = String.fromCodePoint(
|
|
|
|
|
|
|
|
words[index].codePointAt(0)!,
|
|
|
|
|
|
|
|
);
|
|
|
|
const width = charWidth.calculate(currentChar, font);
|
|
|
|
const width = charWidth.calculate(currentChar, font);
|
|
|
|
currentLineWidthTillNow += width;
|
|
|
|
currentLineWidthTillNow += width;
|
|
|
|
words[index] = words[index].slice(1);
|
|
|
|
words[index] = words[index].slice(currentChar.length);
|
|
|
|
|
|
|
|
|
|
|
|
if (currentLineWidthTillNow >= maxWidth) {
|
|
|
|
if (currentLineWidthTillNow >= maxWidth) {
|
|
|
|
// only remove last trailing space which we have added when joining words
|
|
|
|
// only remove last trailing space which we have added when joining words
|
|
|
@ -388,10 +391,6 @@ export const wrapText = (text: string, font: FontString, maxWidth: number) => {
|
|
|
|
push(currentLine);
|
|
|
|
push(currentLine);
|
|
|
|
currentLine = currentChar;
|
|
|
|
currentLine = currentChar;
|
|
|
|
currentLineWidthTillNow = width;
|
|
|
|
currentLineWidthTillNow = width;
|
|
|
|
if (currentLineWidthTillNow === maxWidth) {
|
|
|
|
|
|
|
|
currentLine = "";
|
|
|
|
|
|
|
|
currentLineWidthTillNow = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
currentLine += currentChar;
|
|
|
|
currentLine += currentChar;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -448,7 +447,6 @@ export const wrapText = (text: string, font: FontString, maxWidth: number) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
push(currentLine);
|
|
|
|
push(currentLine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return lines.join("\n");
|
|
|
|
return lines.join("\n");
|
|
|
|
};
|
|
|
|
};
|
|
|
|