From 131eee5cd7547ddb658d6337e1877da3d73b3158 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 31 Aug 2015 22:13:08 +0200 Subject: Avoid synthesizing stretch on condensed font families If an entire font family is condensed or stretched and we match by family name, the default stretch factor of 100 will make the font engine try to synthesize it back to medium stretched font. The existing code is already made to deal with a stretch of 0 that is no longer used. This patch reintroduces 0 stretch to indicate no specific stretch has been requested. Specifically setting stretch to 100 on a QFont will introduce the old behavior. [ChangeLog][QtGui][QFont] The default value of QFont::stretch() is now 0 to indicate any default stretch is acceptable. Task-number: QTBUG-48043 Change-Id: I574747f980fd4f9893df828818aae99a07b41623 Reviewed-by: Eskil Abrahamsen Blomfeldt --- tests/auto/gui/text/qfontcache/tst_qfontcache.cpp | 2 -- .../gui/text/qfontdatabase/tst_qfontdatabase.cpp | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp b/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp index 54bc802cf0..fbca313ea3 100644 --- a/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp +++ b/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp @@ -101,8 +101,6 @@ void tst_QFontCache::engineData() } if (req.pointSize < 0) req.pointSize = req.pixelSize*72.0/d->dpi; - if (req.stretch == 0) - req.stretch = 100; req.family = cacheKey; diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp index adaf3b1f7a..f71d808390 100644 --- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp +++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp @@ -64,6 +64,8 @@ private slots: void aliases(); void fallbackFonts(); + void liberationFont(); + private: const QString m_testFont; }; @@ -275,5 +277,23 @@ void tst_QFontDatabase::fallbackFonts() } } +void tst_QFontDatabase::liberationFont() +{ + QString libSans("Liberation Sans"); + QString libSansNarrow("Liberation Sans Narrow"); + + QFontDatabase db; + if (!db.hasFamily(libSans) || !db.hasFamily(libSansNarrow)) + QSKIP("Requires Liberation Sans installed"); + + QFont fontLS(libSans); + QFont fontLSN(libSansNarrow); + + QFontMetrics fmLS(fontLS); + QFontMetrics fmLSN(fontLSN); + + QVERIFY(fmLS.width(QStringLiteral("foo bar")) > fmLSN.width(QStringLiteral("foo bar"))); +} + QTEST_MAIN(tst_QFontDatabase) #include "tst_qfontdatabase.moc" -- cgit v1.2.3 From 2889ebc9032b06fef812edc2a44d2e1e4e1edcc6 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 15 Aug 2016 15:05:17 +0200 Subject: QSharedPointer: clean up #ifdefs We require Q_COMPILER_RVALUE_REFS and _VARIADIC_TEMPLATES since Qt 5.7, so remove the non-variadic version which anyway has zero test coverage. Also drop #include , as that is included from qglobal.h already, and drop QSKIP from test. Change-Id: I1fc7f7068eac80ad6fd85e1d8f6d33c5c7bb67db Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index 1bba41816b..d0a0feb125 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -1738,9 +1738,6 @@ void tst_QSharedPointer::creating() void tst_QSharedPointer::creatingVariadic() { -#if !defined(Q_COMPILER_RVALUE_REFS) || !defined(Q_COMPILER_VARIADIC_TEMPLATES) - QSKIP("This compiler is not in C++11 mode or it doesn't support rvalue refs and variadic templates"); -#else int i = 42; { @@ -1768,12 +1765,10 @@ void tst_QSharedPointer::creatingVariadic() QCOMPARE(ptr->i, 2); QCOMPARE(ptr->ptr, (void*)0); -#ifdef Q_COMPILER_NULLPTR NoDefaultConstructor2(nullptr, 3); // control check ptr = QSharedPointer::create(nullptr, 3); QCOMPARE(ptr->i, 3); QCOMPARE(ptr->ptr, (void*)nullptr); -#endif } { NoDefaultConstructorRef1 x(i); // control check @@ -1809,7 +1804,6 @@ void tst_QSharedPointer::creatingVariadic() QCOMPARE(ptr->str, QString("bytearray")); QCOMPARE(ptr->i, 42); } -#endif } void tst_QSharedPointer::creatingQObject() -- cgit v1.2.3 From 869513a49f7902b5942e439a972807583dab9bf9 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 15 Aug 2016 09:47:11 +0200 Subject: tst_QRegularExpression: clean up - port Q_FOREACH to C++11 range-for (incl. one case of iterating over QHash::keys()) - port uses of inefficient QLists to QVector - add Q_DECLARE_TYPEINFO for types held in Qt containers Fixes errors pointed out by my tree's static checks. Change-Id: I30eb432528fa3008240b5c217d5f2f9ddc3679be Reviewed-by: Giuseppe D'Angelo --- .../qregularexpression/tst_qregularexpression.cpp | 26 ++++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp index 5825bdb6d6..2a93250ba5 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -61,6 +61,9 @@ struct Match QStringList captured; QHash namedCaptured; }; +QT_BEGIN_NAMESPACE +Q_DECLARE_TYPEINFO(Match, Q_MOVABLE_TYPE); +QT_END_NAMESPACE Q_DECLARE_METATYPE(Match) @@ -85,9 +88,9 @@ bool operator==(const QRegularExpressionMatch &rem, const Match &m) } } - Q_FOREACH (const QString &name, m.namedCaptured.keys()) { - QString remCaptured = rem.captured(name); - QString mCaptured = m.namedCaptured.value(name); + for (auto it = m.namedCaptured.begin(), end = m.namedCaptured.end(); it != end; ++it) { + const QString remCaptured = rem.captured(it.key()); + const QString mCaptured = it.value(); if (remCaptured != mCaptured || remCaptured.isNull() != mCaptured.isNull() || remCaptured.isEmpty() != mCaptured.isEmpty()) { @@ -115,12 +118,11 @@ bool operator!=(const Match &m, const QRegularExpressionMatch &rem) } -bool operator==(const QRegularExpressionMatchIterator &iterator, const QList &expectedMatchList) +bool operator==(const QRegularExpressionMatchIterator &iterator, const QVector &expectedMatchList) { QRegularExpressionMatchIterator i = iterator; - foreach (const Match &expectedMatch, expectedMatchList) - { + for (const Match &expectedMatch : expectedMatchList) { if (!i.hasNext()) return false; @@ -135,17 +137,17 @@ bool operator==(const QRegularExpressionMatchIterator &iterator, const QList &expectedMatchList, const QRegularExpressionMatchIterator &iterator) +bool operator==(const QVector &expectedMatchList, const QRegularExpressionMatchIterator &iterator) { return operator==(iterator, expectedMatchList); } -bool operator!=(const QRegularExpressionMatchIterator &iterator, const QList &expectedMatchList) +bool operator!=(const QRegularExpressionMatchIterator &iterator, const QVector &expectedMatchList) { return !operator==(iterator, expectedMatchList); } -bool operator!=(const QList &expectedMatchList, const QRegularExpressionMatchIterator &iterator) +bool operator!=(const QVector &expectedMatchList, const QRegularExpressionMatchIterator &iterator) { return !operator==(expectedMatchList, iterator); } @@ -1117,9 +1119,9 @@ void tst_QRegularExpression::globalMatch_data() QTest::addColumn("offset"); QTest::addColumn("matchType"); QTest::addColumn("matchOptions"); - QTest::addColumn >("matchList"); + QTest::addColumn >("matchList"); - QList matchList; + QVector matchList; Match m; matchList.clear(); @@ -1375,7 +1377,7 @@ void tst_QRegularExpression::globalMatch() QFETCH(int, offset); QFETCH(QRegularExpression::MatchType, matchType); QFETCH(QRegularExpression::MatchOptions, matchOptions); - QFETCH(QList, matchList); + QFETCH(QVector, matchList); testMatch(regexp, static_cast(&QRegularExpression::globalMatch), -- cgit v1.2.3 From ac1e87d9f373ad649d989f254b37d2f29ddf25fe Mon Sep 17 00:00:00 2001 From: Konstantin Tokarev Date: Wed, 3 Aug 2016 15:45:02 +0300 Subject: Added capHeight() to QRawFont and QFontMetrics(F) Cap height is an important metric of font, in particular it is required to make decent implementation of "initial-letter" CSS property in QtWebKit. Note that some fonts lack cap height metadata, so we need to fall back to measuring H letter height. Change-Id: Icf69d92159d070889085e20d31f2e397d796d940 Reviewed-by: Eskil Abrahamsen Blomfeldt --- tests/auto/gui/text/qrawfont/testdata.qrc | 1 + tests/auto/gui/text/qrawfont/testfont_os2_v1.ttf | Bin 0 -> 72960 bytes tests/auto/gui/text/qrawfont/tst_qrawfont.cpp | 30 +++++++++++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tests/auto/gui/text/qrawfont/testfont_os2_v1.ttf (limited to 'tests') diff --git a/tests/auto/gui/text/qrawfont/testdata.qrc b/tests/auto/gui/text/qrawfont/testdata.qrc index 8f8e32ed24..c7ac9641d1 100644 --- a/tests/auto/gui/text/qrawfont/testdata.qrc +++ b/tests/auto/gui/text/qrawfont/testdata.qrc @@ -1,6 +1,7 @@ testfont_bold_italic.ttf + testfont_os2_v1.ttf ../../../shared/resources/testfont.ttf diff --git a/tests/auto/gui/text/qrawfont/testfont_os2_v1.ttf b/tests/auto/gui/text/qrawfont/testfont_os2_v1.ttf new file mode 100644 index 0000000000..ee8b67d892 Binary files /dev/null and b/tests/auto/gui/text/qrawfont/testfont_os2_v1.ttf differ diff --git a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp index 471b32dd50..3cf108ed62 100644 --- a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp +++ b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp @@ -93,6 +93,7 @@ private slots: private: QString testFont; QString testFontBoldItalic; + QString testFontOs2V1; #endif // QT_NO_RAWFONT }; @@ -110,6 +111,7 @@ void tst_QRawFont::initTestCase() { testFont = QFINDTESTDATA("testfont.ttf"); testFontBoldItalic = QFINDTESTDATA("testfont_bold_italic.ttf"); + testFontOs2V1 = QFINDTESTDATA("testfont_os2_v1.ttf"); if (testFont.isEmpty() || testFontBoldItalic.isEmpty()) QFAIL("qrawfont unittest font files not found!"); @@ -184,6 +186,7 @@ void tst_QRawFont::correctFontData_data() QTest::addColumn("hintingPreference"); QTest::addColumn("unitsPerEm"); QTest::addColumn("pixelSize"); + QTest::addColumn("capHeight"); int hintingPreferences[] = { int(QFont::PreferDefaultHinting), @@ -207,7 +210,8 @@ void tst_QRawFont::correctFontData_data() << QFont::Normal << QFont::HintingPreference(*hintingPreference) << qreal(1000.0) - << qreal(10.0); + << qreal(10.0) + << 7; fileName = testFontBoldItalic; title = fileName @@ -221,7 +225,23 @@ void tst_QRawFont::correctFontData_data() << QFont::Bold << QFont::HintingPreference(*hintingPreference) << qreal(1000.0) - << qreal(10.0); + << qreal(10.0) + << 7; + + fileName = testFontOs2V1; + title = fileName + + QLatin1String(": hintingPreference=") + + QString::number(*hintingPreference); + + QTest::newRow(qPrintable(title)) + << fileName + << QString::fromLatin1("QtBidiTestFont") + << QFont::StyleNormal + << QFont::Normal + << QFont::HintingPreference(*hintingPreference) + << qreal(1000.0) + << qreal(10.0) + << 7; ++hintingPreference; } @@ -236,6 +256,7 @@ void tst_QRawFont::correctFontData() QFETCH(QFont::HintingPreference, hintingPreference); QFETCH(qreal, unitsPerEm); QFETCH(qreal, pixelSize); + QFETCH(int, capHeight); QRawFont font(fileName, 10, hintingPreference); QVERIFY(font.isValid()); @@ -246,6 +267,11 @@ void tst_QRawFont::correctFontData() QCOMPARE(font.hintingPreference(), hintingPreference); QCOMPARE(font.unitsPerEm(), unitsPerEm); QCOMPARE(font.pixelSize(), pixelSize); + + // Some platforms return the actual fractional height of the + // H character when the value is missing from the OS/2 table, + // so we ceil it off to match (any touched pixel counts). + QCOMPARE(qCeil(font.capHeight()), capHeight); } void tst_QRawFont::glyphIndices() -- cgit v1.2.3 From af5ccb7f8c91591ef9dec1ccf0ca211962002a94 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 7 Aug 2016 15:32:40 +0300 Subject: tst_QStyleSheetStyle: Extract Method sample_widgets() The only difference between the sample widget sets was: - widgets << new QLabel("TESTING TESTING"); + widgets << new QLabel("TESTING TESTING"); I chose the latter, because it's the more complex example and neither the hoverColors nor focusColors tests suggest the boldness of the text matters. Part of port away from Q_FOREACH. Change-Id: I9a928de4e781b96ad00a8c9515977c35ebfa6c24 Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../qstylesheetstyle/tst_qstylesheetstyle.cpp | 48 +++++++++------------- 1 file changed, 20 insertions(+), 28 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp index 8d84addedb..b95a17bd4e 100644 --- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -817,6 +817,24 @@ static bool testForColors(const QImage& image, const QColor& color, bool ensureP return false; } +static const QList sample_widgets() // returning const to avoid detaching when passing to range-for +{ + QList widgets; + widgets << new QPushButton("TESTING TESTING"); + widgets << new QLineEdit("TESTING TESTING"); + widgets << new QLabel("TESTING TESTING"); + QSpinBox *spinbox = new QSpinBox; + spinbox->setMaximum(1000000000); + spinbox->setValue(123456789); + widgets << spinbox; + QComboBox *combobox = new QComboBox; + combobox->setEditable(true); + combobox->addItems(QStringList() << "TESTING TESTING"); + widgets << combobox; + widgets << new QLabel("TESTING TESTING"); + return widgets; +} + void tst_QStyleSheetStyle::focusColors() { // Tests if colors can be changed by altering the focus of the widget. @@ -833,22 +851,9 @@ void tst_QStyleSheetStyle::focusColors() " (for example, QTBUG-33959)." "That doesn't mean that the feature doesn't work in practice."); #endif - QList widgets; - widgets << new QPushButton("TESTING TESTING"); - widgets << new QLineEdit("TESTING TESTING"); - widgets << new QLabel("TESTING TESTING"); - QSpinBox *spinbox = new QSpinBox; - spinbox->setMaximum(1000000000); - spinbox->setValue(123456789); - widgets << spinbox; - QComboBox *combobox = new QComboBox; - combobox->setEditable(true); - combobox->addItems(QStringList() << "TESTING TESTING"); - widgets << combobox; - widgets << new QLabel("TESTING TESTING"); - foreach (QWidget *widget, widgets) { + for (QWidget *widget : sample_widgets()) { QDialog frame; QLayout* layout = new QGridLayout; @@ -891,21 +896,8 @@ void tst_QStyleSheetStyle::hoverColors() #ifdef Q_OS_OSX QSKIP("This test is fragile on Mac, most likely due to QTBUG-33959."); #endif - QList widgets; - widgets << new QPushButton("TESTING TESTING"); - widgets << new QLineEdit("TESTING TESTING"); - widgets << new QLabel("TESTING TESTING"); - QSpinBox *spinbox = new QSpinBox; - spinbox->setMaximum(1000000000); - spinbox->setValue(123456789); - widgets << spinbox; - QComboBox *combobox = new QComboBox; - combobox->setEditable(true); - combobox->addItems(QStringList() << "TESTING TESTING"); - widgets << combobox; - widgets << new QLabel("TESTING TESTING"); - foreach (QWidget *widget, widgets) { + for (QWidget *widget : sample_widgets()) { //without Qt::X11BypassWindowManagerHint the window manager may move the window after we moved the cursor QDialog frame(0, Qt::X11BypassWindowManagerHint); QLayout* layout = new QGridLayout; -- cgit v1.2.3 From e6f5a7d6c03366d773dfa29ce4c119d7ab941ac4 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 5 Aug 2016 10:04:11 +0300 Subject: tst_QString: clean up - add Q_DECLARE_TYPEINFO for types held in Qt containers (incl. QVariant) - port Q_FOREACH to C++11 range-for - port uses of inefficient QLists to QVector Fixes errors pointed out by my tree's static checks. Change-Id: I7176b4b12ed47ed23166857bd127c459ea2a48d5 Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 36784435b8..2e35c961c6 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -84,11 +84,11 @@ public: template void apply0(QString &s, MemFun mf) const - { Q_FOREACH (QChar ch, this->pinned) (s.*mf)(ch); } + { for (QChar ch : qAsConst(this->pinned)) (s.*mf)(ch); } template void apply1(QString &s, MemFun mf, A1 a1) const - { Q_FOREACH (QChar ch, this->pinned) (s.*mf)(a1, ch); } + { for (QChar ch : qAsConst(this->pinned)) (s.*mf)(a1, ch); } }; template <> @@ -254,6 +254,9 @@ public: }; } // unnamed namespace +QT_BEGIN_NAMESPACE +Q_DECLARE_TYPEINFO(CharStarContainer, Q_PRIMITIVE_TYPE); +QT_END_NAMESPACE Q_DECLARE_METATYPE(CharStarContainer) @@ -643,7 +646,7 @@ QString verifyZeroTermination(const QString &str) } while (0) \ /**/ -typedef QList IntList; +typedef QVector IntList; tst_QString::tst_QString() { -- cgit v1.2.3