diff options
Diffstat (limited to 'tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp')
-rw-r--r-- | tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp | 133 |
1 files changed, 94 insertions, 39 deletions
diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp index 6b6ad201bf..b2d00f6666 100644 --- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp +++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QSignalSpy> @@ -37,6 +12,11 @@ #include <private/qfont_p.h> #include <private/qfontengine_p.h> #include <qpa/qplatformfontdatabase.h> +#include <qpa/qplatformintegration.h> + +#include <QtGui/private/qguiapplication_p.h> + +using namespace Qt::StringLiterals; Q_LOGGING_CATEGORY(lcTests, "qt.text.tests") @@ -84,11 +64,18 @@ private slots: void stretchRespected(); + void variableFont(); + +#ifdef Q_OS_WIN + void findCourier(); +#endif + private: QString m_ledFont; QString m_testFont; QString m_testFontCondensed; QString m_testFontItalic; + QString m_testFontVariable; }; tst_QFontDatabase::tst_QFontDatabase() @@ -101,10 +88,12 @@ void tst_QFontDatabase::initTestCase() m_testFont = QFINDTESTDATA("testfont.ttf"); m_testFontCondensed = QFINDTESTDATA("testfont_condensed.ttf"); m_testFontItalic = QFINDTESTDATA("testfont_italic.ttf"); + m_testFontVariable = QFINDTESTDATA("testfont_variable.ttf"); QVERIFY(!m_ledFont.isEmpty()); QVERIFY(!m_testFont.isEmpty()); QVERIFY(!m_testFontCondensed.isEmpty()); QVERIFY(!m_testFontItalic.isEmpty()); + QVERIFY(!m_testFontVariable.isEmpty()); } void tst_QFontDatabase::styles_data() @@ -242,7 +231,7 @@ void tst_QFontDatabase::addAppFont() int id; if (useMemoryFont) { QFile fontfile(m_ledFont); - fontfile.open(QIODevice::ReadOnly); + QVERIFY(fontfile.open(QIODevice::ReadOnly)); QByteArray fontdata = fontfile.readAll(); QVERIFY(!fontdata.isEmpty()); id = QFontDatabase::addApplicationFontFromData(fontdata); @@ -255,7 +244,7 @@ void tst_QFontDatabase::addAppFont() QCOMPARE(id, -1); return; #endif - QCOMPARE(fontDbChangedSpy.count(), 1); + QCOMPARE(fontDbChangedSpy.size(), 1); if (id == -1) QSKIP("Skip the test since app fonts are not supported on this system"); @@ -264,9 +253,9 @@ void tst_QFontDatabase::addAppFont() const QStringList newFamilies = QFontDatabase::families(); QVERIFY(!newFamilies.isEmpty()); - QVERIFY(newFamilies.count() >= oldFamilies.count()); + QVERIFY(newFamilies.size() >= oldFamilies.size()); - for (int i = 0; i < addedFamilies.count(); ++i) { + for (int i = 0; i < addedFamilies.size(); ++i) { QString family = addedFamilies.at(i); QVERIFY(newFamilies.contains(family)); QFont qfont(family); @@ -275,9 +264,9 @@ void tst_QFontDatabase::addAppFont() } QVERIFY(QFontDatabase::removeApplicationFont(id)); - QCOMPARE(fontDbChangedSpy.count(), 2); + QCOMPARE(fontDbChangedSpy.size(), 2); - QVERIFY(QFontDatabase::families().count() <= oldFamilies.count()); + QVERIFY(QFontDatabase::families().size() <= oldFamilies.size()); } void tst_QFontDatabase::addTwoAppFontsFromFamily() @@ -338,8 +327,8 @@ void tst_QFontDatabase::fallbackFonts() layout.createLine(); layout.endLayout(); - QList<QGlyphRun> runs = layout.glyphRuns(0, 1); - foreach (QGlyphRun run, runs) { + const QList<QGlyphRun> runs = layout.glyphRuns(0, 1); + for (QGlyphRun run : runs) { QRawFont rawFont = run.rawFont(); QVERIFY(rawFont.isValid()); @@ -434,13 +423,12 @@ void tst_QFontDatabase::condensedFontMatching() QFont f; f.setStyleStrategy(QFont::NoFontMerging); QFontPrivate *font_d = QFontPrivate::get(f); - if (font_d->engineForScript(QChar::Script_Common)->type() != QFontEngine::Freetype) + if (font_d->engineForScript(QChar::Script_Common)->type() != QFontEngine::Freetype + && font_d->engineForScript(QChar::Script_Common)->type() != QFontEngine::DirectWrite) { QEXPECT_FAIL("","No matching of sub-family by stretch on Windows", Continue); + } #endif -#ifdef Q_OS_ANDROID - QEXPECT_FAIL("", "QTBUG-69216", Continue); -#endif QCOMPARE(QFontMetrics(tfcByStretch).horizontalAdvance(testString()), QFontMetrics(tfcByStyleName).horizontalAdvance(testString())); @@ -500,5 +488,72 @@ void tst_QFontDatabase::registerOpenTypePreferredNamesApplication() QFontDatabase::removeApplicationFont(id); } +#ifdef Q_OS_WIN +void tst_QFontDatabase::findCourier() +{ + QFont font = QFontDatabase::font(u"Courier"_s, u""_s, 16); + QFontInfo info(font); + QCOMPARE(info.family(), u"Courier New"_s); + QCOMPARE(info.pointSize(), 16); + + font = QFontDatabase::font("Courier", "", 64); + info = font; + QCOMPARE(info.family(), u"Courier New"_s); + QCOMPARE(info.pointSize(), 64); + + // By setting "PreferBitmap" we should get Courier itself. + font.setStyleStrategy(QFont::PreferBitmap); + info = font; + QCOMPARE(info.family(), u"Courier"_s); + // Which has an upper bound on point size + QCOMPARE(info.pointSize(), 19); + + font.setStyleStrategy(QFont::PreferDefault); + info = font; + QCOMPARE(info.family(), u"Courier New"_s); + QCOMPARE(info.pointSize(), 64); +} +#endif + +void tst_QFontDatabase::variableFont() +{ + { + QPlatformFontDatabase *pfdb = QGuiApplicationPrivate::platformIntegration()->fontDatabase(); + if (!pfdb->supportsVariableApplicationFonts()) + QSKIP("Variable application fonts not supported on this platform"); + } + + int id = QFontDatabase::addApplicationFont(m_testFontVariable); + if (id == -1) + QSKIP("Skip the test since app fonts are not supported on this system"); + + QString family = QFontDatabase::applicationFontFamilies(id).first(); + { + QFont font(family); + QCOMPARE(QFontInfo(font).styleName(), u"Regular"_s); + QCOMPARE(QFontInfo(font).weight(), QFont::Normal); + } + + { + QFont font(family); + font.setWeight(QFont::Black); + QCOMPARE(QFontInfo(font).styleName(), u"QtExtraBold"_s); + QCOMPARE(QFontInfo(font).weight(), int(QFont::Black)); + } + + { + QFont regularFont(family); + QFont extraBoldFont(family); + extraBoldFont.setStyleName(u"QtExtraBold"_s); + + QFontMetricsF regularFm(regularFont); + QFontMetricsF extraBoldFm(extraBoldFont); + + QVERIFY(regularFm.horizontalAdvance(QLatin1Char('1')) < extraBoldFm.horizontalAdvance(QLatin1Char('1'))); + } + + QFontDatabase::removeApplicationFont(id); +} + QTEST_MAIN(tst_QFontDatabase) #include "tst_qfontdatabase.moc" |