From e28ae083d2ba69406bf444f951b6c820c5aaf4f4 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 24 Apr 2018 14:33:00 +0200 Subject: 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 Reviewed-by: Lars Knoll --- src/gui/text/qfontdatabase.cpp | 1 - .../gui/text/qfontdatabase/tst_qfontdatabase.cpp | 24 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index a4e5130937..42c449a0c8 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -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; } diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp index ebe9d3b992..9f247a90e2 100644 --- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp +++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp @@ -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; -- cgit v1.2.3