Fix increasing font size of certain emojis
Before this commit, NeoChat has two methods of detecting whether or not a piece of text was an emoji. One is through a regex, and the other is by using the ICU library. The two methods are used in different parts of the code. This commit removes the regex detector and instead uses ICU for all the places where NeoChat needs to figure out whether or not a string is an emoji. This fixes increasing the font size for messages that only consist of emoji when certain emoji are used that the regex did not handle (such as the transgender symbol and transgender flag emojis).
This commit is contained in:
committed by
Tobias Fella
parent
ab4e1a86dc
commit
f7533a454c
@@ -3,12 +3,24 @@
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#ifdef HAVE_ICU
|
||||
#include <QTextBoundaryFinder>
|
||||
#include <QTextCharFormat>
|
||||
#include <unicode/uchar.h>
|
||||
#include <unicode/urename.h>
|
||||
#endif
|
||||
|
||||
#include <Quotient/connection.h>
|
||||
|
||||
#include <QJsonDocument>
|
||||
|
||||
using namespace Quotient;
|
||||
|
||||
bool QmlUtils::isEmoji(const QString &text)
|
||||
{
|
||||
return Utils::isEmoji(text);
|
||||
}
|
||||
|
||||
bool QmlUtils::isValidJson(const QByteArray &json)
|
||||
{
|
||||
return !QJsonDocument::fromJson(json).isNull();
|
||||
@@ -26,4 +38,28 @@ QColor QmlUtils::getUserColor(qreal hueF)
|
||||
return QColor::fromHslF(hueF, 1, -0.7 * lightness + 0.9, 1);
|
||||
}
|
||||
|
||||
bool Utils::isEmoji(const QString &text)
|
||||
{
|
||||
#ifdef HAVE_ICU
|
||||
QTextBoundaryFinder finder(QTextBoundaryFinder::Grapheme, text);
|
||||
int from = 0;
|
||||
while (finder.toNextBoundary() != -1) {
|
||||
auto to = finder.position();
|
||||
if (text[from].isSpace()) {
|
||||
from = to;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto first = text.mid(from, to - from).toUcs4()[0];
|
||||
if (!u_hasBinaryProperty(first, UCHAR_EMOJI)) {
|
||||
return false;
|
||||
}
|
||||
from = to;
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#include "moc_utils.cpp"
|
||||
|
||||
Reference in New Issue
Block a user