Only tweet should chunk

This commit is contained in:
Dragon Fire
2024-04-26 00:48:11 -04:00
parent d535822cbb
commit 07897e36a6
2 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -194,7 +194,7 @@ module.exports = class TweetCommand extends Command {
}
async fillTextWithEmoji(ctx, text, x, y, maxLineLen, emojiSize) {
const wrapped = wrapText(ctx, text, maxLineLen);
const wrapped = wrapText(ctx, text, maxLineLen, true);
const emoji = text.match(emojiRegex());
if (!emoji) {
ctx.fillText(wrapped.join('\n'), x, y);
+2 -2
View File
@@ -206,7 +206,7 @@ module.exports = class CanvasUtil {
return shorten ? `${text}...` : text;
}
static wrapText(ctx, text, maxWidth) {
static wrapText(ctx, text, maxWidth, shouldChunk = false) {
const lines = [];
const wordsAndBreaks = text.split('\n');
for (let i = 0; i < wordsAndBreaks.length; i++) {
@@ -221,7 +221,7 @@ 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) {
} else if (ctx.measureText(word).width > maxWidth && shouldChunk) {
const chunks = [];
let currentChunk = '';
for (let k = 0; k < word.length; k++) {