Skip to content

Commit

Permalink
Increase font size on emoji posted into chat
Browse files Browse the repository at this point in the history
Because they're difficult to make out otherwise.

Relates to #1130.
  • Loading branch information
askmeaboutlo0m committed Aug 20, 2023
1 parent 65f1e26 commit 55b4d54
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Unreleased Version 2.2.0-pre
* Feature: Implement brush export and make the brush import also understand classic brushes.
* Fix: Make erasing with MyPaint brushes in indirect mode actually work.
* Feature: Make sliders adhere to the chosen color space. Thanks to leandro2222 for suggesting.
* Feature: Increase font size on emoji posted into chat. Thanks to leandro2222 for suggesting.

2023-07-31 Version 2.2.0-beta.6
* Fix: Don't forget account password when entering a wrong session password.
Expand Down
7 changes: 5 additions & 2 deletions src/desktop/chat/chatwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct Chat {
".timestamp { color: #8d8d8d }"
".alert .timestamp { color: #eff0f1 }"
"a:link { color: #1d99f3 }"
".emoji { font-size: xx-large; }"
);
}

Expand Down Expand Up @@ -601,7 +602,8 @@ void ChatWidget::receiveMessage(int sender, int recipient, uint8_t tflags, uint8
return;
}

const QString safetext = htmlutils::linkify(message.toHtmlEscaped());
const QString safetext =
htmlutils::linkify(htmlutils::wrapEmoji(message.toHtmlEscaped()));

Q_ASSERT(d->chats.contains(chatId));
Chat &chat = d->chats[chatId];
Expand Down Expand Up @@ -654,7 +656,8 @@ void ChatWidget::setPinnedMessage(const QString &message)
void ChatWidget::systemMessage(const QString& message, bool alert)
{
const bool wasAtEnd = d->isAtEnd();
const QString safetext = htmlutils::linkify(message.toHtmlEscaped());
const QString safetext =
htmlutils::linkify(htmlutils::wrapEmoji(message.toHtmlEscaped()));
if(alert) {
d->publicChat().appendMessageCompact(0, QString(), safetext, false, true);
emit expandRequested();
Expand Down
15 changes: 15 additions & 0 deletions src/libclient/utils/html.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,19 @@ QString linkify(const QString &input, const QString &extra)
return out;
}

QString wrapEmoji(const QString &input, const QString &replacement)
{
// This regex is taken from the Unicode Technical Standard #51 version 15,
// revision 23, section 1.4.9 "EBNF and Regex". It doesn't exactly match
// emoji, but it should hopefully be close enough for our use case.
// https://unicode.org/reports/tr51/#EBNF_and_Regex
static QRegularExpression re{
"(\\p{RI}\\p{RI}|\\p{Emoji}(\\p{EMod}|\\x{FE0F}\\x{20E3}?|[\\x{E0020}-"
"\\x{E007E}]+\\x{E007F})?(\\x{200D}(\\p{RI}\\p{RI}|\\p{Emoji}(\\p{EMod}"
"|\\x{FE0F}\\x{20E3}?|[\\x{E0020}-\\x{E007E}]+\\x{E007F})?))*)+"};
QString s = input;
s.replace(re, replacement);
return s;
}

}
4 changes: 4 additions & 0 deletions src/libclient/utils/html.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ QString newlineToBr(const QString &input);
*/
QString linkify(const QString &input, const QString &extra=QString());

QString wrapEmoji(
const QString &input,
const QString &replacement = "<span class=\"emoji\">\\1</span>");

}

#endif

0 comments on commit 55b4d54

Please sign in to comment.