Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-02 10:21:14

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QFONT_H
0005 #define QFONT_H
0006 
0007 #include <QtCore/qcompare.h>
0008 #include <QtCore/qendian.h>
0009 #include <QtCore/qshareddata.h>
0010 #include <QtGui/qtguiglobal.h>
0011 #include <QtGui/qwindowdefs.h>
0012 #include <QtCore/qstring.h>
0013 
0014 
0015 QT_BEGIN_NAMESPACE
0016 
0017 
0018 class QFontPrivate;                                     /* don't touch */
0019 class QVariant;
0020 
0021 class Q_GUI_EXPORT QFont
0022 {
0023     Q_GADGET
0024 public:
0025     enum StyleHint {
0026         Helvetica,  SansSerif = Helvetica,
0027         Times,      Serif = Times,
0028         Courier,    TypeWriter = Courier,
0029         OldEnglish, Decorative = OldEnglish,
0030         System,
0031         AnyStyle,
0032         Cursive,
0033         Monospace,
0034         Fantasy
0035     };
0036     Q_ENUM(StyleHint)
0037 
0038     enum StyleStrategy {
0039         PreferDefault           = 0x0001,
0040         PreferBitmap            = 0x0002,
0041         PreferDevice            = 0x0004,
0042         PreferOutline           = 0x0008,
0043         ForceOutline            = 0x0010,
0044         PreferMatch             = 0x0020,
0045         PreferQuality           = 0x0040,
0046         PreferAntialias         = 0x0080,
0047         NoAntialias             = 0x0100,
0048         NoSubpixelAntialias     = 0x0800,
0049         PreferNoShaping         = 0x1000,
0050         ContextFontMerging      = 0x2000,
0051         PreferTypoLineMetrics   = 0x4000,
0052         NoFontMerging           = 0x8000
0053     };
0054     Q_ENUM(StyleStrategy)
0055 
0056     enum HintingPreference {
0057         PreferDefaultHinting        = 0,
0058         PreferNoHinting             = 1,
0059         PreferVerticalHinting       = 2,
0060         PreferFullHinting           = 3
0061     };
0062     Q_ENUM(HintingPreference)
0063 
0064     enum Weight {
0065         Thin = 100,
0066         ExtraLight = 200,
0067         Light = 300,
0068         Normal = 400,
0069         Medium = 500,
0070         DemiBold = 600,
0071         Bold = 700,
0072         ExtraBold = 800,
0073         Black = 900
0074     };
0075     Q_ENUM(Weight)
0076 
0077     enum Style {
0078         StyleNormal,
0079         StyleItalic,
0080         StyleOblique
0081     };
0082     Q_ENUM(Style)
0083 
0084     enum Stretch {
0085         AnyStretch     =   0,
0086         UltraCondensed =  50,
0087         ExtraCondensed =  62,
0088         Condensed      =  75,
0089         SemiCondensed  =  87,
0090         Unstretched    = 100,
0091         SemiExpanded   = 112,
0092         Expanded       = 125,
0093         ExtraExpanded  = 150,
0094         UltraExpanded  = 200
0095     };
0096     Q_ENUM(Stretch)
0097 
0098     enum Capitalization {
0099         MixedCase,
0100         AllUppercase,
0101         AllLowercase,
0102         SmallCaps,
0103         Capitalize
0104     };
0105     Q_ENUM(Capitalization)
0106 
0107     enum SpacingType {
0108         PercentageSpacing,
0109         AbsoluteSpacing
0110     };
0111     Q_ENUM(SpacingType)
0112 
0113     enum ResolveProperties {
0114         NoPropertiesResolved        = 0x0000,
0115         FamilyResolved              = 0x0001,
0116         SizeResolved                = 0x0002,
0117         StyleHintResolved           = 0x0004,
0118         StyleStrategyResolved       = 0x0008,
0119         WeightResolved              = 0x0010,
0120         StyleResolved               = 0x0020,
0121         UnderlineResolved           = 0x0040,
0122         OverlineResolved            = 0x0080,
0123         StrikeOutResolved           = 0x0100,
0124         FixedPitchResolved          = 0x0200,
0125         StretchResolved             = 0x0400,
0126         KerningResolved             = 0x0800,
0127         CapitalizationResolved      = 0x1000,
0128         LetterSpacingResolved       = 0x2000,
0129         WordSpacingResolved         = 0x4000,
0130         HintingPreferenceResolved   = 0x8000,
0131         StyleNameResolved           = 0x10000,
0132         FamiliesResolved            = 0x20000,
0133         FeaturesResolved            = 0x40000,
0134         VariableAxesResolved        = 0x80000,
0135         AllPropertiesResolved       = 0xfffff
0136     };
0137     Q_ENUM(ResolveProperties)
0138 
0139     QFont();
0140 
0141     QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
0142     explicit QFont(const QStringList &families, int pointSize = -1, int weight = -1, bool italic = false);
0143     QFont(const QFont &font, const QPaintDevice *pd);
0144     QFont(const QFont &font);
0145     ~QFont();
0146 
0147     void swap(QFont &other) noexcept
0148     { d.swap(other.d); std::swap(resolve_mask, other.resolve_mask); }
0149 
0150     QString family() const;
0151     void setFamily(const QString &);
0152 
0153     QStringList families() const;
0154     void setFamilies(const QStringList &);
0155 
0156     QString styleName() const;
0157     void setStyleName(const QString &);
0158 
0159     int pointSize() const;
0160     void setPointSize(int);
0161     qreal pointSizeF() const;
0162     void setPointSizeF(qreal);
0163 
0164     int pixelSize() const;
0165     void setPixelSize(int);
0166 
0167     Weight weight() const;
0168     void setWeight(Weight weight);
0169 
0170     inline bool bold() const;
0171     inline void setBold(bool);
0172 
0173     void setStyle(Style style);
0174     Style style() const;
0175 
0176     inline bool italic() const;
0177     inline void setItalic(bool b);
0178 
0179     bool underline() const;
0180     void setUnderline(bool);
0181 
0182     bool overline() const;
0183     void setOverline(bool);
0184 
0185     bool strikeOut() const;
0186     void setStrikeOut(bool);
0187 
0188     bool fixedPitch() const;
0189     void setFixedPitch(bool);
0190 
0191     bool kerning() const;
0192     void setKerning(bool);
0193 
0194     StyleHint styleHint() const;
0195     StyleStrategy styleStrategy() const;
0196     void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
0197     void setStyleStrategy(StyleStrategy s);
0198 
0199     int stretch() const;
0200     void setStretch(int);
0201 
0202     qreal letterSpacing() const;
0203     SpacingType letterSpacingType() const;
0204     void setLetterSpacing(SpacingType type, qreal spacing);
0205 
0206     qreal wordSpacing() const;
0207     void setWordSpacing(qreal spacing);
0208 
0209     void setCapitalization(Capitalization);
0210     Capitalization capitalization() const;
0211 
0212     void setHintingPreference(HintingPreference hintingPreference);
0213     HintingPreference hintingPreference() const;
0214 
0215     struct Tag
0216     {
0217         constexpr Tag() = default;
0218 
0219         template <size_t N>
0220         constexpr Q_IMPLICIT Tag(const char (&str)[N]) noexcept
0221             :  m_value((quint32(str[0]) << 24) | (quint32(str[1]) << 16)
0222                      | (quint32(str[2]) << 8) | quint32(str[3]))
0223         {
0224             static_assert(N == 5, "The tag name must be exactly 4 characters long!");
0225         }
0226 
0227         constexpr bool isValid() const noexcept { return m_value != 0; }
0228         constexpr quint32 value() const noexcept { return m_value; }
0229 
0230         QByteArray toString() const
0231         {
0232             const char data[] = {
0233                 char((m_value & 0xff000000) >> 24),
0234                 char((m_value & 0x00ff0000) >> 16),
0235                 char((m_value & 0x0000ff00) >> 8),
0236                 char((m_value & 0x000000ff)) };
0237             return QByteArray(data, sizeof(data));
0238         }
0239 
0240         static constexpr std::optional<Tag> fromValue(quint32 value) noexcept
0241         {
0242             Tag maybeTag;
0243             maybeTag.m_value = value;
0244             return maybeTag.isValid() ? std::optional<Tag>(maybeTag) : std::nullopt;
0245         }
0246         Q_GUI_EXPORT static std::optional<Tag> fromString(QAnyStringView view) noexcept;
0247 
0248 #ifndef QT_NO_DATASTREAM
0249         friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, Tag);
0250         friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, Tag &);
0251 #endif
0252 
0253 #ifndef QT_NO_DEBUG_STREAM
0254         friend Q_GUI_EXPORT QDebug operator<<(QDebug debug, Tag tag);
0255 #endif
0256 
0257         friend constexpr size_t qHash(Tag key, size_t seed = 0) noexcept
0258         { return qHash(key.value(), seed); }
0259 
0260     private:
0261         friend constexpr bool comparesEqual(const Tag &lhs, const Tag &rhs) noexcept
0262         { return lhs.m_value == rhs.m_value; }
0263         friend constexpr Qt::strong_ordering compareThreeWay(const Tag &lhs, const Tag &rhs) noexcept
0264         { return Qt::compareThreeWay(lhs.m_value, rhs.m_value); }
0265         Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QFont::Tag)
0266 
0267         quint32 m_value = 0;
0268     };
0269 
0270     void setFeature(Tag tag, quint32 value);
0271     void unsetFeature(Tag tag);
0272     quint32 featureValue(Tag tag) const;
0273     bool isFeatureSet(Tag tag) const;
0274     QList<Tag> featureTags() const;
0275     void clearFeatures();
0276 
0277     void setVariableAxis(Tag tag, float value);
0278     void unsetVariableAxis(Tag tag);
0279     bool isVariableAxisSet(Tag tag) const;
0280     float variableAxisValue(Tag tag) const;
0281     void clearVariableAxes();
0282     QList<Tag> variableAxisTags() const;
0283 
0284     // dupicated from QFontInfo
0285     bool exactMatch() const;
0286 
0287     QFont &operator=(const QFont &);
0288     bool operator==(const QFont &) const;
0289     bool operator!=(const QFont &) const;
0290     bool operator<(const QFont &) const;
0291     operator QVariant() const;
0292     bool isCopyOf(const QFont &) const;
0293     QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFont)
0294 
0295     QString key() const;
0296 
0297     QString toString() const;
0298     bool fromString(const QString &);
0299 
0300     static QString substitute(const QString &);
0301     static QStringList substitutes(const QString &);
0302     static QStringList substitutions();
0303     static void insertSubstitution(const QString&, const QString &);
0304     static void insertSubstitutions(const QString&, const QStringList &);
0305     static void removeSubstitutions(const QString &);
0306     static void initialize();
0307     static void cleanup();
0308     static void cacheStatistics();
0309 
0310     QString defaultFamily() const;
0311 
0312     QFont resolve(const QFont &) const;
0313     inline uint resolveMask() const { return resolve_mask; }
0314     inline void setResolveMask(uint mask) { resolve_mask = mask; }
0315 
0316 #if QT_DEPRECATED_SINCE(6, 0)
0317     QT_DEPRECATED_VERSION_X_6_0("Use setWeight() instead") void setLegacyWeight(int legacyWeight);
0318     QT_DEPRECATED_VERSION_X_6_0("Use weight() instead") int legacyWeight() const;
0319 #endif
0320 
0321 private:
0322     explicit QFont(QFontPrivate *);
0323 
0324     void detach();
0325 
0326 
0327     friend class QFontPrivate;
0328     friend class QFontDialogPrivate;
0329     friend class QFontMetrics;
0330     friend class QFontMetricsF;
0331     friend class QFontInfo;
0332     friend class QPainter;
0333     friend class QPainterPrivate;
0334     friend class QApplication;
0335     friend class QWidget;
0336     friend class QWidgetPrivate;
0337     friend class QTextLayout;
0338     friend class QTextEngine;
0339     friend class QStackTextEngine;
0340     friend class QTextLine;
0341     friend struct QScriptLine;
0342     friend class QOpenGLContext;
0343     friend class QWin32PaintEngine;
0344     friend class QAlphaPaintEngine;
0345     friend class QPainterPath;
0346     friend class QTextItemInt;
0347     friend class QPicturePaintEngine;
0348     friend class QPainterReplayer;
0349     friend class QPaintBufferEngine;
0350     friend class QCommandLinkButtonPrivate;
0351     friend class QFontEngine;
0352 
0353 #ifndef QT_NO_DATASTREAM
0354     friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
0355     friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
0356 #endif
0357 
0358 #ifndef QT_NO_DEBUG_STREAM
0359     friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
0360 #endif
0361 
0362     QExplicitlySharedDataPointer<QFontPrivate> d;
0363     uint resolve_mask;
0364 };
0365 
0366 Q_DECLARE_SHARED(QFont)
0367 
0368 Q_GUI_EXPORT size_t qHash(const QFont &font, size_t seed = 0) noexcept;
0369 
0370 inline bool QFont::bold() const
0371 { return weight() > Medium; }
0372 
0373 
0374 inline void QFont::setBold(bool enable)
0375 { setWeight(enable ? Bold : Normal); }
0376 
0377 inline bool QFont::italic() const
0378 {
0379     return (style() != StyleNormal);
0380 }
0381 
0382 inline void QFont::setItalic(bool b) {
0383     setStyle(b ? StyleItalic : StyleNormal);
0384 }
0385 
0386 
0387 /*****************************************************************************
0388   QFont stream functions
0389  *****************************************************************************/
0390 
0391 #ifndef QT_NO_DATASTREAM
0392 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
0393 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
0394 #endif
0395 
0396 #ifndef QT_NO_DEBUG_STREAM
0397 Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
0398 #endif
0399 
0400 QT_END_NAMESPACE
0401 
0402 #endif // QFONT_H