2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2013-01-02 11:13:29 +00:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-09-19 12:28:29 +00:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2012-09-19 12:28:29 +00:00
|
|
|
** 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 Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, 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.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-05-24 09:34:08 +00:00
|
|
|
** GNU General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3.0 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU General Public License version 3.0 requirements will be
|
|
|
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2012-01-24 06:17:24 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
2012-01-13 03:05:50 +00:00
|
|
|
#include <QtGui/QFontDatabase>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#include <qrawfont.h>
|
|
|
|
#include <private/qrawfont_p.h>
|
|
|
|
|
|
|
|
class tst_QRawFont: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
#if !defined(QT_NO_RAWFONT)
|
|
|
|
private slots:
|
2011-08-17 23:24:09 +00:00
|
|
|
void init();
|
2012-01-13 03:05:50 +00:00
|
|
|
void initTestCase();
|
2011-08-17 23:24:09 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void invalidRawFont();
|
|
|
|
|
|
|
|
void explicitRawFontNotLoadedInDatabase_data();
|
|
|
|
void explicitRawFontNotLoadedInDatabase();
|
|
|
|
|
|
|
|
void explicitRawFontNotAvailableInSystem_data();
|
|
|
|
void explicitRawFontNotAvailableInSystem();
|
|
|
|
|
|
|
|
void correctFontData_data();
|
|
|
|
void correctFontData();
|
|
|
|
|
|
|
|
void glyphIndices();
|
|
|
|
|
|
|
|
void advances_data();
|
|
|
|
void advances();
|
|
|
|
|
|
|
|
void textLayout();
|
|
|
|
|
|
|
|
void fontTable_data();
|
|
|
|
void fontTable();
|
|
|
|
|
|
|
|
void supportedWritingSystems_data();
|
|
|
|
void supportedWritingSystems();
|
|
|
|
|
|
|
|
void supportsCharacter_data();
|
|
|
|
void supportsCharacter();
|
|
|
|
|
|
|
|
void supportsUcs4Character_data();
|
|
|
|
void supportsUcs4Character();
|
|
|
|
|
|
|
|
void fromFont_data();
|
|
|
|
void fromFont();
|
|
|
|
|
|
|
|
void copyConstructor_data();
|
|
|
|
void copyConstructor();
|
|
|
|
|
|
|
|
void detach_data();
|
|
|
|
void detach();
|
|
|
|
|
|
|
|
void unsupportedWritingSystem_data();
|
|
|
|
void unsupportedWritingSystem();
|
2011-05-06 13:45:37 +00:00
|
|
|
|
|
|
|
void rawFontSetPixelSize_data();
|
|
|
|
void rawFontSetPixelSize();
|
2011-07-19 16:36:05 +00:00
|
|
|
|
|
|
|
void multipleRawFontsFromData();
|
2014-05-12 07:09:24 +00:00
|
|
|
|
|
|
|
void rawFontFromInvalidData();
|
2012-01-13 03:05:50 +00:00
|
|
|
private:
|
|
|
|
QString testFont;
|
|
|
|
QString testFontBoldItalic;
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif // QT_NO_RAWFONT
|
|
|
|
};
|
|
|
|
|
|
|
|
#if !defined(QT_NO_RAWFONT)
|
|
|
|
Q_DECLARE_METATYPE(QFont::HintingPreference)
|
|
|
|
Q_DECLARE_METATYPE(QFont::Style)
|
|
|
|
Q_DECLARE_METATYPE(QFont::Weight)
|
|
|
|
Q_DECLARE_METATYPE(QFontDatabase::WritingSystem)
|
|
|
|
|
2011-08-17 23:24:09 +00:00
|
|
|
void tst_QRawFont::init()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-01-13 03:05:50 +00:00
|
|
|
void tst_QRawFont::initTestCase()
|
|
|
|
{
|
|
|
|
testFont = QFINDTESTDATA("testfont.ttf");
|
|
|
|
testFontBoldItalic = QFINDTESTDATA("testfont_bold_italic.ttf");
|
|
|
|
if (testFont.isEmpty() || testFontBoldItalic.isEmpty())
|
|
|
|
QFAIL("qrawfont unittest font files not found!");
|
|
|
|
|
|
|
|
QFontDatabase database;
|
|
|
|
if (database.families().count() == 0)
|
|
|
|
QSKIP("No fonts available!!!");
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_QRawFont::invalidRawFont()
|
|
|
|
{
|
|
|
|
QRawFont font;
|
|
|
|
QVERIFY(!font.isValid());
|
2011-05-02 08:06:44 +00:00
|
|
|
QCOMPARE(font.pixelSize(), 0.0);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(font.familyName().isEmpty());
|
|
|
|
QCOMPARE(font.style(), QFont::StyleNormal);
|
|
|
|
QCOMPARE(font.weight(), -1);
|
|
|
|
QCOMPARE(font.ascent(), 0.0);
|
|
|
|
QCOMPARE(font.descent(), 0.0);
|
|
|
|
QVERIFY(font.glyphIndexesForString(QLatin1String("Test")).isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::explicitRawFontNotLoadedInDatabase_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
|
|
|
|
|
|
|
|
QTest::newRow("Default hinting preference") << QFont::PreferDefaultHinting;
|
|
|
|
QTest::newRow("No hinting") << QFont::PreferNoHinting;
|
|
|
|
QTest::newRow("Vertical hinting") << QFont::PreferVerticalHinting;
|
|
|
|
QTest::newRow("Full hinting") << QFont::PreferFullHinting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::explicitRawFontNotLoadedInDatabase()
|
|
|
|
{
|
|
|
|
QFETCH(QFont::HintingPreference, hintingPreference);
|
|
|
|
|
2012-01-13 03:05:50 +00:00
|
|
|
QRawFont font(testFont, 10, hintingPreference);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(font.isValid());
|
|
|
|
|
|
|
|
QVERIFY(!QFontDatabase().families().contains(font.familyName()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::explicitRawFontNotAvailableInSystem_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
|
|
|
|
|
|
|
|
QTest::newRow("Default hinting preference") << QFont::PreferDefaultHinting;
|
|
|
|
QTest::newRow("No hinting") << QFont::PreferNoHinting;
|
|
|
|
QTest::newRow("Vertical hinting") << QFont::PreferVerticalHinting;
|
|
|
|
QTest::newRow("Full hinting") << QFont::PreferFullHinting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::explicitRawFontNotAvailableInSystem()
|
|
|
|
{
|
|
|
|
QFETCH(QFont::HintingPreference, hintingPreference);
|
|
|
|
|
2012-01-13 03:05:50 +00:00
|
|
|
QRawFont rawfont(testFont, 10, hintingPreference);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
QFont font(rawfont.familyName(), 10);
|
|
|
|
|
|
|
|
QVERIFY(!font.exactMatch());
|
|
|
|
QVERIFY(font.family() != QFontInfo(font).family());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::correctFontData_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("fileName");
|
|
|
|
QTest::addColumn<QString>("expectedFamilyName");
|
|
|
|
QTest::addColumn<QFont::Style>("style");
|
|
|
|
QTest::addColumn<QFont::Weight>("weight");
|
|
|
|
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
|
|
|
|
QTest::addColumn<qreal>("unitsPerEm");
|
2011-05-02 08:06:44 +00:00
|
|
|
QTest::addColumn<qreal>("pixelSize");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
int hintingPreferences[] = {
|
|
|
|
int(QFont::PreferDefaultHinting),
|
|
|
|
int(QFont::PreferNoHinting),
|
|
|
|
int(QFont::PreferVerticalHinting),
|
|
|
|
int(QFont::PreferFullHinting),
|
|
|
|
-1
|
|
|
|
};
|
|
|
|
int *hintingPreference = hintingPreferences;
|
|
|
|
|
|
|
|
while (*hintingPreference >= 0) {
|
2012-01-13 03:05:50 +00:00
|
|
|
QString fileName = testFont;
|
2011-04-27 10:05:43 +00:00
|
|
|
QString title = fileName
|
|
|
|
+ QLatin1String(": hintingPreference=")
|
|
|
|
+ QString::number(*hintingPreference);
|
|
|
|
|
|
|
|
QTest::newRow(qPrintable(title))
|
|
|
|
<< fileName
|
|
|
|
<< QString::fromLatin1("QtBidiTestFont")
|
|
|
|
<< QFont::StyleNormal
|
|
|
|
<< QFont::Normal
|
|
|
|
<< QFont::HintingPreference(*hintingPreference)
|
2013-06-17 10:01:00 +00:00
|
|
|
<< qreal(1000.0)
|
|
|
|
<< qreal(10.0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-01-13 03:05:50 +00:00
|
|
|
fileName = testFontBoldItalic;
|
2011-04-27 10:05:43 +00:00
|
|
|
title = fileName
|
|
|
|
+ QLatin1String(": hintingPreference=")
|
|
|
|
+ QString::number(*hintingPreference);
|
|
|
|
|
|
|
|
QTest::newRow(qPrintable(title))
|
|
|
|
<< fileName
|
|
|
|
<< QString::fromLatin1("QtBidiTestFont")
|
|
|
|
<< QFont::StyleItalic
|
|
|
|
<< QFont::Bold
|
|
|
|
<< QFont::HintingPreference(*hintingPreference)
|
2013-06-17 10:01:00 +00:00
|
|
|
<< qreal(1000.0)
|
|
|
|
<< qreal(10.0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
++hintingPreference;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::correctFontData()
|
|
|
|
{
|
|
|
|
QFETCH(QString, fileName);
|
|
|
|
QFETCH(QString, expectedFamilyName);
|
|
|
|
QFETCH(QFont::Style, style);
|
|
|
|
QFETCH(QFont::Weight, weight);
|
|
|
|
QFETCH(QFont::HintingPreference, hintingPreference);
|
|
|
|
QFETCH(qreal, unitsPerEm);
|
2011-05-02 08:06:44 +00:00
|
|
|
QFETCH(qreal, pixelSize);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QRawFont font(fileName, 10, hintingPreference);
|
|
|
|
QVERIFY(font.isValid());
|
|
|
|
|
|
|
|
QCOMPARE(font.familyName(), expectedFamilyName);
|
|
|
|
QCOMPARE(font.style(), style);
|
|
|
|
QCOMPARE(font.weight(), int(weight));
|
|
|
|
QCOMPARE(font.hintingPreference(), hintingPreference);
|
|
|
|
QCOMPARE(font.unitsPerEm(), unitsPerEm);
|
|
|
|
QCOMPARE(font.pixelSize(), pixelSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::glyphIndices()
|
|
|
|
{
|
2012-01-13 03:05:50 +00:00
|
|
|
QRawFont font(testFont, 10);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(font.isValid());
|
|
|
|
|
|
|
|
QVector<quint32> glyphIndices = font.glyphIndexesForString(QLatin1String("Foobar"));
|
|
|
|
QVector<quint32> expectedGlyphIndices;
|
|
|
|
expectedGlyphIndices << 44 << 83 << 83 << 70 << 69 << 86;
|
|
|
|
|
|
|
|
QCOMPARE(glyphIndices, expectedGlyphIndices);
|
2012-10-11 13:19:34 +00:00
|
|
|
|
|
|
|
glyphIndices = font.glyphIndexesForString(QString());
|
|
|
|
QVERIFY(glyphIndices.isEmpty());
|
|
|
|
|
|
|
|
QString str(QLatin1String("Foobar"));
|
|
|
|
int numGlyphs = str.size();
|
|
|
|
glyphIndices.resize(numGlyphs);
|
|
|
|
|
|
|
|
QVERIFY(!font.glyphIndexesForChars(str.constData(), 0, glyphIndices.data(), &numGlyphs));
|
|
|
|
QCOMPARE(numGlyphs, 0);
|
|
|
|
|
|
|
|
QVERIFY(!font.glyphIndexesForChars(str.constData(), str.size(), glyphIndices.data(), &numGlyphs));
|
|
|
|
QCOMPARE(numGlyphs, str.size());
|
|
|
|
|
|
|
|
QVERIFY(font.glyphIndexesForChars(str.constData(), str.size(), glyphIndices.data(), &numGlyphs));
|
|
|
|
QCOMPARE(numGlyphs, str.size());
|
|
|
|
|
|
|
|
QCOMPARE(glyphIndices, expectedGlyphIndices);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::advances_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
|
|
|
|
|
|
|
|
QTest::newRow("Default hinting preference") << QFont::PreferDefaultHinting;
|
|
|
|
QTest::newRow("No hinting") << QFont::PreferNoHinting;
|
|
|
|
QTest::newRow("Vertical hinting") << QFont::PreferVerticalHinting;
|
|
|
|
QTest::newRow("Full hinting") << QFont::PreferFullHinting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::advances()
|
|
|
|
{
|
|
|
|
QFETCH(QFont::HintingPreference, hintingPreference);
|
|
|
|
|
2012-01-13 03:05:50 +00:00
|
|
|
QRawFont font(testFont, 10, hintingPreference);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(font.isValid());
|
|
|
|
|
|
|
|
QRawFontPrivate *font_d = QRawFontPrivate::get(font);
|
|
|
|
QVERIFY(font_d->fontEngine != 0);
|
|
|
|
|
|
|
|
QVector<quint32> glyphIndices;
|
|
|
|
glyphIndices << 44 << 83 << 83 << 70 << 69 << 86; // "Foobar"
|
|
|
|
|
|
|
|
bool supportsSubPixelPositions = font_d->fontEngine->supportsSubPixelPositions();
|
|
|
|
QVector<QPointF> advances = font.advancesForGlyphIndexes(glyphIndices);
|
|
|
|
for (int i=0; i<glyphIndices.size(); ++i) {
|
2012-04-24 10:06:33 +00:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
// In Windows, freetype engine returns advance of 9 when full hinting is used (default) for
|
|
|
|
// some of the glyphs.
|
|
|
|
if (font_d->fontEngine->type() == QFontEngine::Freetype
|
|
|
|
&& (hintingPreference == QFont::PreferFullHinting || hintingPreference == QFont::PreferDefaultHinting)
|
|
|
|
&& (i == 0 || i == 5)) {
|
|
|
|
QEXPECT_FAIL("", "Advance for some glyphs is not the expected with Windows Freetype engine (9 instead of 8)", Continue);
|
|
|
|
}
|
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(qFuzzyCompare(qRound(advances.at(i).x()), 8.0));
|
|
|
|
if (supportsSubPixelPositions)
|
|
|
|
QVERIFY(advances.at(i).x() > 8.0);
|
|
|
|
|
|
|
|
QVERIFY(qFuzzyIsNull(advances.at(i).y()));
|
|
|
|
}
|
2012-10-11 13:19:34 +00:00
|
|
|
|
|
|
|
advances = font.advancesForGlyphIndexes(QVector<quint32>());
|
|
|
|
QVERIFY(advances.isEmpty());
|
|
|
|
|
|
|
|
int numGlyphs = glyphIndices.size();
|
|
|
|
advances.resize(numGlyphs);
|
|
|
|
|
|
|
|
QVERIFY(!font.advancesForGlyphIndexes(glyphIndices.constData(), advances.data(), 0));
|
|
|
|
|
|
|
|
QVERIFY(font.advancesForGlyphIndexes(glyphIndices.constData(), advances.data(), numGlyphs));
|
|
|
|
|
|
|
|
for (int i=0; i<glyphIndices.size(); ++i) {
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
// In Windows, freetype engine returns advance of 9 when full hinting is used (default) for
|
|
|
|
// some of the glyphs.
|
|
|
|
if (font_d->fontEngine->type() == QFontEngine::Freetype
|
|
|
|
&& (hintingPreference == QFont::PreferFullHinting || hintingPreference == QFont::PreferDefaultHinting)
|
|
|
|
&& (i == 0 || i == 5)) {
|
|
|
|
QEXPECT_FAIL("", "Advance for some glyphs is not the expected with Windows Freetype engine (9 instead of 8)", Continue);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
QVERIFY(qFuzzyCompare(qRound(advances.at(i).x()), 8.0));
|
|
|
|
if (supportsSubPixelPositions)
|
|
|
|
QVERIFY(advances.at(i).x() > 8.0);
|
|
|
|
|
|
|
|
QVERIFY(qFuzzyIsNull(advances.at(i).y()));
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::textLayout()
|
|
|
|
{
|
|
|
|
QFontDatabase fontDatabase;
|
2012-01-13 03:05:50 +00:00
|
|
|
int id = fontDatabase.addApplicationFont(testFont);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(id >= 0);
|
|
|
|
|
|
|
|
QString familyName = QString::fromLatin1("QtBidiTestFont");
|
|
|
|
QFont font(familyName);
|
2011-05-02 08:06:44 +00:00
|
|
|
font.setPixelSize(18.0);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(QFontInfo(font).family(), familyName);
|
|
|
|
|
|
|
|
QTextLayout layout(QLatin1String("Foobar"));
|
|
|
|
layout.setFont(font);
|
2012-05-15 17:02:53 +00:00
|
|
|
layout.setCacheEnabled(true);
|
2011-04-27 10:05:43 +00:00
|
|
|
layout.beginLayout();
|
|
|
|
layout.createLine();
|
|
|
|
layout.endLayout();
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QList<QGlyphRun> glyphRuns = layout.glyphRuns();
|
|
|
|
QCOMPARE(glyphRuns.size(), 1);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun glyphs = glyphRuns.at(0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QRawFont rawFont = glyphs.rawFont();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(rawFont.isValid());
|
|
|
|
QCOMPARE(rawFont.familyName(), familyName);
|
2011-05-02 08:06:44 +00:00
|
|
|
QCOMPARE(rawFont.pixelSize(), 18.0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QVector<quint32> expectedGlyphIndices;
|
|
|
|
expectedGlyphIndices << 44 << 83 << 83 << 70 << 69 << 86;
|
|
|
|
|
|
|
|
QCOMPARE(glyphs.glyphIndexes(), expectedGlyphIndices);
|
|
|
|
|
|
|
|
QVERIFY(fontDatabase.removeApplicationFont(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::fontTable_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QByteArray>("tagName");
|
|
|
|
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
|
|
|
|
QTest::addColumn<int>("offset");
|
|
|
|
QTest::addColumn<quint32>("expectedValue");
|
|
|
|
|
|
|
|
QTest::newRow("Head table, magic number, default hinting")
|
|
|
|
<< QByteArray("head")
|
|
|
|
<< QFont::PreferDefaultHinting
|
|
|
|
<< 12
|
|
|
|
<< (QSysInfo::ByteOrder == QSysInfo::BigEndian
|
|
|
|
? 0x5F0F3CF5
|
|
|
|
: 0xF53C0F5F);
|
|
|
|
|
|
|
|
QTest::newRow("Head table, magic number, no hinting")
|
|
|
|
<< QByteArray("head")
|
|
|
|
<< QFont::PreferNoHinting
|
|
|
|
<< 12
|
|
|
|
<< (QSysInfo::ByteOrder == QSysInfo::BigEndian
|
|
|
|
? 0x5F0F3CF5
|
|
|
|
: 0xF53C0F5F);
|
|
|
|
|
|
|
|
QTest::newRow("Head table, magic number, vertical hinting")
|
|
|
|
<< QByteArray("head")
|
|
|
|
<< QFont::PreferVerticalHinting
|
|
|
|
<< 12
|
|
|
|
<< (QSysInfo::ByteOrder == QSysInfo::BigEndian
|
|
|
|
? 0x5F0F3CF5
|
|
|
|
: 0xF53C0F5F);
|
|
|
|
|
|
|
|
QTest::newRow("Head table, magic number, full hinting")
|
|
|
|
<< QByteArray("head")
|
|
|
|
<< QFont::PreferFullHinting
|
|
|
|
<< 12
|
|
|
|
<< (QSysInfo::ByteOrder == QSysInfo::BigEndian
|
|
|
|
? 0x5F0F3CF5
|
|
|
|
: 0xF53C0F5F);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::fontTable()
|
|
|
|
{
|
|
|
|
QFETCH(QByteArray, tagName);
|
|
|
|
QFETCH(QFont::HintingPreference, hintingPreference);
|
|
|
|
QFETCH(int, offset);
|
|
|
|
QFETCH(quint32, expectedValue);
|
|
|
|
|
2012-01-13 03:05:50 +00:00
|
|
|
QRawFont font(testFont, 10, hintingPreference);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(font.isValid());
|
|
|
|
|
|
|
|
QByteArray table = font.fontTable(tagName);
|
|
|
|
QVERIFY(!table.isEmpty());
|
|
|
|
|
|
|
|
const quint32 *value = reinterpret_cast<const quint32 *>(table.constData() + offset);
|
|
|
|
QCOMPARE(*value, expectedValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef QList<QFontDatabase::WritingSystem> WritingSystemList;
|
|
|
|
Q_DECLARE_METATYPE(WritingSystemList)
|
|
|
|
|
|
|
|
void tst_QRawFont::supportedWritingSystems_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("fileName");
|
|
|
|
QTest::addColumn<WritingSystemList>("writingSystems");
|
|
|
|
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
|
|
|
|
|
|
|
|
for (int hintingPreference=QFont::PreferDefaultHinting;
|
|
|
|
hintingPreference<=QFont::PreferFullHinting;
|
|
|
|
++hintingPreference) {
|
|
|
|
|
|
|
|
QTest::newRow(qPrintable(QString::fromLatin1("testfont.ttf, hintingPreference=%1")
|
|
|
|
.arg(hintingPreference)))
|
2012-01-13 03:05:50 +00:00
|
|
|
<< testFont
|
2011-04-27 10:05:43 +00:00
|
|
|
<< (QList<QFontDatabase::WritingSystem>()
|
|
|
|
<< QFontDatabase::Latin
|
|
|
|
<< QFontDatabase::Hebrew
|
|
|
|
<< QFontDatabase::Vietnamese) // Vietnamese uses same unicode bits as Latin
|
|
|
|
<< QFont::HintingPreference(hintingPreference);
|
|
|
|
|
|
|
|
QTest::newRow(qPrintable(QString::fromLatin1("testfont_bold_italic.ttf, hintingPreference=%1")
|
|
|
|
.arg(hintingPreference)))
|
2012-01-13 03:05:50 +00:00
|
|
|
<< testFontBoldItalic
|
2011-04-27 10:05:43 +00:00
|
|
|
<< (QList<QFontDatabase::WritingSystem>()
|
|
|
|
<< QFontDatabase::Latin
|
|
|
|
<< QFontDatabase::Hebrew
|
|
|
|
<< QFontDatabase::Devanagari
|
|
|
|
<< QFontDatabase::Vietnamese) // Vietnamese uses same unicode bits as Latin
|
|
|
|
<< QFont::HintingPreference(hintingPreference);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::supportedWritingSystems()
|
|
|
|
{
|
|
|
|
QFETCH(QString, fileName);
|
|
|
|
QFETCH(WritingSystemList, writingSystems);
|
|
|
|
QFETCH(QFont::HintingPreference, hintingPreference);
|
|
|
|
|
|
|
|
QRawFont font(fileName, 10, hintingPreference);
|
|
|
|
QVERIFY(font.isValid());
|
|
|
|
|
|
|
|
WritingSystemList actualWritingSystems = font.supportedWritingSystems();
|
|
|
|
QCOMPARE(actualWritingSystems.size(), writingSystems.size());
|
|
|
|
|
|
|
|
foreach (QFontDatabase::WritingSystem writingSystem, writingSystems)
|
|
|
|
QVERIFY(actualWritingSystems.contains(writingSystem));
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::supportsCharacter_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("fileName");
|
|
|
|
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
|
|
|
|
QTest::addColumn<QChar>("character");
|
|
|
|
QTest::addColumn<bool>("shouldBeSupported");
|
|
|
|
|
|
|
|
const char *fileNames[2] = {
|
2012-01-13 03:05:50 +00:00
|
|
|
"testfont.ttf",
|
|
|
|
"testfont_bold_italic.ttf"
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (int hintingPreference=QFont::PreferDefaultHinting;
|
|
|
|
hintingPreference<=QFont::PreferFullHinting;
|
|
|
|
++hintingPreference) {
|
|
|
|
|
|
|
|
for (int i=0; i<2; ++i) {
|
2012-01-13 03:05:50 +00:00
|
|
|
QString fileName = QFINDTESTDATA(fileNames[i]);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// Latin text
|
|
|
|
for (char ch='!'; ch<='~'; ++ch) {
|
|
|
|
QString title = QString::fromLatin1("%1, character=0x%2, hintingPreference=%3")
|
|
|
|
.arg(fileName).arg(QString::number(ch, 16)).arg(hintingPreference);
|
|
|
|
|
|
|
|
QTest::newRow(qPrintable(title))
|
|
|
|
<< fileName
|
|
|
|
<< QFont::HintingPreference(hintingPreference)
|
|
|
|
<< QChar::fromLatin1(ch)
|
|
|
|
<< true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hebrew text
|
|
|
|
for (quint16 ch=0x05D0; ch<=0x05EA; ++ch) {
|
|
|
|
QString title = QString::fromLatin1("%1, character=0x%2, hintingPreference=%3")
|
|
|
|
.arg(fileName).arg(QString::number(ch, 16)).arg(hintingPreference);
|
|
|
|
|
|
|
|
QTest::newRow(qPrintable(title))
|
|
|
|
<< fileName
|
|
|
|
<< QFont::HintingPreference(hintingPreference)
|
|
|
|
<< QChar(ch)
|
|
|
|
<< true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTest::newRow(qPrintable(QString::fromLatin1("Missing character, %1, hintingPreference=%2")
|
|
|
|
.arg(fileName).arg(hintingPreference)))
|
|
|
|
<< fileName
|
|
|
|
<< QFont::HintingPreference(hintingPreference)
|
|
|
|
<< QChar(0xD8)
|
|
|
|
<< false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::supportsCharacter()
|
|
|
|
{
|
|
|
|
QFETCH(QString, fileName);
|
|
|
|
QFETCH(QFont::HintingPreference, hintingPreference);
|
|
|
|
QFETCH(QChar, character);
|
|
|
|
QFETCH(bool, shouldBeSupported);
|
|
|
|
|
|
|
|
QRawFont font(fileName, 10, hintingPreference);
|
|
|
|
QVERIFY(font.isValid());
|
|
|
|
|
|
|
|
QCOMPARE(font.supportsCharacter(character), shouldBeSupported);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::supportsUcs4Character_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("fileName");
|
|
|
|
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
|
|
|
|
QTest::addColumn<quint32>("ucs4");
|
|
|
|
QTest::addColumn<bool>("shouldBeSupported");
|
|
|
|
|
|
|
|
// Gothic text
|
|
|
|
for (int hintingPreference=QFont::PreferDefaultHinting;
|
|
|
|
hintingPreference<=QFont::PreferFullHinting;
|
|
|
|
++hintingPreference) {
|
|
|
|
for (quint32 ch=0x10330; ch<=0x1034A; ++ch) {
|
|
|
|
{
|
2012-01-13 03:05:50 +00:00
|
|
|
QString fileName = testFont;
|
2011-04-27 10:05:43 +00:00
|
|
|
QString title = QString::fromLatin1("%1, character=0x%2, hintingPreference=%3")
|
|
|
|
.arg(fileName).arg(QString::number(ch, 16)).arg(hintingPreference);
|
|
|
|
|
|
|
|
QTest::newRow(qPrintable(title))
|
|
|
|
<< fileName
|
|
|
|
<< QFont::HintingPreference(hintingPreference)
|
|
|
|
<< ch
|
|
|
|
<< true;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2012-01-13 03:05:50 +00:00
|
|
|
QString fileName = testFontBoldItalic;
|
2011-04-27 10:05:43 +00:00
|
|
|
QString title = QString::fromLatin1("%1, character=0x%2, hintingPreference=%3")
|
|
|
|
.arg(fileName).arg(QString::number(ch, 16)).arg(hintingPreference);
|
|
|
|
|
|
|
|
QTest::newRow(qPrintable(title))
|
|
|
|
<< fileName
|
|
|
|
<< QFont::HintingPreference(hintingPreference)
|
|
|
|
<< ch
|
|
|
|
<< false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::supportsUcs4Character()
|
|
|
|
{
|
|
|
|
QFETCH(QString, fileName);
|
|
|
|
QFETCH(QFont::HintingPreference, hintingPreference);
|
|
|
|
QFETCH(quint32, ucs4);
|
|
|
|
QFETCH(bool, shouldBeSupported);
|
|
|
|
|
|
|
|
QRawFont font(fileName, 10, hintingPreference);
|
|
|
|
QVERIFY(font.isValid());
|
|
|
|
|
|
|
|
QCOMPARE(font.supportsCharacter(ucs4), shouldBeSupported);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::fromFont_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("fileName");
|
|
|
|
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
|
|
|
|
QTest::addColumn<QString>("familyName");
|
|
|
|
QTest::addColumn<QFontDatabase::WritingSystem>("writingSystem");
|
|
|
|
|
|
|
|
for (int i=QFont::PreferDefaultHinting; i<=QFont::PreferFullHinting; ++i) {
|
|
|
|
QString titleBase = QString::fromLatin1("%2, hintingPreference=%1, writingSystem=%3")
|
|
|
|
.arg(i);
|
|
|
|
{
|
2012-01-13 03:05:50 +00:00
|
|
|
QString fileName = testFont;
|
2011-04-27 10:05:43 +00:00
|
|
|
QFontDatabase::WritingSystem writingSystem = QFontDatabase::Any;
|
|
|
|
|
|
|
|
QString title = titleBase.arg(fileName).arg(writingSystem);
|
|
|
|
QTest::newRow(qPrintable(title))
|
|
|
|
<< fileName
|
|
|
|
<< QFont::HintingPreference(i)
|
|
|
|
<< "QtBidiTestFont"
|
|
|
|
<< writingSystem;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2012-01-13 03:05:50 +00:00
|
|
|
QString fileName = testFont;
|
2011-04-27 10:05:43 +00:00
|
|
|
QFontDatabase::WritingSystem writingSystem = QFontDatabase::Hebrew;
|
|
|
|
|
|
|
|
QString title = titleBase.arg(fileName).arg(writingSystem);
|
|
|
|
QTest::newRow(qPrintable(title))
|
|
|
|
<< fileName
|
|
|
|
<< QFont::HintingPreference(i)
|
|
|
|
<< "QtBidiTestFont"
|
|
|
|
<< writingSystem;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2012-01-13 03:05:50 +00:00
|
|
|
QString fileName = testFont;
|
2011-04-27 10:05:43 +00:00
|
|
|
QFontDatabase::WritingSystem writingSystem = QFontDatabase::Latin;
|
|
|
|
|
|
|
|
QString title = titleBase.arg(fileName).arg(writingSystem);
|
|
|
|
QTest::newRow(qPrintable(title))
|
|
|
|
<< fileName
|
|
|
|
<< QFont::HintingPreference(i)
|
|
|
|
<< "QtBidiTestFont"
|
|
|
|
<< writingSystem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::fromFont()
|
|
|
|
{
|
|
|
|
QFETCH(QString, fileName);
|
|
|
|
QFETCH(QFont::HintingPreference, hintingPreference);
|
|
|
|
QFETCH(QString, familyName);
|
|
|
|
QFETCH(QFontDatabase::WritingSystem, writingSystem);
|
|
|
|
|
|
|
|
QFontDatabase fontDatabase;
|
|
|
|
int id = fontDatabase.addApplicationFont(fileName);
|
|
|
|
QVERIFY(id >= 0);
|
|
|
|
|
|
|
|
QFont font(familyName);
|
|
|
|
font.setHintingPreference(hintingPreference);
|
2011-05-02 08:06:44 +00:00
|
|
|
font.setPixelSize(26.0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QRawFont rawFont = QRawFont::fromFont(font, writingSystem);
|
|
|
|
QVERIFY(rawFont.isValid());
|
2011-08-17 23:24:09 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(rawFont.familyName(), familyName);
|
2011-05-02 08:06:44 +00:00
|
|
|
QCOMPARE(rawFont.pixelSize(), 26.0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QVERIFY(fontDatabase.removeApplicationFont(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::copyConstructor_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
|
|
|
|
|
|
|
|
QTest::newRow("Default hinting preference") << QFont::PreferDefaultHinting;
|
|
|
|
QTest::newRow("No hinting preference") << QFont::PreferNoHinting;
|
|
|
|
QTest::newRow("Vertical hinting preference") << QFont::PreferVerticalHinting;
|
|
|
|
QTest::newRow("Full hinting preference") << QFont::PreferFullHinting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::copyConstructor()
|
|
|
|
{
|
|
|
|
QFETCH(QFont::HintingPreference, hintingPreference);
|
|
|
|
|
|
|
|
{
|
|
|
|
QString rawFontFamilyName;
|
2011-05-02 08:06:44 +00:00
|
|
|
qreal rawFontPixelSize;
|
2011-04-27 10:05:43 +00:00
|
|
|
qreal rawFontAscent;
|
|
|
|
qreal rawFontDescent;
|
|
|
|
int rawFontTableSize;
|
|
|
|
|
|
|
|
QRawFont outerRawFont;
|
|
|
|
{
|
2012-01-13 03:05:50 +00:00
|
|
|
QRawFont rawFont(testFont, 11, hintingPreference);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(rawFont.isValid());
|
|
|
|
|
|
|
|
rawFontFamilyName = rawFont.familyName();
|
|
|
|
rawFontPixelSize = rawFont.pixelSize();
|
|
|
|
rawFontAscent = rawFont.ascent();
|
|
|
|
rawFontDescent = rawFont.descent();
|
|
|
|
rawFontTableSize = rawFont.fontTable("glyf").size();
|
|
|
|
QVERIFY(rawFontTableSize > 0);
|
|
|
|
|
|
|
|
{
|
|
|
|
QRawFont otherRawFont(rawFont);
|
|
|
|
QVERIFY(otherRawFont.isValid());
|
|
|
|
QCOMPARE(otherRawFont.pixelSize(), rawFontPixelSize);
|
|
|
|
QCOMPARE(otherRawFont.familyName(), rawFontFamilyName);
|
|
|
|
QCOMPARE(otherRawFont.hintingPreference(), hintingPreference);
|
|
|
|
QCOMPARE(otherRawFont.ascent(), rawFontAscent);
|
|
|
|
QCOMPARE(otherRawFont.descent(), rawFontDescent);
|
|
|
|
QCOMPARE(otherRawFont.fontTable("glyf").size(), rawFontTableSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
QRawFont otherRawFont = rawFont;
|
|
|
|
QVERIFY(otherRawFont.isValid());
|
|
|
|
QCOMPARE(otherRawFont.pixelSize(), rawFontPixelSize);
|
|
|
|
QCOMPARE(otherRawFont.familyName(), rawFontFamilyName);
|
|
|
|
QCOMPARE(otherRawFont.hintingPreference(), hintingPreference);
|
|
|
|
QCOMPARE(otherRawFont.ascent(), rawFontAscent);
|
|
|
|
QCOMPARE(otherRawFont.descent(), rawFontDescent);
|
|
|
|
QCOMPARE(otherRawFont.fontTable("glyf").size(), rawFontTableSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
outerRawFont = rawFont;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVERIFY(outerRawFont.isValid());
|
|
|
|
QCOMPARE(outerRawFont.pixelSize(), rawFontPixelSize);
|
|
|
|
QCOMPARE(outerRawFont.familyName(), rawFontFamilyName);
|
|
|
|
QCOMPARE(outerRawFont.hintingPreference(), hintingPreference);
|
|
|
|
QCOMPARE(outerRawFont.ascent(), rawFontAscent);
|
|
|
|
QCOMPARE(outerRawFont.descent(), rawFontDescent);
|
|
|
|
QCOMPARE(outerRawFont.fontTable("glyf").size(), rawFontTableSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::detach_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
|
|
|
|
|
|
|
|
QTest::newRow("Default hinting preference") << QFont::PreferDefaultHinting;
|
|
|
|
QTest::newRow("No hinting preference") << QFont::PreferNoHinting;
|
|
|
|
QTest::newRow("Vertical hinting preference") << QFont::PreferVerticalHinting;
|
|
|
|
QTest::newRow("Full hinting preference") << QFont::PreferFullHinting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::detach()
|
|
|
|
{
|
|
|
|
QFETCH(QFont::HintingPreference, hintingPreference);
|
|
|
|
|
|
|
|
{
|
|
|
|
QString rawFontFamilyName;
|
2011-05-02 08:06:44 +00:00
|
|
|
qreal rawFontPixelSize;
|
2011-04-27 10:05:43 +00:00
|
|
|
qreal rawFontAscent;
|
|
|
|
qreal rawFontDescent;
|
|
|
|
int rawFontTableSize;
|
|
|
|
|
|
|
|
QRawFont outerRawFont;
|
|
|
|
{
|
2012-01-13 03:05:50 +00:00
|
|
|
QRawFont rawFont(testFont, 11, hintingPreference);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(rawFont.isValid());
|
|
|
|
|
|
|
|
rawFontFamilyName = rawFont.familyName();
|
|
|
|
rawFontPixelSize = rawFont.pixelSize();
|
|
|
|
rawFontAscent = rawFont.ascent();
|
|
|
|
rawFontDescent = rawFont.descent();
|
|
|
|
rawFontTableSize = rawFont.fontTable("glyf").size();
|
|
|
|
QVERIFY(rawFontTableSize > 0);
|
|
|
|
|
|
|
|
{
|
|
|
|
QRawFont otherRawFont(rawFont);
|
|
|
|
|
2012-01-13 03:05:50 +00:00
|
|
|
otherRawFont.loadFromFile(testFont, rawFontPixelSize, hintingPreference);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QVERIFY(otherRawFont.isValid());
|
|
|
|
QCOMPARE(otherRawFont.pixelSize(), rawFontPixelSize);
|
|
|
|
QCOMPARE(otherRawFont.familyName(), rawFontFamilyName);
|
|
|
|
QCOMPARE(otherRawFont.hintingPreference(), hintingPreference);
|
|
|
|
QCOMPARE(otherRawFont.ascent(), rawFontAscent);
|
|
|
|
QCOMPARE(otherRawFont.descent(), rawFontDescent);
|
|
|
|
QCOMPARE(otherRawFont.fontTable("glyf").size(), rawFontTableSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
QRawFont otherRawFont = rawFont;
|
|
|
|
|
2012-01-13 03:05:50 +00:00
|
|
|
otherRawFont.loadFromFile(testFont, rawFontPixelSize, hintingPreference);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QVERIFY(otherRawFont.isValid());
|
|
|
|
QCOMPARE(otherRawFont.pixelSize(), rawFontPixelSize);
|
|
|
|
QCOMPARE(otherRawFont.familyName(), rawFontFamilyName);
|
|
|
|
QCOMPARE(otherRawFont.hintingPreference(), hintingPreference);
|
|
|
|
QCOMPARE(otherRawFont.ascent(), rawFontAscent);
|
|
|
|
QCOMPARE(otherRawFont.descent(), rawFontDescent);
|
|
|
|
QCOMPARE(otherRawFont.fontTable("glyf").size(), rawFontTableSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
outerRawFont = rawFont;
|
|
|
|
|
2012-01-13 03:05:50 +00:00
|
|
|
rawFont.loadFromFile(testFont, rawFontPixelSize, hintingPreference);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVERIFY(outerRawFont.isValid());
|
|
|
|
QCOMPARE(outerRawFont.pixelSize(), rawFontPixelSize);
|
|
|
|
QCOMPARE(outerRawFont.familyName(), rawFontFamilyName);
|
|
|
|
QCOMPARE(outerRawFont.hintingPreference(), hintingPreference);
|
|
|
|
QCOMPARE(outerRawFont.ascent(), rawFontAscent);
|
|
|
|
QCOMPARE(outerRawFont.descent(), rawFontDescent);
|
|
|
|
QCOMPARE(outerRawFont.fontTable("glyf").size(), rawFontTableSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::unsupportedWritingSystem_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
|
|
|
|
|
|
|
|
QTest::newRow("Default hinting preference") << QFont::PreferDefaultHinting;
|
|
|
|
QTest::newRow("No hinting preference") << QFont::PreferNoHinting;
|
|
|
|
QTest::newRow("Vertical hinting preference") << QFont::PreferVerticalHinting;
|
|
|
|
QTest::newRow("Full hinting preference") << QFont::PreferFullHinting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::unsupportedWritingSystem()
|
|
|
|
{
|
|
|
|
QFETCH(QFont::HintingPreference, hintingPreference);
|
|
|
|
|
|
|
|
QFontDatabase fontDatabase;
|
2012-01-13 03:05:50 +00:00
|
|
|
int id = fontDatabase.addApplicationFont(testFont);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QFont font("QtBidiTestFont");
|
|
|
|
font.setHintingPreference(hintingPreference);
|
2011-05-02 08:06:44 +00:00
|
|
|
font.setPixelSize(12.0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QRawFont rawFont = QRawFont::fromFont(font, QFontDatabase::Any);
|
|
|
|
QCOMPARE(rawFont.familyName(), QString::fromLatin1("QtBidiTestFont"));
|
2011-05-02 08:06:44 +00:00
|
|
|
QCOMPARE(rawFont.pixelSize(), 12.0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
rawFont = QRawFont::fromFont(font, QFontDatabase::Hebrew);
|
|
|
|
QCOMPARE(rawFont.familyName(), QString::fromLatin1("QtBidiTestFont"));
|
2011-05-02 08:06:44 +00:00
|
|
|
QCOMPARE(rawFont.pixelSize(), 12.0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QString arabicText = QFontDatabase::writingSystemSample(QFontDatabase::Arabic);
|
|
|
|
|
|
|
|
QTextLayout layout;
|
|
|
|
layout.setFont(font);
|
|
|
|
layout.setText(arabicText);
|
2012-05-15 17:02:53 +00:00
|
|
|
layout.setCacheEnabled(true);
|
2011-04-27 10:05:43 +00:00
|
|
|
layout.beginLayout();
|
|
|
|
layout.createLine();
|
|
|
|
layout.endLayout();
|
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QList<QGlyphRun> glyphRuns = layout.glyphRuns();
|
|
|
|
QCOMPARE(glyphRuns.size(), 1);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-05-10 07:43:00 +00:00
|
|
|
QGlyphRun glyphs = glyphRuns.at(0);
|
|
|
|
QRawFont layoutFont = glyphs.rawFont();
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(layoutFont.familyName() != QString::fromLatin1("QtBidiTestFont"));
|
2011-05-02 08:06:44 +00:00
|
|
|
QCOMPARE(layoutFont.pixelSize(), 12.0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
rawFont = QRawFont::fromFont(font, QFontDatabase::Arabic);
|
|
|
|
QCOMPARE(rawFont.familyName(), layoutFont.familyName());
|
2011-05-02 08:06:44 +00:00
|
|
|
QCOMPARE(rawFont.pixelSize(), 12.0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
fontDatabase.removeApplicationFont(id);
|
|
|
|
}
|
|
|
|
|
2011-05-06 13:45:37 +00:00
|
|
|
void tst_QRawFont::rawFontSetPixelSize_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
|
|
|
|
|
|
|
|
QTest::newRow("Default hinting preference") << QFont::PreferDefaultHinting;
|
|
|
|
QTest::newRow("No hinting preference") << QFont::PreferNoHinting;
|
|
|
|
QTest::newRow("Vertical hinting preference") << QFont::PreferVerticalHinting;
|
|
|
|
QTest::newRow("Full hinting preference") << QFont::PreferFullHinting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QRawFont::rawFontSetPixelSize()
|
|
|
|
{
|
|
|
|
QFETCH(QFont::HintingPreference, hintingPreference);
|
|
|
|
|
|
|
|
QTextLayout layout("Foobar");
|
|
|
|
|
|
|
|
QFont font = layout.font();
|
|
|
|
font.setHintingPreference(hintingPreference);
|
|
|
|
font.setPixelSize(12);
|
|
|
|
layout.setFont(font);
|
|
|
|
|
2012-05-15 17:02:53 +00:00
|
|
|
layout.setCacheEnabled(true);
|
2011-05-06 13:45:37 +00:00
|
|
|
layout.beginLayout();
|
|
|
|
layout.createLine();
|
|
|
|
layout.endLayout();
|
|
|
|
|
2011-05-10 23:53:54 +00:00
|
|
|
QGlyphRun glyphs = layout.glyphRuns().at(0);
|
|
|
|
QRawFont rawFont = glyphs.rawFont();
|
2011-05-06 13:45:37 +00:00
|
|
|
QCOMPARE(rawFont.pixelSize(), 12.0);
|
|
|
|
|
|
|
|
rawFont.setPixelSize(24);
|
|
|
|
QCOMPARE(rawFont.pixelSize(), 24.0);
|
|
|
|
}
|
|
|
|
|
2011-07-19 16:36:05 +00:00
|
|
|
void tst_QRawFont::multipleRawFontsFromData()
|
|
|
|
{
|
2012-01-13 03:05:50 +00:00
|
|
|
QFile file(testFont);
|
2011-07-19 16:36:05 +00:00
|
|
|
QRawFont testFont;
|
|
|
|
if (file.open(QIODevice::ReadOnly)) {
|
|
|
|
testFont.loadFromData(file.readAll(), 11, QFont::PreferDefaultHinting);
|
|
|
|
file.close();
|
|
|
|
}
|
2012-01-13 03:05:50 +00:00
|
|
|
file.setFileName(testFontBoldItalic);
|
2011-07-19 16:36:05 +00:00
|
|
|
QRawFont testFontBoldItalic;
|
|
|
|
if (file.open(QIODevice::ReadOnly))
|
|
|
|
testFontBoldItalic.loadFromData(file.readAll(), 11, QFont::PreferDefaultHinting);
|
|
|
|
|
|
|
|
QVERIFY(testFont.familyName() != (testFontBoldItalic.familyName())
|
2012-04-24 10:06:33 +00:00
|
|
|
|| testFont.style() != (testFontBoldItalic.style()));
|
2011-07-19 16:36:05 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 07:09:24 +00:00
|
|
|
void tst_QRawFont::rawFontFromInvalidData()
|
|
|
|
{
|
|
|
|
QByteArray invalidData("foobar");
|
|
|
|
QRawFont font;
|
|
|
|
font.loadFromData(invalidData, 10, QFont::PreferDefaultHinting);
|
|
|
|
|
|
|
|
QVERIFY(!font.isValid());
|
2014-05-15 11:32:27 +00:00
|
|
|
|
|
|
|
invalidData.fill(255, 1024);
|
|
|
|
font.loadFromData(invalidData, 10, QFont::PreferDefaultHinting);
|
|
|
|
|
|
|
|
QVERIFY(!font.isValid());
|
2014-05-12 07:09:24 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif // QT_NO_RAWFONT
|
|
|
|
|
|
|
|
QTEST_MAIN(tst_QRawFont)
|
|
|
|
#include "tst_qrawfont.moc"
|
|
|
|
|