mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Do the same in emoji
This commit is contained in:
@@ -214,15 +214,17 @@ module.exports = class TweetCommand extends Command {
|
||||
const line = wrapped[currentLine];
|
||||
const lineNoEmoji = line.split(emojiRegex());
|
||||
const lineEmoji = line.match(emojiRegex());
|
||||
const height = 23 + 5;
|
||||
let currentX = x;
|
||||
let currentY = y;
|
||||
const metrics = ctx.measureText(line);
|
||||
if (!lineEmoji) {
|
||||
ctx.fillText(line, x, y + (height * currentLine));
|
||||
ctx.fillText(line, x, currentY);
|
||||
currentY += metrics.emHeightAscent + metrics.emHeightDescent;
|
||||
continue;
|
||||
}
|
||||
let currentX = x;
|
||||
for (let i = 0; i < lineNoEmoji.length; i++) {
|
||||
const linePart = lineNoEmoji[i];
|
||||
ctx.fillText(linePart, currentX, y + (height * currentLine));
|
||||
ctx.fillText(linePart, currentX, currentY);
|
||||
currentX += ctx.measureText(linePart).width;
|
||||
const parsedEmoji = twemoji.parse(lineEmoji[i]);
|
||||
if (!parsedEmoji.length || !parsedEmoji[0].url) continue;
|
||||
@@ -230,8 +232,9 @@ module.exports = class TweetCommand extends Command {
|
||||
const loadedEmoji = await loadImage(body);
|
||||
loadedEmoji.width = emojiSize;
|
||||
loadedEmoji.height = emojiSize;
|
||||
ctx.drawImage(loadedEmoji, currentX, y + (height * currentLine), emojiSize, emojiSize);
|
||||
ctx.drawImage(loadedEmoji, currentX, currentY, emojiSize, emojiSize);
|
||||
currentX += emojiSize;
|
||||
currentY += metrics.emHeightAscent + metrics.emHeightDescent;
|
||||
}
|
||||
}
|
||||
this.fillHashtags(ctx, wrapped, x, y, emojiSize);
|
||||
|
||||
Reference in New Issue
Block a user