2021-02-05 06:01:45 +02:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
2021-02-05 06:13:36 +02:00
|
|
|
** Copyright (C) 2016 Ivailo Monev
|
2021-02-05 06:01:45 +02:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Katie Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
** This file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
|
|
|
#include <qfontdatabase.h>
|
|
|
|
#include <qdir.h>
|
2022-01-17 23:14:43 +02:00
|
|
|
#include <qdebug.h>
|
2021-02-05 06:01:45 +02:00
|
|
|
|
|
|
|
//TESTED_CLASS=
|
|
|
|
//TESTED_FILES=
|
|
|
|
|
|
|
|
class tst_QFontDatabase : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
tst_QFontDatabase();
|
|
|
|
virtual ~tst_QFontDatabase();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void styles_data();
|
|
|
|
void styles();
|
|
|
|
|
|
|
|
void fixedPitch_data();
|
|
|
|
void fixedPitch();
|
|
|
|
|
|
|
|
void widthTwoTimes_data();
|
|
|
|
void widthTwoTimes();
|
2022-01-17 08:41:13 +02:00
|
|
|
|
|
|
|
void resolveFamily_data();
|
|
|
|
void resolveFamily();
|
2021-02-05 06:01:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
tst_QFontDatabase::tst_QFontDatabase()
|
|
|
|
{
|
|
|
|
QDir::setCurrent(SRCDIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
tst_QFontDatabase::~tst_QFontDatabase()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
void tst_QFontDatabase::styles_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("font");
|
|
|
|
|
2022-01-17 08:41:13 +02:00
|
|
|
QTest::newRow("data0") << QString("FreeSerif [GNU]");
|
2021-02-05 06:01:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QFontDatabase::styles()
|
|
|
|
{
|
|
|
|
QFETCH( QString, font );
|
|
|
|
|
|
|
|
QFontDatabase fdb;
|
|
|
|
QStringList styles = fdb.styles( font );
|
|
|
|
QStringList::Iterator it = styles.begin();
|
|
|
|
while ( it != styles.end() ) {
|
|
|
|
QString style = *it;
|
|
|
|
QString trimmed = style.trimmed();
|
|
|
|
++it;
|
|
|
|
|
|
|
|
QCOMPARE( style, trimmed );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QFontDatabase::fixedPitch_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("font");
|
|
|
|
QTest::addColumn<bool>("fixedPitch");
|
|
|
|
|
2022-01-17 08:41:13 +02:00
|
|
|
QTest::newRow("FreeSans") << QString("FreeSans") << false;
|
|
|
|
QTest::newRow("FreeMono") << QString("FreeMono") << true;
|
2021-02-05 06:01:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QFontDatabase::fixedPitch()
|
|
|
|
{
|
|
|
|
QFETCH(QString, font);
|
|
|
|
QFETCH(bool, fixedPitch);
|
|
|
|
|
|
|
|
QFontDatabase fdb;
|
2021-02-05 06:33:27 +02:00
|
|
|
// qDebug() << fdb.families();
|
2022-01-10 22:39:06 +02:00
|
|
|
if (!fdb.hasFamily(font)) {
|
2022-01-17 08:41:13 +02:00
|
|
|
QSKIP("Font not installed", SkipSingle);
|
2022-01-10 19:52:15 +02:00
|
|
|
}
|
2021-02-05 06:01:45 +02:00
|
|
|
|
|
|
|
QCOMPARE(fdb.isFixedPitch(font), fixedPitch);
|
|
|
|
|
|
|
|
QFont qfont(font);
|
|
|
|
QFontInfo fi(qfont);
|
|
|
|
QCOMPARE(fi.fixedPitch(), fixedPitch);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QFontDatabase::widthTwoTimes_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("font");
|
|
|
|
QTest::addColumn<int>("pixelSize");
|
|
|
|
QTest::addColumn<QString>("text");
|
|
|
|
|
2022-01-10 21:08:04 +02:00
|
|
|
QTest::newRow("FreeSans") << QString("FreeSans") << 1000 << QString("Some text");
|
2021-02-05 06:01:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QFontDatabase::widthTwoTimes()
|
|
|
|
{
|
|
|
|
QFETCH(QString, font);
|
|
|
|
QFETCH(int, pixelSize);
|
|
|
|
QFETCH(QString, text);
|
|
|
|
|
|
|
|
QFont f;
|
|
|
|
f.setFamily(font);
|
|
|
|
f.setPixelSize(pixelSize);
|
|
|
|
|
|
|
|
QFontMetrics fm(f);
|
2022-01-05 19:51:58 +02:00
|
|
|
int w1 = fm.width(text.at(0));
|
|
|
|
int w2 = fm.width(text.at(0));
|
2021-02-05 06:01:45 +02:00
|
|
|
|
|
|
|
QCOMPARE(w1, w2);
|
|
|
|
}
|
|
|
|
|
2022-01-17 08:41:13 +02:00
|
|
|
void tst_QFontDatabase::resolveFamily_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("alias");
|
2022-01-17 23:14:43 +02:00
|
|
|
QTest::addColumn<QString>("font");
|
2022-01-17 08:41:13 +02:00
|
|
|
|
|
|
|
QTest::newRow("Sans Serif") << QString("Sans Serif") << QString("FreeSans");
|
|
|
|
QTest::newRow("Monospace") << QString("Monospace") << QString("FreeMono");
|
2022-01-17 23:14:43 +02:00
|
|
|
QTest::newRow("FreeSans [GNU ]") << QString("FreeSans [GNU ]") << QString("FreeSans");
|
2022-01-17 08:41:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QFontDatabase::resolveFamily()
|
|
|
|
{
|
|
|
|
QFETCH(QString, alias);
|
2022-01-17 23:14:43 +02:00
|
|
|
QFETCH(QString, font);
|
2022-01-17 08:41:13 +02:00
|
|
|
|
|
|
|
if (!QFontDatabase::supportsThreadedFontRendering()) {
|
|
|
|
QSKIP("Font resolution is not supported", SkipSingle);
|
|
|
|
}
|
|
|
|
|
|
|
|
QFontDatabase fdb;
|
|
|
|
// qDebug() << fdb.families();
|
2022-01-17 23:14:43 +02:00
|
|
|
if (!fdb.hasFamily(font)) {
|
2022-01-17 08:41:13 +02:00
|
|
|
QSKIP("Font not installed", SkipSingle);
|
|
|
|
}
|
|
|
|
|
|
|
|
QVERIFY(fdb.hasFamily(alias));
|
|
|
|
}
|
|
|
|
|
2021-02-05 06:01:45 +02:00
|
|
|
QTEST_MAIN(tst_QFontDatabase)
|
|
|
|
|
|
|
|
#include "moc_tst_qfontdatabase.cpp"
|