- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qfont.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtGui module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QFONT_H
    00043 #define QFONT_H
    00044
    00045 #include <QtGui/qwindowdefs.h>
    00046 #include <QtCore/qstring.h>
    00047 #include <QtCore/qsharedpointer.h>
    00048
    00049 #if defined(Q_WS_X11) || defined(Q_WS_QWS)
    00050 typedef struct FT_FaceRec_* FT_Face;
    00051 #endif
    00052
    00053 QT_BEGIN_HEADER
    00054
    00055 QT_BEGIN_NAMESPACE
    00056
    00057 QT_MODULE(Gui)
    00058
    00059 class QFontPrivate;                                     /* don't touch */
    00060 class QStringList;
    00061 class QVariant;
    00062 class Q3TextFormatCollection;
    00063
    00064 class Q_GUI_EXPORT QFont
    00065 {
    00066     Q_GADGET
    00067     Q_ENUMS(StyleStrategy)
    00068 public:
    00069     enum StyleHint {
    00070         Helvetica,  SansSerif = Helvetica,
    00071         Times,      Serif = Times,
    00072         Courier,    TypeWriter = Courier,
    00073         OldEnglish, Decorative = OldEnglish,
    00074         System,
    00075         AnyStyle,
    00076         Cursive,
    00077         Monospace,
    00078         Fantasy
    00079     };
    00080
    00081     enum StyleStrategy {
    00082         PreferDefault       = 0x0001,
    00083         PreferBitmap        = 0x0002,
    00084         PreferDevice        = 0x0004,
    00085         PreferOutline       = 0x0008,
    00086         ForceOutline        = 0x0010,
    00087         PreferMatch         = 0x0020,
    00088         PreferQuality       = 0x0040,
    00089         PreferAntialias     = 0x0080,
    00090         NoAntialias         = 0x0100,
    00091         OpenGLCompatible    = 0x0200,
    00092         ForceIntegerMetrics = 0x0400,
    00093         NoFontMerging       = 0x8000
    00094     };
    00095
    00096     enum Weight {
    00097         Light    = 25,
    00098         Normal   = 50,
    00099         DemiBold = 63,
    00100         Bold     = 75,
    00101         Black    = 87
    00102     };
    00103
    00104     enum Style {
    00105         StyleNormal,
    00106         StyleItalic,
    00107         StyleOblique
    00108     };
    00109
    00110     enum Stretch {
    00111         UltraCondensed =  50,
    00112         ExtraCondensed =  62,
    00113         Condensed      =  75,
    00114         SemiCondensed  =  87,
    00115         Unstretched    = 100,
    00116         SemiExpanded   = 112,
    00117         Expanded       = 125,
    00118         ExtraExpanded  = 150,
    00119         UltraExpanded  = 200
    00120     };
    00121
    00122     enum Capitalization {
    00123         MixedCase,
    00124         AllUppercase,
    00125         AllLowercase,
    00126         SmallCaps,
    00127         Capitalize
    00128     };
    00129
    00130     enum SpacingType {
    00131         PercentageSpacing,
    00132         AbsoluteSpacing
    00133     };
    00134
    00135     enum ResolveProperties {
    00136         FamilyResolved         = 0x0001,
    00137         SizeResolved           = 0x0002,
    00138         StyleHintResolved      = 0x0004,
    00139         StyleStrategyResolved  = 0x0008,
    00140         WeightResolved         = 0x0010,
    00141         StyleResolved          = 0x0020,
    00142         UnderlineResolved      = 0x0040,
    00143         OverlineResolved       = 0x0080,
    00144         StrikeOutResolved      = 0x0100,
    00145         FixedPitchResolved     = 0x0200,
    00146         StretchResolved        = 0x0400,
    00147         KerningResolved        = 0x0800,
    00148         CapitalizationResolved = 0x1000,
    00149         LetterSpacingResolved  = 0x2000,
    00150         WordSpacingResolved    = 0x4000,
    00151         AllPropertiesResolved  = 0x7fff
    00152     };
    00153
    00154     QFont();
    00155     QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
    00156     QFont(const QFont &, QPaintDevice *pd);
    00157     QFont(const QFont &);
    00158     ~QFont();
    00159
    00160     QString family() const;
    00161     void setFamily(const QString &);
    00162
    00163     int pointSize() const;
    00164     void setPointSize(int);
    00165     qreal pointSizeF() const;
    00166     void setPointSizeF(qreal);
    00167
    00168     int pixelSize() const;
    00169     void setPixelSize(int);
    00170
    00171     int weight() const;
    00172     void setWeight(int);
    00173
    00174     inline bool bold() const;
    00175     inline void setBold(bool);
    00176
    00177     void setStyle(Style style);
    00178     Style style() const;
    00179
    00180     inline bool italic() const;
    00181     inline void setItalic(bool b);
    00182
    00183     bool underline() const;
    00184     void setUnderline(bool);
    00185
    00186     bool overline() const;
    00187     void setOverline(bool);
    00188
    00189     bool strikeOut() const;
    00190     void setStrikeOut(bool);
    00191
    00192     bool fixedPitch() const;
    00193     void setFixedPitch(bool);
    00194
    00195     bool kerning() const;
    00196     void setKerning(bool);
    00197
    00198     StyleHint styleHint() const;
    00199     StyleStrategy styleStrategy() const;
    00200     void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
    00201     void setStyleStrategy(StyleStrategy s);
    00202
    00203     int stretch() const;
    00204     void setStretch(int);
    00205
    00206     qreal letterSpacing() const;
    00207     SpacingType letterSpacingType() const;
    00208     void setLetterSpacing(SpacingType type, qreal spacing);
    00209
    00210     qreal wordSpacing() const;
    00211     void setWordSpacing(qreal spacing);
    00212
    00213     void setCapitalization(Capitalization);
    00214     Capitalization capitalization() const;
    00215
    00216     // is raw mode still needed?
    00217     bool rawMode() const;
    00218     void setRawMode(bool);
    00219
    00220     // dupicated from QFontInfo
    00221     bool exactMatch() const;
    00222
    00223     QFont &operator=(const QFont &);
    00224     bool operator==(const QFont &) const;
    00225     bool operator!=(const QFont &) const;
    00226     bool operator<(const QFont &) const;
    00227     operator QVariant() const;
    00228     bool isCopyOf(const QFont &) const;
    00229
    00230
    00231 #ifdef Q_WS_WIN
    00232     HFONT handle() const;
    00233 #else // !Q_WS_WIN
    00234     Qt::HANDLE handle() const;
    00235 #endif // Q_WS_WIN
    00236 #ifdef Q_WS_MAC
    00237     quint32 macFontID() const;
    00238 #endif
    00239 #if defined(Q_WS_X11) || defined(Q_WS_QWS)
    00240     FT_Face freetypeFace() const;
    00241 #endif
    00242
    00243     // needed for X11
    00244     void setRawName(const QString &);
    00245     QString rawName() const;
    00246
    00247     QString key() const;
    00248
    00249     QString toString() const;
    00250     bool fromString(const QString &);
    00251
    00252     static QString substitute(const QString &);
    00253     static QStringList substitutes(const QString &);
    00254     static QStringList substitutions();
    00255     static void insertSubstitution(const QString&, const QString &);
    00256     static void insertSubstitutions(const QString&, const QStringList &);
    00257     static void removeSubstitution(const QString &);
    00258     static void initialize();
    00259     static void cleanup();
    00260 #ifndef Q_WS_QWS
    00261     static void cacheStatistics();
    00262 #endif
    00263
    00264     QString defaultFamily() const;
    00265     QString lastResortFamily() const;
    00266     QString lastResortFont() const;
    00267
    00268     QFont resolve(const QFont &) const;
    00269     inline uint resolve() const { return resolve_mask; }
    00270     inline void resolve(uint mask) { resolve_mask = mask; }
    00271
    00272 #ifdef QT3_SUPPORT
    00273     static QT3_SUPPORT QFont defaultFont();
    00274     static QT3_SUPPORT void setDefaultFont(const QFont &);
    00275     QT3_SUPPORT void setPixelSizeFloat(qreal);
    00276     QT3_SUPPORT qreal pointSizeFloat() const { return pointSizeF(); }
    00277     QT3_SUPPORT void setPointSizeFloat(qreal size) { setPointSizeF(size); }
    00278 #endif
    00279
    00280 private:
    00281     QFont(QFontPrivate *);
    00282
    00283     void detach();
    00284
    00285 #if defined(Q_WS_MAC)
    00286     void macSetFont(QPaintDevice *);
    00287 #elif defined(Q_WS_X11)
    00288     void x11SetScreen(int screen = -1);
    00289     int x11Screen() const;
    00290 #endif
    00291
    00292     friend class QFontPrivate;
    00293     friend class QFontDialogPrivate;
    00294     friend class QFontMetrics;
    00295     friend class QFontMetricsF;
    00296     friend class QFontInfo;
    00297     friend class QPainter;
    00298     friend class QPainterPrivate;
    00299     friend class QPSPrintEngineFont;
    00300     friend class QApplication;
    00301     friend class QWidget;
    00302     friend class QWidgetPrivate;
    00303     friend class Q3TextFormatCollection;
    00304     friend class QTextLayout;
    00305     friend class QTextEngine;
    00306     friend class QStackTextEngine;
    00307     friend class QTextLine;
    00308     friend struct QScriptLine;
    00309     friend class QGLContext;
    00310     friend class QWin32PaintEngine;
    00311     friend class QAlphaPaintEngine;
    00312     friend class QPainterPath;
    00313     friend class QTextItemInt;
    00314     friend class QPicturePaintEngine;
    00315     friend class QPainterReplayer;
    00316     friend class QPaintBufferEngine;
    00317     friend class QCommandLinkButtonPrivate;
    00318
    00319 #ifndef QT_NO_DATASTREAM
    00320     friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
    00321     friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
    00322 #endif
    00323
    00324     QExplicitlySharedDataPointer<QFontPrivate> d;
    00325     uint resolve_mask;
    00326 };
    00327
    00328
    00329 inline bool QFont::bold() const
    00330 { return weight() > Normal; }
    00331
    00332
    00333 inline void QFont::setBold(bool enable)
    00334 { setWeight(enable ? Bold : Normal); }
    00335
    00336 inline bool QFont::italic() const
    00337 {
    00338     return (style() != StyleNormal);
    00339 }
    00340
    00341 inline void QFont::setItalic(bool b) {
    00342     setStyle(b ? StyleItalic : StyleNormal);
    00343 }
    00344
    00345
    00346 /*****************************************************************************
    00347   QFont stream functions
    00348  *****************************************************************************/
    00349
    00350 #ifndef QT_NO_DATASTREAM
    00351 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
    00352 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
    00353 #endif
    00354
    00355 #ifndef QT_NO_DEBUG_STREAM
    00356 Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
    00357 #endif
    00358
    00359 QT_END_NAMESPACE
    00360
    00361 QT_END_HEADER
    00362
    00363 #endif // QFONT_H