From e7562a50b98ee0e218c0e17b322a1b28df25e42e Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 19 Feb 2025 09:07:58 +0100 Subject: [PATCH] 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 (cherry picked from commit 1d6f71779f05df1af3daacd48f309cd92523152a) Reviewed-by: Qt Cherry-pick Bot --- src/gui/text/qfontdatabase.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 72556b90dee..cef3af226bb 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -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);