Show only fonts that can render the grin emoji in the emoji font list

Users often are confused what fonts to pick. However this approach is
way too slow. We need to somehow prefilter the list, but for that we
need to know what writing system emojis belong in or some other quick
filter, that we can apply before the QRawFont and possibly the QFont.
emoji-font-selection
Nicolas Werner 2 years ago
parent 9399e68fda
commit aabe61cd5a
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
  1. 36
      src/UserSettingsPage.cpp

@ -8,6 +8,7 @@
#include <QFontDatabase>
#include <QInputDialog>
#include <QMessageBox>
#include <QRawFont>
#include <QStandardPaths>
#include <QString>
#include <QTextStream>
@ -26,6 +27,29 @@
#include "config/nheko.h"
static QStringList
fontFamilies(bool emoji)
{
static QFontDatabase fontDb;
if (!emoji) {
return fontDb.families();
} else {
static QStringList emojiFamilies = [] {
QStringList families;
const auto originalFamilies = fontDb.families();
for (const auto &family : originalFamilies) {
auto rawFont = QRawFont::fromFont(QFont(family));
if (rawFont.supportsCharacter(0x0001F600ull)) {
families.push_back(family);
}
}
return families;
}();
return emojiFamilies;
}
}
QSharedPointer<UserSettings> UserSettings::instance_;
UserSettings::UserSettings()
@ -1526,7 +1550,6 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
l.push_back(QString::fromStdString(d));
return l;
};
static QFontDatabase fontDb;
switch (index.row()) {
case Theme:
@ -1546,9 +1569,9 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
i->camera().toStdString(), i->cameraResolution().toStdString()));
case Font:
return fontDb.families();
return fontFamilies(false);
case EmojiFont:
return fontDb.families(QFontDatabase::WritingSystem::Symbol);
return fontFamilies(true);
case Ringtone: {
QStringList l{
QStringLiteral("Mute"),
@ -1592,8 +1615,6 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
bool
UserSettingsModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
static QFontDatabase fontDb;
auto i = UserSettings::instance();
if (role == Value) {
switch (index.row()) {
@ -1836,15 +1857,14 @@ UserSettingsModel::setData(const QModelIndex &index, const QVariant &value, int
}
case Font: {
if (value.userType() == QMetaType::Int) {
i->setFontFamily(fontDb.families().at(value.toInt()));
i->setFontFamily(fontFamilies(false).at(value.toInt()));
return true;
} else
return false;
}
case EmojiFont: {
if (value.userType() == QMetaType::Int) {
i->setEmojiFontFamily(
fontDb.families(QFontDatabase::WritingSystem::Symbol).at(value.toInt()));
i->setEmojiFontFamily(fontFamilies(true).at(value.toInt()));
return true;
} else
return false;

Loading…
Cancel
Save