mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +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) {
|
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());
|
const emoji = text.match(emojiRegex());
|
||||||
if (!emoji) {
|
if (!emoji) {
|
||||||
ctx.fillText(wrapped.join('\n'), x, y);
|
ctx.fillText(wrapped.join('\n'), x, y);
|
||||||
|
|||||||
+2
-2
@@ -206,7 +206,7 @@ module.exports = class CanvasUtil {
|
|||||||
return shorten ? `${text}...` : text;
|
return shorten ? `${text}...` : text;
|
||||||
}
|
}
|
||||||
|
|
||||||
static wrapText(ctx, text, maxWidth) {
|
static wrapText(ctx, text, maxWidth, shouldChunk = false) {
|
||||||
const lines = [];
|
const lines = [];
|
||||||
const wordsAndBreaks = text.split('\n');
|
const wordsAndBreaks = text.split('\n');
|
||||||
for (let i = 0; i < wordsAndBreaks.length; i++) {
|
for (let i = 0; i < wordsAndBreaks.length; i++) {
|
||||||
@@ -221,7 +221,7 @@ module.exports = class CanvasUtil {
|
|||||||
const word = words[j];
|
const word = words[j];
|
||||||
if (ctx.measureText(`${currentLine} ${word}`).width <= maxWidth) {
|
if (ctx.measureText(`${currentLine} ${word}`).width <= maxWidth) {
|
||||||
currentLine += `${currentLine === '' ? '' : ' '}${word}`;
|
currentLine += `${currentLine === '' ? '' : ' '}${word}`;
|
||||||
} else if (ctx.measureText(word).width > maxWidth) {
|
} else if (ctx.measureText(word).width > maxWidth && shouldChunk) {
|
||||||
const chunks = [];
|
const chunks = [];
|
||||||
let currentChunk = '';
|
let currentChunk = '';
|
||||||
for (let k = 0; k < word.length; k++) {
|
for (let k = 0; k < word.length; k++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user