Make hashtags and @ blue

This commit is contained in:
Dragon Fire
2024-04-26 18:15:45 -04:00
parent d1b5202898
commit e1f4b5b8ee
+21
View File
@@ -207,6 +207,7 @@ module.exports = class TweetCommand extends Command {
const emoji = text.match(emojiRegex());
if (!emoji) {
ctx.fillText(wrapped.join('\n'), x, y);
this.fillHashtags(ctx, wrapped, x, y);
return ctx;
}
for (let currentLine = 0; currentLine < wrapped.length; currentLine++) {
@@ -233,6 +234,26 @@ module.exports = class TweetCommand extends Command {
currentX += emojiSize;
}
}
this.fillHashtags(ctx, wrapped, x, y);
return ctx;
}
fillHashtags(ctx, wrappedText, x, y) {
const height = 23 + 9;
let currentLine = 0;
for (const line of wrappedText) {
const words = line.split(' ');
for (let i = 0; i < words.length; i++) {
const word = words[i];
if (!word.startsWith('#') && !word.startsWith('@')) continue;
const preLen = ctx.measureText(`${words.slice(0, i).join(' ')} `).width;
const oldStyle = ctx.fillStyle;
ctx.fillStyle = 'blue';
ctx.fillText(word, x + preLen, y + (height * currentLine));
ctx.fillStyle = oldStyle;
}
currentLine++;
}
return ctx;
}