diff options
Diffstat (limited to 'src/gui/text/qfont.h')
-rw-r--r-- | src/gui/text/qfont.h | 106 |
1 files changed, 85 insertions, 21 deletions
diff --git a/src/gui/text/qfont.h b/src/gui/text/qfont.h index b54df8d2df..0b41e31bdb 100644 --- a/src/gui/text/qfont.h +++ b/src/gui/text/qfont.h @@ -4,6 +4,8 @@ #ifndef QFONT_H #define QFONT_H +#include <QtCore/qcompare.h> +#include <QtCore/qendian.h> #include <QtCore/qshareddata.h> #include <QtGui/qtguiglobal.h> #include <QtGui/qwindowdefs.h> @@ -34,18 +36,20 @@ public: Q_ENUM(StyleHint) enum StyleStrategy { - PreferDefault = 0x0001, - PreferBitmap = 0x0002, - PreferDevice = 0x0004, - PreferOutline = 0x0008, - ForceOutline = 0x0010, - PreferMatch = 0x0020, - PreferQuality = 0x0040, - PreferAntialias = 0x0080, - NoAntialias = 0x0100, - NoSubpixelAntialias = 0x0800, - PreferNoShaping = 0x1000, - NoFontMerging = 0x8000 + PreferDefault = 0x0001, + PreferBitmap = 0x0002, + PreferDevice = 0x0004, + PreferOutline = 0x0008, + ForceOutline = 0x0010, + PreferMatch = 0x0020, + PreferQuality = 0x0040, + PreferAntialias = 0x0080, + NoAntialias = 0x0100, + NoSubpixelAntialias = 0x0800, + PreferNoShaping = 0x1000, + ContextFontMerging = 0x2000, + PreferTypoLineMetrics = 0x4000, + NoFontMerging = 0x8000 }; Q_ENUM(StyleStrategy) @@ -127,7 +131,8 @@ public: StyleNameResolved = 0x10000, FamiliesResolved = 0x20000, FeaturesResolved = 0x40000, - AllPropertiesResolved = 0x7ffff + VariableAxesResolved = 0x80000, + AllPropertiesResolved = 0xfffff }; Q_ENUM(ResolveProperties) @@ -207,15 +212,74 @@ public: void setHintingPreference(HintingPreference hintingPreference); HintingPreference hintingPreference() const; - void setFeature(const char *feature, quint32 value); - void setFeature(quint32 tag, quint32 value); - void setFeatures(const QHash<quint32, quint32> &features); - void unsetFeature(quint32 tag); - void unsetFeature(const char *feature); - QHash<quint32, quint32> features() const; + struct Tag + { + constexpr Tag() = default; + + template <size_t N> + constexpr Q_IMPLICIT Tag(const char (&str)[N]) noexcept + : m_value((quint32(str[0]) << 24) | (quint32(str[1]) << 16) + | (quint32(str[2]) << 8) | quint32(str[3])) + { + static_assert(N == 5, "The tag name must be exactly 4 characters long!"); + } + + constexpr bool isValid() const noexcept { return m_value != 0; } + constexpr quint32 value() const noexcept { return m_value; } + + QByteArray toString() const + { + const char data[] = { + char((m_value & 0xff000000) >> 24), + char((m_value & 0x00ff0000) >> 16), + char((m_value & 0x0000ff00) >> 8), + char((m_value & 0x000000ff)) }; + return QByteArray(data, sizeof(data)); + } + + static constexpr std::optional<Tag> fromValue(quint32 value) noexcept + { + Tag maybeTag; + maybeTag.m_value = value; + return maybeTag.isValid() ? std::optional<Tag>(maybeTag) : std::nullopt; + } + Q_GUI_EXPORT static std::optional<Tag> fromString(QAnyStringView view) noexcept; - static QByteArray tagToString(quint32 tag); - static quint32 stringToTag(const char *tagString); +#ifndef QT_NO_DATASTREAM + friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, Tag); + friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, Tag &); +#endif + +#ifndef QT_NO_DEBUG_STREAM + friend Q_GUI_EXPORT QDebug operator<<(QDebug debug, Tag tag); +#endif + + friend constexpr size_t qHash(Tag key, size_t seed = 0) noexcept + { return qHash(key.value(), seed); } + + private: + friend constexpr bool comparesEqual(const Tag &lhs, const Tag &rhs) noexcept + { return lhs.m_value == rhs.m_value; } + friend constexpr Qt::strong_ordering compareThreeWay(const Tag &lhs, const Tag &rhs) noexcept + { return Qt::compareThreeWay(lhs.m_value, rhs.m_value); } + Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QFont::Tag) + + quint32 m_value = 0; + }; + + void setFeature(Tag tag, quint32 value); + void unsetFeature(Tag tag); + quint32 featureValue(Tag tag) const; + bool isFeatureSet(Tag tag) const; + QList<Tag> featureTags() const; + void clearFeatures(); + + void setVariableAxis(Tag tag, float value); + void unsetVariableAxis(Tag tag); + bool isVariableAxisSet(Tag tag) const; + float variableAxisValue(Tag tag) const; + void clearVariableAxes(); + QList<Tag> variableAxisTags() const; // dupicated from QFontInfo bool exactMatch() const; |