src/gui/text/qfont.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QFONT_H
       
    43 #define QFONT_H
       
    44 
       
    45 #include <QtGui/qwindowdefs.h>
       
    46 #include <QtCore/qstring.h>
       
    47 #include <QtCore/qsharedpointer.h>
       
    48 
       
    49 #if defined(Q_WS_X11) || defined(Q_WS_QWS)
       
    50 typedef struct FT_FaceRec_* FT_Face;
       
    51 #endif
       
    52 
       
    53 QT_BEGIN_HEADER
       
    54 
       
    55 QT_BEGIN_NAMESPACE
       
    56 
       
    57 QT_MODULE(Gui)
       
    58 
       
    59 class QFontPrivate;                                     /* don't touch */
       
    60 class QStringList;
       
    61 class QVariant;
       
    62 class Q3TextFormatCollection;
       
    63 
       
    64 class Q_GUI_EXPORT QFont
       
    65 {
       
    66     Q_GADGET
       
    67     Q_ENUMS(StyleStrategy)
       
    68 public:
       
    69     enum StyleHint {
       
    70         Helvetica,  SansSerif = Helvetica,
       
    71         Times,      Serif = Times,
       
    72         Courier,    TypeWriter = Courier,
       
    73         OldEnglish, Decorative = OldEnglish,
       
    74         System,
       
    75         AnyStyle
       
    76     };
       
    77 
       
    78     enum StyleStrategy {
       
    79         PreferDefault    = 0x0001,
       
    80         PreferBitmap     = 0x0002,
       
    81         PreferDevice     = 0x0004,
       
    82         PreferOutline    = 0x0008,
       
    83         ForceOutline     = 0x0010,
       
    84         PreferMatch      = 0x0020,
       
    85         PreferQuality    = 0x0040,
       
    86         PreferAntialias  = 0x0080,
       
    87         NoAntialias      = 0x0100,
       
    88         OpenGLCompatible = 0x0200,
       
    89         NoFontMerging    = 0x8000
       
    90     };
       
    91 
       
    92     enum Weight {
       
    93         Light    = 25,
       
    94         Normal   = 50,
       
    95         DemiBold = 63,
       
    96         Bold     = 75,
       
    97         Black    = 87
       
    98     };
       
    99 
       
   100     enum Style {
       
   101         StyleNormal,
       
   102         StyleItalic,
       
   103         StyleOblique
       
   104     };
       
   105 
       
   106     enum Stretch {
       
   107         UltraCondensed =  50,
       
   108         ExtraCondensed =  62,
       
   109         Condensed      =  75,
       
   110         SemiCondensed  =  87,
       
   111         Unstretched    = 100,
       
   112         SemiExpanded   = 112,
       
   113         Expanded       = 125,
       
   114         ExtraExpanded  = 150,
       
   115         UltraExpanded  = 200
       
   116     };
       
   117 
       
   118     enum Capitalization {
       
   119         MixedCase,
       
   120         AllUppercase,
       
   121         AllLowercase,
       
   122         SmallCaps,
       
   123         Capitalize
       
   124     };
       
   125 
       
   126     enum SpacingType {
       
   127         PercentageSpacing,
       
   128         AbsoluteSpacing
       
   129     };
       
   130 
       
   131     enum ResolveProperties {
       
   132         FamilyResolved         = 0x0001,
       
   133         SizeResolved           = 0x0002,
       
   134         StyleHintResolved      = 0x0004,
       
   135         StyleStrategyResolved  = 0x0008,
       
   136         WeightResolved         = 0x0010,
       
   137         StyleResolved          = 0x0020,
       
   138         UnderlineResolved      = 0x0040,
       
   139         OverlineResolved       = 0x0080,
       
   140         StrikeOutResolved      = 0x0100,
       
   141         FixedPitchResolved     = 0x0200,
       
   142         StretchResolved        = 0x0400,
       
   143         KerningResolved        = 0x0800,
       
   144         CapitalizationResolved = 0x1000,
       
   145         LetterSpacingResolved  = 0x2000,
       
   146         WordSpacingResolved    = 0x4000,
       
   147         AllPropertiesResolved  = 0x7fff
       
   148     };
       
   149 
       
   150     QFont();
       
   151     QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
       
   152     QFont(const QFont &, QPaintDevice *pd);
       
   153     QFont(const QFont &);
       
   154     ~QFont();
       
   155 
       
   156     QString family() const;
       
   157     void setFamily(const QString &);
       
   158 
       
   159     int pointSize() const;
       
   160     void setPointSize(int);
       
   161     qreal pointSizeF() const;
       
   162     void setPointSizeF(qreal);
       
   163 
       
   164     int pixelSize() const;
       
   165     void setPixelSize(int);
       
   166 
       
   167     int weight() const;
       
   168     void setWeight(int);
       
   169 
       
   170     inline bool bold() const;
       
   171     inline void setBold(bool);
       
   172 
       
   173     void setStyle(Style style);
       
   174     Style style() const;
       
   175 
       
   176     inline bool italic() const;
       
   177     inline void setItalic(bool b);
       
   178 
       
   179     bool underline() const;
       
   180     void setUnderline(bool);
       
   181 
       
   182     bool overline() const;
       
   183     void setOverline(bool);
       
   184 
       
   185     bool strikeOut() const;
       
   186     void setStrikeOut(bool);
       
   187 
       
   188     bool fixedPitch() const;
       
   189     void setFixedPitch(bool);
       
   190 
       
   191     bool kerning() const;
       
   192     void setKerning(bool);
       
   193 
       
   194     StyleHint styleHint() const;
       
   195     StyleStrategy styleStrategy() const;
       
   196     void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
       
   197     void setStyleStrategy(StyleStrategy s);
       
   198 
       
   199     int stretch() const;
       
   200     void setStretch(int);
       
   201 
       
   202     qreal letterSpacing() const;
       
   203     SpacingType letterSpacingType() const;
       
   204     void setLetterSpacing(SpacingType type, qreal spacing);
       
   205 
       
   206     qreal wordSpacing() const;
       
   207     void setWordSpacing(qreal spacing);
       
   208 
       
   209     void setCapitalization(Capitalization);
       
   210     Capitalization capitalization() const;
       
   211 
       
   212     // is raw mode still needed?
       
   213     bool rawMode() const;
       
   214     void setRawMode(bool);
       
   215 
       
   216     // dupicated from QFontInfo
       
   217     bool exactMatch() const;
       
   218 
       
   219     QFont &operator=(const QFont &);
       
   220     bool operator==(const QFont &) const;
       
   221     bool operator!=(const QFont &) const;
       
   222     bool operator<(const QFont &) const;
       
   223     operator QVariant() const;
       
   224     bool isCopyOf(const QFont &) const;
       
   225 
       
   226 
       
   227 #ifdef Q_WS_WIN
       
   228     HFONT handle() const;
       
   229 #else // !Q_WS_WIN
       
   230     Qt::HANDLE handle() const;
       
   231 #endif // Q_WS_WIN
       
   232 #ifdef Q_WS_MAC
       
   233     quint32 macFontID() const;
       
   234 #endif
       
   235 #if defined(Q_WS_X11) || defined(Q_WS_QWS)
       
   236     FT_Face freetypeFace() const;
       
   237 #endif
       
   238 
       
   239     // needed for X11
       
   240     void setRawName(const QString &);
       
   241     QString rawName() const;
       
   242 
       
   243     QString key() const;
       
   244 
       
   245     QString toString() const;
       
   246     bool fromString(const QString &);
       
   247 
       
   248     static QString substitute(const QString &);
       
   249     static QStringList substitutes(const QString &);
       
   250     static QStringList substitutions();
       
   251     static void insertSubstitution(const QString&, const QString &);
       
   252     static void insertSubstitutions(const QString&, const QStringList &);
       
   253     static void removeSubstitution(const QString &);
       
   254     static void initialize();
       
   255     static void cleanup();
       
   256 #ifndef Q_WS_QWS
       
   257     static void cacheStatistics();
       
   258 #endif
       
   259 
       
   260     QString defaultFamily() const;
       
   261     QString lastResortFamily() const;
       
   262     QString lastResortFont() const;
       
   263 
       
   264     QFont resolve(const QFont &) const;
       
   265     inline uint resolve() const { return resolve_mask; }
       
   266     inline void resolve(uint mask) { resolve_mask = mask; }
       
   267 
       
   268 #ifdef QT3_SUPPORT
       
   269     static QT3_SUPPORT QFont defaultFont();
       
   270     static QT3_SUPPORT void setDefaultFont(const QFont &);
       
   271     QT3_SUPPORT void setPixelSizeFloat(qreal);
       
   272     QT3_SUPPORT qreal pointSizeFloat() const { return pointSizeF(); }
       
   273     QT3_SUPPORT void setPointSizeFloat(qreal size) { setPointSizeF(size); }
       
   274 #endif
       
   275 
       
   276 private:
       
   277     QFont(QFontPrivate *);
       
   278 
       
   279     void detach();
       
   280 
       
   281 #if defined(Q_WS_MAC)
       
   282     void macSetFont(QPaintDevice *);
       
   283 #elif defined(Q_WS_X11)
       
   284     void x11SetScreen(int screen = -1);
       
   285     int x11Screen() const;
       
   286 #endif
       
   287 
       
   288     friend class QFontPrivate;
       
   289     friend class QFontDialogPrivate;
       
   290     friend class QFontMetrics;
       
   291     friend class QFontMetricsF;
       
   292     friend class QFontInfo;
       
   293     friend class QPainter;
       
   294     friend class QPSPrintEngineFont;
       
   295     friend class QApplication;
       
   296     friend class QWidget;
       
   297     friend class QWidgetPrivate;
       
   298     friend class Q3TextFormatCollection;
       
   299     friend class QTextLayout;
       
   300     friend class QTextEngine;
       
   301     friend class QStackTextEngine;
       
   302     friend class QTextLine;
       
   303     friend struct QScriptLine;
       
   304     friend class QGLContext;
       
   305     friend class QWin32PaintEngine;
       
   306     friend class QAlphaPaintEngine;
       
   307     friend class QPainterPath;
       
   308     friend class QTextItemInt;
       
   309     friend class QPicturePaintEngine;
       
   310     friend class QPainterReplayer;
       
   311     friend class QPaintBufferEngine;
       
   312     friend class QCommandLinkButtonPrivate;
       
   313 
       
   314 #ifndef QT_NO_DATASTREAM
       
   315     friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
       
   316     friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
       
   317 #endif
       
   318 
       
   319     QExplicitlySharedDataPointer<QFontPrivate> d;
       
   320     uint resolve_mask;
       
   321 };
       
   322 
       
   323 
       
   324 inline bool QFont::bold() const
       
   325 { return weight() > Normal; }
       
   326 
       
   327 
       
   328 inline void QFont::setBold(bool enable)
       
   329 { setWeight(enable ? Bold : Normal); }
       
   330 
       
   331 inline bool QFont::italic() const
       
   332 {
       
   333     return (style() != StyleNormal);
       
   334 }
       
   335 
       
   336 inline void QFont::setItalic(bool b) {
       
   337     setStyle(b ? StyleItalic : StyleNormal);
       
   338 }
       
   339 
       
   340 
       
   341 /*****************************************************************************
       
   342   QFont stream functions
       
   343  *****************************************************************************/
       
   344 
       
   345 #ifndef QT_NO_DATASTREAM
       
   346 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
       
   347 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
       
   348 #endif
       
   349 
       
   350 #ifndef QT_NO_DEBUG_STREAM
       
   351 Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
       
   352 #endif
       
   353 
       
   354 QT_END_NAMESPACE
       
   355 
       
   356 QT_END_HEADER
       
   357 
       
   358 #endif // QFONT_H