1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include <QtGui/qwindowdefs.h>
46 #include <QtCore/qstring.h>
47 #include <QtCore/qsharedpointer.h>
49 #if defined(Q_WS_X11) || defined(Q_WS_QWS)
50 typedef struct FT_FaceRec_* FT_Face;
59 class QFontPrivate; /* don't touch */
62 class Q3TextFormatCollection;
64 class Q_GUI_EXPORT QFont
67 Q_ENUMS(StyleStrategy)
70 Helvetica, SansSerif = Helvetica,
72 Courier, TypeWriter = Courier,
73 OldEnglish, Decorative = OldEnglish,
82 PreferDefault = 0x0001,
83 PreferBitmap = 0x0002,
84 PreferDevice = 0x0004,
85 PreferOutline = 0x0008,
86 ForceOutline = 0x0010,
88 PreferQuality = 0x0040,
89 PreferAntialias = 0x0080,
91 OpenGLCompatible = 0x0200,
92 ForceIntegerMetrics = 0x0400,
93 NoFontMerging = 0x8000
96 enum HintingPreference {
97 PreferDefaultHinting = 0,
99 PreferVerticalHinting = 2,
100 PreferFullHinting = 3
129 enum Capitalization {
142 enum ResolveProperties {
143 FamilyResolved = 0x0001,
144 SizeResolved = 0x0002,
145 StyleHintResolved = 0x0004,
146 StyleStrategyResolved = 0x0008,
147 WeightResolved = 0x0010,
148 StyleResolved = 0x0020,
149 UnderlineResolved = 0x0040,
150 OverlineResolved = 0x0080,
151 StrikeOutResolved = 0x0100,
152 FixedPitchResolved = 0x0200,
153 StretchResolved = 0x0400,
154 KerningResolved = 0x0800,
155 CapitalizationResolved = 0x1000,
156 LetterSpacingResolved = 0x2000,
157 WordSpacingResolved = 0x4000,
158 HintingPreferenceResolved = 0x8000,
159 StyleNameResolved = 0x10000,
160 AllPropertiesResolved = 0x1ffff
164 QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
165 QFont(const QFont &, QPaintDevice *pd);
166 QFont(const QFont &);
169 QString family() const;
170 void setFamily(const QString &);
172 QString styleName() const;
173 void setStyleName(const QString &);
175 int pointSize() const;
176 void setPointSize(int);
177 qreal pointSizeF() const;
178 void setPointSizeF(qreal);
180 int pixelSize() const;
181 void setPixelSize(int);
186 inline bool bold() const;
187 inline void setBold(bool);
189 void setStyle(Style style);
192 inline bool italic() const;
193 inline void setItalic(bool b);
195 bool underline() const;
196 void setUnderline(bool);
198 bool overline() const;
199 void setOverline(bool);
201 bool strikeOut() const;
202 void setStrikeOut(bool);
204 bool fixedPitch() const;
205 void setFixedPitch(bool);
207 bool kerning() const;
208 void setKerning(bool);
210 StyleHint styleHint() const;
211 StyleStrategy styleStrategy() const;
212 void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
213 void setStyleStrategy(StyleStrategy s);
216 void setStretch(int);
218 qreal letterSpacing() const;
219 SpacingType letterSpacingType() const;
220 void setLetterSpacing(SpacingType type, qreal spacing);
222 qreal wordSpacing() const;
223 void setWordSpacing(qreal spacing);
225 void setCapitalization(Capitalization);
226 Capitalization capitalization() const;
228 void setHintingPreference(HintingPreference hintingPreference);
229 HintingPreference hintingPreference() const;
231 // is raw mode still needed?
232 bool rawMode() const;
233 void setRawMode(bool);
235 // dupicated from QFontInfo
236 bool exactMatch() const;
238 QFont &operator=(const QFont &);
239 bool operator==(const QFont &) const;
240 bool operator!=(const QFont &) const;
241 bool operator<(const QFont &) const;
242 operator QVariant() const;
243 bool isCopyOf(const QFont &) const;
244 #ifdef Q_COMPILER_RVALUE_REFS
245 inline QFont &operator=(QFont &&other)
246 { qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask); return *this; }
250 HFONT handle() const;
252 Qt::HANDLE handle() const;
255 quint32 macFontID() const;
257 #if defined(Q_WS_X11) || defined(Q_WS_QWS)
258 FT_Face freetypeFace() const;
262 void setRawName(const QString &);
263 QString rawName() const;
267 QString toString() const;
268 bool fromString(const QString &);
270 static QString substitute(const QString &);
271 static QStringList substitutes(const QString &);
272 static QStringList substitutions();
273 static void insertSubstitution(const QString&, const QString &);
274 static void insertSubstitutions(const QString&, const QStringList &);
275 static void removeSubstitution(const QString &);
276 static void initialize();
277 static void cleanup();
279 static void cacheStatistics();
282 QString defaultFamily() const;
283 QString lastResortFamily() const;
284 QString lastResortFont() const;
286 QFont resolve(const QFont &) const;
287 inline uint resolve() const { return resolve_mask; }
288 inline void resolve(uint mask) { resolve_mask = mask; }
291 static QT3_SUPPORT QFont defaultFont();
292 static QT3_SUPPORT void setDefaultFont(const QFont &);
293 QT3_SUPPORT void setPixelSizeFloat(qreal);
294 QT3_SUPPORT qreal pointSizeFloat() const { return pointSizeF(); }
295 QT3_SUPPORT void setPointSizeFloat(qreal size) { setPointSizeF(size); }
299 QFont(QFontPrivate *);
303 #if defined(Q_WS_MAC)
304 void macSetFont(QPaintDevice *);
305 #elif defined(Q_WS_X11)
306 void x11SetScreen(int screen = -1);
307 int x11Screen() const;
310 friend class QFontPrivate;
311 friend class QFontDialogPrivate;
312 friend class QFontMetrics;
313 friend class QFontMetricsF;
314 friend class QFontInfo;
315 friend class QPainter;
316 friend class QPainterPrivate;
317 friend class QPSPrintEngineFont;
318 friend class QApplication;
319 friend class QWidget;
320 friend class QWidgetPrivate;
321 friend class Q3TextFormatCollection;
322 friend class QTextLayout;
323 friend class QTextEngine;
324 friend class QStackTextEngine;
325 friend class QTextLine;
326 friend struct QScriptLine;
327 friend class QGLContext;
328 friend class QWin32PaintEngine;
329 friend class QAlphaPaintEngine;
330 friend class QPainterPath;
331 friend class QTextItemInt;
332 friend class QPicturePaintEngine;
333 friend class QPainterReplayer;
334 friend class QPaintBufferEngine;
335 friend class QCommandLinkButtonPrivate;
336 friend class QFontEngine;
338 #ifndef QT_NO_DATASTREAM
339 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
340 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
343 QExplicitlySharedDataPointer<QFontPrivate> d;
348 inline bool QFont::bold() const
349 { return weight() > Normal; }
352 inline void QFont::setBold(bool enable)
353 { setWeight(enable ? Bold : Normal); }
355 inline bool QFont::italic() const
357 return (style() != StyleNormal);
360 inline void QFont::setItalic(bool b) {
361 setStyle(b ? StyleItalic : StyleNormal);
365 /*****************************************************************************
366 QFont stream functions
367 *****************************************************************************/
369 #ifndef QT_NO_DATASTREAM
370 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
371 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
374 #ifndef QT_NO_DEBUG_STREAM
375 Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);