summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-03-14 15:10:32 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-03-17 18:43:40 +0000
commitfcd5a02886848533c22bca80879888c1ed694195 (patch)
tree1b320118a71fca220d68c3e3d745e99fbc02e4eb /src/gui/text
parent6dd86d901f9eaf4cd4dac5b1d9e977eb2bed3feb (diff)
Avoid populating font family aliases if family matched
When trying to match a font request to fonts in the database we might end up with a mismatch due to the style not being available, but the font family itself was. If that's the case there's no point in trying to populate font aliases, so we explicitly propagate this fact back to QFontDatabasePrivate::findFont so that it can choose to not populate family aliases. Fixes: QTBUG-98369 Fixes: QTBUG-99216 Change-Id: I14470554c73eace836f57cb65e63ada594ccf62e Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> (cherry picked from commit 69d525a6fa19934b3e57f503132bb4ab19f6b923) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qfontdatabase.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index 1486c035e8..f7705b16a9 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -905,6 +905,13 @@ static QtFontStyle *bestStyle(QtFontFoundry *foundry, const QtFontStyle::Key &st
return foundry->styles[best];
}
+enum {
+ FamilyMismatch = 0x800000,
+ ScriptMismatch = 0x080000,
+ PitchMismatch = 0x004000,
+ StyleMismatch = 0x002000,
+ BitmapScaledPenalty = 0x001000
+};
static
unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
@@ -1008,20 +1015,16 @@ unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
unsigned int this_score = 0x0000;
- enum {
- PitchMismatch = 0x4000,
- StyleMismatch = 0x2000,
- BitmapScaledPenalty = 0x1000
- };
+
if (pitch != '*') {
if ((pitch == 'm' && !family->fixedPitch)
|| (pitch == 'p' && family->fixedPitch))
- this_score += PitchMismatch;
+ this_score |= PitchMismatch;
}
if (styleKey != style->key)
- this_score += StyleMismatch;
+ this_score |= StyleMismatch;
if (!style->smoothScalable && px != size->pixelSize) // bitmap scaled
- this_score += BitmapScaledPenalty;
+ this_score |= BitmapScaledPenalty;
if (px != pixelSize) // close, but not exact, size match
this_score += qAbs(px - pixelSize);
@@ -1106,11 +1109,14 @@ static int match(int script,
if (!matchFamilyName(family_name, test.family))
continue;
+ score &= ~FamilyMismatch;
+
test.family->ensurePopulated();
// Check if family is supported in the script we want
if (writingSystem != QFontDatabase::Any && !familySupportsWritingSystem(test.family, writingSystem))
continue;
+ score &= ~ScriptMismatch;
// as we know the script is supported, we can be sure
// to find a matching font here.
@@ -2410,7 +2416,7 @@ QFontEngine *QFontDatabasePrivate::findFont(const QFontDef &req,
QList<int> blackListed;
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)) {
+ if ((score & FamilyMismatch) && QGuiApplicationPrivate::platformIntegration()->fontDatabase()->populateFamilyAliases(family_name)) {
// We populated family aliases (e.g. localized families), so try again
index = match(multi ? QChar::Script_Common : script, request, family_name, foundry_name, &desc, blackListed);
}