mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
Only tweet should chunk
This commit is contained in:
@@ -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
@@ -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++) {
|
||||
|
||||
Reference in New Issue
Block a user