From 66b5803ab902a2c1937c712a127f93a801ac59a9 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 9 Oct 2023 21:10:54 +0200 Subject: [PATCH] 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 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qrawfont.cpp | 30 ++++++++++++++----- src/gui/text/qrawfont.h | 1 + tests/auto/gui/text/qrawfont/tst_qrawfont.cpp | 16 +++++----- 3 files changed, 32 insertions(+), 15 deletions(-) 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 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("tagName"); + QTest::addColumn("tag"); QTest::addColumn("hintingPreference"); QTest::addColumn("offset"); QTest::addColumn("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(table.constData() + offset); QCOMPARE(*value, expectedValue); + + QCOMPARE(font.fontTable(tag.toString()), table); } typedef QList WritingSystemList;