macOS: Fix stretch of condensed fonts with NoFontMerging

When showing a condensed font with AnyStretch, we should
not apply any stretch to the font (and if a stretch is
requested, we should calculate the actual stretch based
on how much the font is already stretched or condensed).

This usually works as expected, however, when using
QFont::NoFontMerging as the style strategy, we would
scale the glyph advances by the stretch of the font
since the calculated stretch of the font engine would
be overwritten by the actual stretch. In the case where
we use font merging, this would be done for the multi
engine, so we would not get the same issue, since the
text engine gets the stretch from the actual font engine
and this still has the original, calculated stretch
set.

Note on the test: We can't use testString() for this,
since it contains a space, and the test font does not
have a glyph for this, so we will end up merging a
different font for the space, giving us a slightly
different advance.

[ChangeLog][QtGui][macOS] Fixed display of condensed fonts
when NoFontMerging is in use.

Task-number: QTBUG-63800
Change-Id: I5b05e0dbfc8ae4b5d10c621ecb0975f53fda9483
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2018-04-24 14:33:00 +02:00
parent 8447f5f006
commit e28ae083d2
2 changed files with 24 additions and 1 deletions

View File

@ -689,7 +689,6 @@ static void initFontDef(const QtFontDesc &desc, const QFontDef &request, QFontDe
if (!multi)
fontDef->style = desc.style->key.style;
fontDef->fixedPitch = desc.family->fixedPitch;
fontDef->stretch = desc.style->key.stretch;
fontDef->ignorePitch = false;
}

View File

@ -65,6 +65,7 @@ private slots:
void fallbackFonts();
void condensedFontWidth();
void condensedFontWidthNoFontMerging();
void condensedFontMatching();
void rasterFonts();
@ -297,6 +298,29 @@ static QString testString()
return QStringLiteral("foo bar");
}
void tst_QFontDatabase::condensedFontWidthNoFontMerging()
{
int regularFontId = QFontDatabase::addApplicationFont(m_testFont);
int condensedFontId = QFontDatabase::addApplicationFont(m_testFontCondensed);
QVERIFY(!QFontDatabase::applicationFontFamilies(regularFontId).isEmpty());
QVERIFY(!QFontDatabase::applicationFontFamilies(condensedFontId).isEmpty());
QString regularFontName = QFontDatabase::applicationFontFamilies(regularFontId).first();
QString condensedFontName = QFontDatabase::applicationFontFamilies(condensedFontId).first();
QFont condensedFont1(condensedFontName);
if (regularFontName == condensedFontName)
condensedFont1.setStyleName(QStringLiteral("Condensed"));
condensedFont1.setStyleStrategy(QFont::PreferMatch);
QFont condensedFont2 = condensedFont1;
condensedFont2.setStyleStrategy(QFont::StyleStrategy(QFont::NoFontMerging | QFont::PreferMatch));
QCOMPARE(QFontMetricsF(condensedFont2).horizontalAdvance(QStringLiteral("foobar")),
QFontMetricsF(condensedFont1).horizontalAdvance(QStringLiteral("foobar")));
}
void tst_QFontDatabase::condensedFontWidth()
{
QFontDatabase db;