Adapt QRawFont to use QFont::Tag
Add an overload for fontTable (we can't deprecate the const char * overload as it will be used for string literals, even if the tag- overload would work), and use the tag type in the test instead of QByteArray. Task-number: QTBUG-117046 Change-Id: I104f11a25e9c453a5d1081b6cf320bdc186b7e80 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
parent
19bc5de296
commit
66b5803ab9
@ -632,19 +632,33 @@ QFont::HintingPreference QRawFont::hintingPreference() const
|
||||
}
|
||||
|
||||
/*!
|
||||
Retrieves the sfnt table named \a tagName from the underlying physical font, or an empty
|
||||
byte array if no such table was found. The returned font table's byte order is Big Endian, like
|
||||
the sfnt format specifies. The \a tagName must be four characters long and should be formatted
|
||||
in the default endianness of the current platform.
|
||||
\fn QByteArray QRawFont::fontTable(const char *tag) const
|
||||
\overload fontTable(QFont::Tag)
|
||||
|
||||
The name must be a four-character string.
|
||||
*/
|
||||
QByteArray QRawFont::fontTable(const char *tagName) const
|
||||
|
||||
/*!
|
||||
\fn QByteArray QRawFont::fontTable(QFont::Tag tag) const
|
||||
\since 6.7
|
||||
|
||||
Retrieves the sfnt table specified by \a tag from the underlying physical font,
|
||||
or an empty byte array if no such table was found. The returned font table's byte order is
|
||||
Big Endian, like the sfnt format specifies.
|
||||
*/
|
||||
QByteArray QRawFont::fontTable(const char *tag) const
|
||||
{
|
||||
if (auto maybeTag = QFont::Tag::fromString(tag))
|
||||
return fontTable(*maybeTag);
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
QByteArray QRawFont::fontTable(QFont::Tag tag) const
|
||||
{
|
||||
if (!d->isValid())
|
||||
return QByteArray();
|
||||
|
||||
if (auto maybeTag = QFont::Tag::fromString(tagName))
|
||||
return d->fontEngine->getSfntTable(maybeTag->value());
|
||||
return {};
|
||||
return d->fontEngine->getSfntTable(tag.value());
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -105,6 +105,7 @@ public:
|
||||
QList<QFontDatabase::WritingSystem> supportedWritingSystems() const;
|
||||
|
||||
QByteArray fontTable(const char *tagName) const;
|
||||
QByteArray fontTable(QFont::Tag tag) const;
|
||||
|
||||
static QRawFont fromFont(const QFont &font,
|
||||
QFontDatabase::WritingSystem writingSystem = QFontDatabase::Any);
|
||||
|
@ -398,13 +398,13 @@ void tst_QRawFont::textLayout()
|
||||
|
||||
void tst_QRawFont::fontTable_data()
|
||||
{
|
||||
QTest::addColumn<QByteArray>("tagName");
|
||||
QTest::addColumn<QFont::Tag>("tag");
|
||||
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
|
||||
QTest::addColumn<int>("offset");
|
||||
QTest::addColumn<quint32>("expectedValue");
|
||||
|
||||
QTest::newRow("Head table, magic number, default hinting")
|
||||
<< QByteArray("head")
|
||||
<< QFont::Tag("head")
|
||||
<< QFont::PreferDefaultHinting
|
||||
<< 12
|
||||
<< (QSysInfo::ByteOrder == QSysInfo::BigEndian
|
||||
@ -412,7 +412,7 @@ void tst_QRawFont::fontTable_data()
|
||||
: 0xF53C0F5F);
|
||||
|
||||
QTest::newRow("Head table, magic number, no hinting")
|
||||
<< QByteArray("head")
|
||||
<< QFont::Tag("head")
|
||||
<< QFont::PreferNoHinting
|
||||
<< 12
|
||||
<< (QSysInfo::ByteOrder == QSysInfo::BigEndian
|
||||
@ -420,7 +420,7 @@ void tst_QRawFont::fontTable_data()
|
||||
: 0xF53C0F5F);
|
||||
|
||||
QTest::newRow("Head table, magic number, vertical hinting")
|
||||
<< QByteArray("head")
|
||||
<< QFont::Tag("head")
|
||||
<< QFont::PreferVerticalHinting
|
||||
<< 12
|
||||
<< (QSysInfo::ByteOrder == QSysInfo::BigEndian
|
||||
@ -428,7 +428,7 @@ void tst_QRawFont::fontTable_data()
|
||||
: 0xF53C0F5F);
|
||||
|
||||
QTest::newRow("Head table, magic number, full hinting")
|
||||
<< QByteArray("head")
|
||||
<< QFont::Tag("head")
|
||||
<< QFont::PreferFullHinting
|
||||
<< 12
|
||||
<< (QSysInfo::ByteOrder == QSysInfo::BigEndian
|
||||
@ -438,7 +438,7 @@ void tst_QRawFont::fontTable_data()
|
||||
|
||||
void tst_QRawFont::fontTable()
|
||||
{
|
||||
QFETCH(QByteArray, tagName);
|
||||
QFETCH(QFont::Tag, tag);
|
||||
QFETCH(QFont::HintingPreference, hintingPreference);
|
||||
QFETCH(int, offset);
|
||||
QFETCH(quint32, expectedValue);
|
||||
@ -446,11 +446,13 @@ void tst_QRawFont::fontTable()
|
||||
QRawFont font(testFont, 10, hintingPreference);
|
||||
QVERIFY(font.isValid());
|
||||
|
||||
QByteArray table = font.fontTable(tagName);
|
||||
QByteArray table = font.fontTable(tag);
|
||||
QVERIFY(!table.isEmpty());
|
||||
|
||||
const quint32 *value = reinterpret_cast<const quint32 *>(table.constData() + offset);
|
||||
QCOMPARE(*value, expectedValue);
|
||||
|
||||
QCOMPARE(font.fontTable(tag.toString()), table);
|
||||
}
|
||||
|
||||
typedef QList<QFontDatabase::WritingSystem> WritingSystemList;
|
||||
|
Loading…
Reference in New Issue
Block a user