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 change469b139169
, 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 of469b139169
. 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>
This commit is contained in:
parent
8929e90e86
commit
f385b8827a
@ -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:
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user