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-11 13:22:44 +0200
commitf385b8827a75688b8a2cbd51e8da8a602d7f9567 (patch)
tree61661b03f01f9644ea98f6ff5949f1c8197f5c1b /src
parent8929e90e8665e9cd1434c32faeeda835f23aaf87 (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. Pick-to: 5.15 6.1 Fixes: QTBUG-91398 Change-Id: Id2166a47ae2d386536cf6e5e27ff09165ae8a23a Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/gui/text/qfontdatabase.cpp18
-rw-r--r--src/gui/text/windows/qwindowsfontdatabase.cpp6
-rw-r--r--src/gui/text/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 a105b5dd51..b7d834bc4a 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -1577,13 +1577,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/gui/text/windows/qwindowsfontdatabase.cpp b/src/gui/text/windows/qwindowsfontdatabase.cpp
index 58ff99e3a8..94a152abed 100644
--- a/src/gui/text/windows/qwindowsfontdatabase.cpp
+++ b/src/gui/text/windows/qwindowsfontdatabase.cpp
@@ -604,13 +604,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/gui/text/windows/qwindowsfontdatabase_ft.cpp b/src/gui/text/windows/qwindowsfontdatabase_ft.cpp
index e2c8d3455d..c8dbba015c 100644
--- a/src/gui/text/windows/qwindowsfontdatabase_ft.cpp
+++ b/src/gui/text/windows/qwindowsfontdatabase_ft.cpp
@@ -279,15 +279,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));