If only family is set, prefer that in the families list after resolving

If a font with only a family set is resolved with one that has been setup
with setFamilies() then the family needs to be prepended to the families
list after resolving. This is so that the font still prefers the one set
as just a family with no famillies set.

This also amends the QFontDialog test to account for this too.

[ChangeLog][QtGui][Text] Resolving a font that just has a family set
with families set will prepend the family to the families so that it
is still the first preference for the font.

Task-number: QTBUG-46322
Change-Id: Icc4005732f95b2b4c684e592b06b31e133270e44
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
bb10
Andy Shaw 2019-10-29 09:44:50 +01:00
parent 99e43db7ce
commit b1004c7d0a
3 changed files with 14 additions and 1 deletions

View File

@ -271,8 +271,13 @@ void QFontPrivate::resolve(uint mask, const QFontPrivate *other)
if (! (mask & QFont::FamilyResolved))
request.family = other->request.family;
if (!(mask & QFont::FamiliesResolved))
if (!(mask & QFont::FamiliesResolved)) {
request.families = other->request.families;
// Prepend the family explicitly set so it will be given
// preference in this case
if (mask & QFont::FamilyResolved)
request.families.prepend(request.family);
}
if (! (mask & QFont::StyleNameResolved))
request.styleName = other->request.styleName;

View File

@ -299,6 +299,13 @@ void tst_QFont::resolve()
font5.setFamilies(fontFamilies);
font6 = font6.resolve(font5);
QCOMPARE(font6.families(), fontFamilies);
QFont font7, font8;
font7.setFamily(QLatin1String("Helvetica"));
font8.setFamilies(fontFamilies);
font7 = font7.resolve(font8);
QCOMPARE(font7.families(), QStringList({"Helvetica", "Arial"}));
QCOMPARE(font7.family(), "Helvetica");
}
#ifndef QT_NO_WIDGETS

View File

@ -225,6 +225,7 @@ void tst_QFontDialog::qtbug_41513_stylesheetStyle()
// The fontdialog sets the styleName, when the fontdatabase knows the style name.
resultFont.setStyleName(testFont.styleName());
testFont.setFamilies(QStringList(testFont.family()));
QCOMPARE(resultFont, testFont);
// reset stylesheet