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