Accept multiple fonts with the same family and style name

When the style name is included in the request to
QtFontFoundry::style(), then it will ignore the other properties
and just return the hit that matches it. This is because we want
the style name to take precedence over all other properties when
the user specifies it in a request.

However, we were using the same function to check if a specific
font already exists. If we are registering a font and it is
already in the database, we want it to replace the existing one.
But for fonts such as the variable "Noto Sans Display" there would
actually be multiple styles in the family that were called the
same ("Regular") but had very different properties.

Due to how fonts are populated on GDI, this issue did not occur
there, so the issue is perceived as a regression in Qt 6.8 when
we switched to DirectWrite as the default backend.

We fix this by ignoring the style name when checking if the font
already exists and instead prioritizing the specific properties
it has. If multiple different styles with the same name exists,
they will all be registered.

Note that it will not be possible to differentiate between the fonts
using the style name, same as before, but you will now at least
be able to select the different styles by specifying properties
such as weight.

[ChangeLog][QtGui][Fonts] Fixed an issue with font families where
only the last of multiple sub-families sharing the same name would
be registered.

Pick-to: 6.8
Fixes: QTBUG-131574
Change-Id: I86a04547065c2d9ef88d9a761af95af33eb9b3d6
Reviewed-by: Lars Knoll <lars@knoll.priv.no>
(cherry picked from commit 1d6f71779f05df1af3daacd48f309cd92523152a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2025-02-19 09:07:58 +01:00 committed by Qt Cherry-pick Bot
parent 333a08c98f
commit e7562a50b9

View File

@ -559,7 +559,8 @@ void qt_registerFont(const QString &familyName, const QString &stylename,
}
QtFontFoundry *foundry = f->foundry(foundryname, true);
QtFontStyle *fontStyle = foundry->style(styleKey, stylename, true);
QtFontStyle *fontStyle = foundry->style(styleKey, QString{}, true);
fontStyle->styleName = stylename;
fontStyle->smoothScalable = scalable;
fontStyle->antialiased = antialiased;
QtFontSize *size = fontStyle->pixelSize(pixelSize ? pixelSize : SMOOTH_SCALABLE, true);