diff options
Diffstat (limited to 'src/gui/text/qfontdatabase.cpp')
-rw-r--r-- | src/gui/text/qfontdatabase.cpp | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index b9095d45f6..cf716df669 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -522,12 +522,10 @@ void QFontDatabasePrivate::invalidate() emit static_cast<QGuiApplication *>(QCoreApplication::instance())->fontDatabaseChanged(); } -QtFontFamily *QFontDatabasePrivate::family(const QString &family, FamilyRequestFlags flags) +QtFontFamily *QFontDatabasePrivate::family(const QString &f, FamilyRequestFlags flags) { QtFontFamily *fam = nullptr; - const QString f = family.trimmed(); - int low = 0; int high = count; int pos = count / 2; @@ -1240,9 +1238,13 @@ static bool matchFamilyName(const QString &familyName, QtFontFamily *f) Tries to find the best match for a given request and family/foundry */ -static int match(int script, const QFontDef &request, - const QString &family_name, const QString &foundry_name, - QtFontDesc *desc, const QList<int> &blacklistedFamilies) +static int match(int script, + const QFontDef &request, + const QString &family_name, + const QString &foundry_name, + QtFontDesc *desc, + const QList<int> &blacklistedFamilies, + unsigned int *resultingScore = nullptr) { int result = -1; @@ -1319,6 +1321,10 @@ static int match(int script, const QFontDef &request, if (newscore < 10) // xlfd instead of FT... just accept it break; } + + if (resultingScore != nullptr) + *resultingScore = score; + return result; } @@ -2677,7 +2683,9 @@ bool QFontDatabase::supportsThreadedFontRendering() /*! \internal */ -QFontEngine *QFontDatabase::findFont(const QFontDef &request, int script) +QFontEngine *QFontDatabase::findFont(const QFontDef &request, + int script, + bool preferScriptOverFamily) { QMutexLocker locker(fontDatabaseMutex()); @@ -2719,11 +2727,20 @@ QFontEngine *QFontDatabase::findFont(const QFontDef &request, int script) parseFontName(requestFamily, foundry_name, family_name); QtFontDesc desc; QList<int> blackListed; - int index = match(multi ? QChar::Script_Common : script, request, family_name, foundry_name, &desc, blackListed); - if (index < 0 && QGuiApplicationPrivate::platformIntegration()->fontDatabase()->populateFamilyAliases(family_name)) { + unsigned int score = UINT_MAX; + int index = match(multi ? QChar::Script_Common : script, request, family_name, foundry_name, &desc, blackListed, &score); + if (score > 0 && QGuiApplicationPrivate::platformIntegration()->fontDatabase()->populateFamilyAliases(family_name)) { // We populated familiy aliases (e.g. localized families), so try again index = match(multi ? QChar::Script_Common : script, request, family_name, foundry_name, &desc, blackListed); } + + // If we do not find a match and NoFontMerging is set, use the requested font even if it does + // not support the script. + // + // (we do this at the end to prefer foundries that support the script if they exist) + if (index < 0 && !multi && !preferScriptOverFamily) + index = match(QChar::Script_Common, request, family_name, foundry_name, &desc, blackListed); + if (index >= 0) { QFontDef fontDef = request; |