diff --git a/src/gui/text/qrawfont.cpp b/src/gui/text/qrawfont.cpp index 99cd87f1b2..c5a92f95cb 100644 --- a/src/gui/text/qrawfont.cpp +++ b/src/gui/text/qrawfont.cpp @@ -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()); } /*! diff --git a/src/gui/text/qrawfont.h b/src/gui/text/qrawfont.h index ca202d897f..d23d0c1493 100644 --- a/src/gui/text/qrawfont.h +++ b/src/gui/text/qrawfont.h @@ -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); diff --git a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp index 3c45a18ab2..770c43c08e 100644 --- a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp +++ b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp @@ -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;