From 07897e36a658a6be4531397c52233f327d26b1e5 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Fri, 26 Apr 2024 00:48:11 -0400 Subject: [PATCH] Only tweet should chunk --- commands/edit-image-text/tweet.js | 2 +- util/Canvas.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/edit-image-text/tweet.js b/commands/edit-image-text/tweet.js index 5604dc37..10efc378 100644 --- a/commands/edit-image-text/tweet.js +++ b/commands/edit-image-text/tweet.js @@ -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); diff --git a/util/Canvas.js b/util/Canvas.js index 2fde65da..6c08de48 100644 --- a/util/Canvas.js +++ b/util/Canvas.js @@ -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++) {