summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text/qfontdatabase
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2018-04-24 14:33:00 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2018-05-04 04:46:48 +0000
commite28ae083d2ba69406bf444f951b6c820c5aaf4f4 (patch)
treede94360b3b062ccef90feeeaf49ba01ac0b5b355 /tests/auto/gui/text/qfontdatabase
parent8447f5f006287887ee2910d9710d7bd867aca6e8 (diff)
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>
Diffstat (limited to 'tests/auto/gui/text/qfontdatabase')
-rw-r--r--tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp24
1 files changed, 24 insertions, 0 deletions
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;