Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtGui/qfont.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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