From a1cb26c596f9c9384f852ec1fda41f4c5d5c5633 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Fri, 3 May 2024 10:49:28 -0400 Subject: [PATCH] Fix --- commands/edit-image-text/spongebob-time-card.js | 1 + commands/edit-image-text/tweet.js | 4 ++-- util/Canvas.js | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/commands/edit-image-text/spongebob-time-card.js b/commands/edit-image-text/spongebob-time-card.js index 3ff52ba2..88d6a50e 100644 --- a/commands/edit-image-text/spongebob-time-card.js +++ b/commands/edit-image-text/spongebob-time-card.js @@ -76,6 +76,7 @@ module.exports = class SpongebobTimeCardCommand extends Command { fontSize -= 10; ctx.font = this.client.fonts.get('Spongeboytt1.ttf').toCanvasString(fontSize); metrics = ctx.measureText(lines.join('\n')); + heightMetric = measureTextHeightWithBreaks(ctx, lines.join('\n')); lines = wrapText(ctx, text.toUpperCase(), 1800); } const topMost = (canvas.height / 2) - (((fontSize * lines.length) / 2) + ((60 * (lines.length - 1)) / 2)); diff --git a/commands/edit-image-text/tweet.js b/commands/edit-image-text/tweet.js index 9262427d..d6cc25ac 100644 --- a/commands/edit-image-text/tweet.js +++ b/commands/edit-image-text/tweet.js @@ -68,7 +68,7 @@ module.exports = class TweetCommand extends Command { const ctx = canvas.getContext('2d'); ctx.font = this.client.fonts.get('ChirpRegular.ttf').toCanvasString(23); const lines = wrapText(ctx, text, 710, true); - const metrics = measureTextHeightWithBreaks(ctx, lines.join('\n'), true); + const metrics = measureTextHeightWithBreaks(ctx, lines.join('\n')); const linesLen = metrics + 15; canvas.height += linesLen; let imageHeight = 0; @@ -224,7 +224,7 @@ module.exports = class TweetCommand extends Command { const wrapped = wrapText(ctx, text, maxLineLen, true); const emoji = text.match(emojiRegex()); if (!emoji) { - fillTextWithBreaks(ctx, wrapped.join('\n'), x, y, true); + fillTextWithBreaks(ctx, wrapped.join('\n'), x, y); this.fillHashtags(ctx, wrapped, x, y, emojiSize); return ctx; } diff --git a/util/Canvas.js b/util/Canvas.js index b1d27498..397a09e5 100644 --- a/util/Canvas.js +++ b/util/Canvas.js @@ -197,11 +197,11 @@ module.exports = class CanvasUtil { return ctx; } - static fillTextWithBreaks(ctx, text, x, y, maxLen, drawMultiBreaks = false) { + static fillTextWithBreaks(ctx, text, x, y, maxLen) { const lines = text.split('\n'); let currentY = y; for (const line of lines) { - if (line === '' && drawMultiBreaks) { + if (line === '') { const metrics = ctx.measureText('a'); currentY += metrics.emHeightAscent + metrics.emHeightDescent; } else { @@ -213,11 +213,11 @@ module.exports = class CanvasUtil { return ctx; } - measureTextHeightWithBreaks(ctx, text, parseMultiBreaks = false) { + measureTextHeightWithBreaks(ctx, text) { const lines = text.split('\n'); let result = 0; for (const line of lines) { - if (line === '' && parseMultiBreaks) { + if (line === '') { const metrics = ctx.measureText('a'); result += metrics.emHeightAscent + metrics.emHeightDescent; } else {