summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2021-05-06 11:21:07 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2021-05-22 19:47:22 +0200
commit4dccd73b405edca57ed265a94428fe8431322a04 (patch)
tree92ab0b396c892250fc519ac7cadd6662d726c879 /src
parent9e8f580d76e65632a999450fa8e0ab9a20285ff7 (diff)
Windows: Add synthesized fonts also when there is a style name
Since Windows can synthesize certain font traits for us, we used to register these in the font database so that we could match against them. But after change 469b13916983aff4625657eecbb7d2399cac901d, this in principle no longer happens, because we opt out whenever there is a style name (which there usually is, this could be e.g. "Regular" for a normal font). The result of this was that if we looked for a bold variant of a font, we would not find it. In cases where a multi-engine was used, the request for bold would still survive in the multi engine's fontDef, so we would still pick it up later and apply the synthesis. But when NoFontMerging was set, then we would override the weight in the fontDef with the one from the font database. Since the comment documents that the additional registrations are there to make sure all the variants that Windows can synthesize are available for matching, it does not make sense to skip them just because the font has a style name. So this is a partial revert of 469b13916983aff4625657eecbb7d2399cac901d. Note: This exposed an error in QFontDatabase::isSmoothlyScalable(). The style parameter here is not the "styleName" (as in sub-family), but actually predates that API. Instead it is the "style" as returned by QFontDatabase::styles(), which may be the style name, but it can also be the generated description of the style and weight. In the latter case, we would return false for fonts that are actually smoothly scalable, which is incorrect. This caused a failure in tst_QFontMetrics::metrics(). To remedy this, we add an additional condition, and also match the style if it matches the generated descripion of the style key. [ChangeLog][Windows] Fixed an issue where bold/italic would not be synthesized for fonts if QFont::NoFontMerging was set. Fixes: QTBUG-91398 Change-Id: Id2166a47ae2d386536cf6e5e27ff09165ae8a23a Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> (cherry picked from commit f385b8827a75688b8a2cbd51e8da8a602d7f9567)
Diffstat (limited to 'src')
-rw-r--r--src/gui/text/qfontdatabase.cpp18
-rw-r--r--src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp6
-rw-r--r--src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_ft.cpp6
3 files changed, 18 insertions, 12 deletions
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index 583e77fb1c..91037fbee4 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -1731,13 +1731,19 @@ bool QFontDatabase::isSmoothlyScalable(const QString &family, const QString &sty
for (int j = 0; j < f->count; j++) {
QtFontFoundry *foundry = f->foundries[j];
if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
- for (int k = 0; k < foundry->count; k++)
- if ((style.isEmpty() ||
- foundry->styles[k]->styleName == style ||
- foundry->styles[k]->key == styleKey) && foundry->styles[k]->smoothScalable) {
- smoothScalable = true;
+ for (int k = 0; k < foundry->count; k++) {
+ QtFontStyle *fontStyle = foundry->styles[k];
+ smoothScalable =
+ fontStyle->smoothScalable
+ && ((style.isEmpty()
+ || fontStyle->styleName == style
+ || fontStyle->key == styleKey)
+ || (fontStyle->styleName.isEmpty()
+ && style == styleStringHelper(fontStyle->key.weight,
+ QFont::Style(fontStyle->key.style))));
+ if (smoothScalable)
goto end;
- }
+ }
}
}
end:
diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp
index 21f4f7d879..a50f64f55b 100644
--- a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp
+++ b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp
@@ -1120,13 +1120,13 @@ static bool addFontToDatabase(QString familyName,
style, stretch, antialias, scalable, size, fixed, writingSystems, createFontFile(faceName));
// add fonts windows can generate for us:
- if (weight <= QFont::DemiBold && styleName.isEmpty())
+ if (weight <= QFont::DemiBold)
QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, QFont::Bold,
style, stretch, antialias, scalable, size, fixed, writingSystems, createFontFile(faceName));
- if (style != QFont::StyleItalic && styleName.isEmpty())
+ if (style != QFont::StyleItalic)
QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, weight,
QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, createFontFile(faceName));
- if (weight <= QFont::DemiBold && style != QFont::StyleItalic && styleName.isEmpty())
+ if (weight <= QFont::DemiBold && style != QFont::StyleItalic)
QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, QFont::Bold,
QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, createFontFile(faceName));
diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_ft.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_ft.cpp
index f6dcaef882..3e52c073b9 100644
--- a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_ft.cpp
+++ b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_ft.cpp
@@ -281,15 +281,15 @@ static bool addFontToDatabase(QString familyName,
antialias, scalable, size, fixed, writingSystems, createFontFile(value, index));
// add fonts windows can generate for us:
- if (weight <= QFont::DemiBold && styleName.isEmpty())
+ if (weight <= QFont::DemiBold)
QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, QFont::Bold, style, stretch,
antialias, scalable, size, fixed, writingSystems, createFontFile(value, index));
- if (style != QFont::StyleItalic && styleName.isEmpty())
+ if (style != QFont::StyleItalic)
QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, weight, QFont::StyleItalic, stretch,
antialias, scalable, size, fixed, writingSystems, createFontFile(value, index));
- if (weight <= QFont::DemiBold && style != QFont::StyleItalic && styleName.isEmpty())
+ if (weight <= QFont::DemiBold && style != QFont::StyleItalic)
QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, QFont::Bold, QFont::StyleItalic, stretch,
antialias, scalable, size, fixed, writingSystems, createFontFile(value, index));