summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2021-08-18 11:47:16 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2021-08-19 13:35:40 +0200
commit43a63901f4eb61ad8a29f4cc7a1700685f88ec35 (patch)
tree0f2b3e4f811cbdcd1fb87d7ecf8eb4fc72606c53 /src/gui/text
parent2059d294eb525fe23d1a7681a1563efb513fe31e (diff)
Fix bug with NoFontMerging when font does not support script
When using NoFontMerging, no fallbacks should be resolved. If the font does not support a specific character in the text, we should display a box instead of merging it with another font. But in practice, Qt would still apply the fallback mechanism for one specific case: If the font itself does not support the script of the text, we would get no match and do a search for a fallback instead. Since NoFontMerging is set, we would then force this as preresolved for *all* scripts in the QFont's private data (logically, the match should only have a single response for NoFontMerging). The end result was that if you set the font family before updating the text, you would get broken rendering. This can happen e.g. in Qt Quick, where you could update the font family of a text label while it contains characters which are not supported by the new font. Qt would then pick a fallback instead. When you subsequently update the text, the fallback would already be preresolved for whatever script this is. If it does not support the updated text, we would then see boxes, even if the requested font actually would have supported it. The fix is simply to do an additional pass if NoFontMerging is set and we were not able to match with the specified script. Since the same family might be available in different foundries, with different writing system support, we still want to do a pass first to see if we can match the exact script of the text. Note that QRawFont::fromFont() exploited the bug by using NoFontMerging for getting the fallback font for a specific writing system. To keep this working without having to rewrite fromFont() and risk introducing regressions, we add an argument to make the findFont() function behave as before. It isn't super-pretty, but since it is private API it is hopefully fine. [ChangeLog][QtGui][Text] Fixed an issue with NoFontMerging and changing font families dynamically, where boxes would be seen in place of the correct text. Pick-to: 5.15 6.1 6.2 Done-with: Andy Shaw Fixes: QTBUG-81770 Change-Id: Ide9a36d7528a1040172c5864fa99e7a82eac4e83 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qfontdatabase.cpp12
-rw-r--r--src/gui/text/qfontdatabase_p.h4
-rw-r--r--src/gui/text/qrawfont.cpp2
3 files changed, 15 insertions, 3 deletions
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index 02ac67ce9e..e145114952 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -2350,7 +2350,9 @@ bool QFontDatabase::removeAllApplicationFonts()
/*!
\internal
*/
-QFontEngine *QFontDatabasePrivate::findFont(const QFontDef &request, int script)
+QFontEngine *QFontDatabasePrivate::findFont(const QFontDef &request,
+ int script,
+ bool preferScriptOverFamily)
{
QMutexLocker locker(fontDatabaseMutex());
@@ -2397,6 +2399,14 @@ QFontEngine *QFontDatabasePrivate::findFont(const QFontDef &request, int script)
// 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;
// Don't pass empty family names to the platform font database, since it will then invoke its own matching
diff --git a/src/gui/text/qfontdatabase_p.h b/src/gui/text/qfontdatabase_p.h
index f7998153a1..bf7efc27ef 100644
--- a/src/gui/text/qfontdatabase_p.h
+++ b/src/gui/text/qfontdatabase_p.h
@@ -266,7 +266,9 @@ public:
static void createDatabase();
static void parseFontName(const QString &name, QString &foundry, QString &family);
static QString resolveFontFamilyAlias(const QString &family);
- static QFontEngine *findFont(const QFontDef &request, int script /* QChar::Script */);
+ static QFontEngine *findFont(const QFontDef &request,
+ int script /* QChar::Script */,
+ bool preferScriptOverFamily = false);
static void load(const QFontPrivate *d, int script /* QChar::Script */);
static QFontDatabasePrivate *ensureFontDatabase();
diff --git a/src/gui/text/qrawfont.cpp b/src/gui/text/qrawfont.cpp
index 462c60b1f6..2351f5e378 100644
--- a/src/gui/text/qrawfont.cpp
+++ b/src/gui/text/qrawfont.cpp
@@ -770,7 +770,7 @@ QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writ
QFontDef request(multiEngine->fontDef);
request.styleStrategy |= QFont::NoFontMerging;
- if (QFontEngine *engine = QFontDatabasePrivate::findFont(request, script)) {
+ if (QFontEngine *engine = QFontDatabasePrivate::findFont(request, script, true)) {
if (request.weight > QFont::Normal)
engine->fontDef.weight = request.weight;
if (request.style > QFont::StyleNormal)