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 ** 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
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
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 AllPropertiesResolved = 0xffff
163 QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
164 QFont(const QFont &, QPaintDevice *pd);
165 QFont(const QFont &);
168 QString family() const;
169 void setFamily(const QString &);
171 int pointSize() const;
172 void setPointSize(int);
173 qreal pointSizeF() const;
174 void setPointSizeF(qreal);
176 int pixelSize() const;
177 void setPixelSize(int);
182 inline bool bold() const;
183 inline void setBold(bool);
185 void setStyle(Style style);
188 inline bool italic() const;
189 inline void setItalic(bool b);
191 bool underline() const;
192 void setUnderline(bool);
194 bool overline() const;
195 void setOverline(bool);
197 bool strikeOut() const;
198 void setStrikeOut(bool);
200 bool fixedPitch() const;
201 void setFixedPitch(bool);
203 bool kerning() const;
204 void setKerning(bool);
206 StyleHint styleHint() const;
207 StyleStrategy styleStrategy() const;
208 void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
209 void setStyleStrategy(StyleStrategy s);
212 void setStretch(int);
214 qreal letterSpacing() const;
215 SpacingType letterSpacingType() const;
216 void setLetterSpacing(SpacingType type, qreal spacing);
218 qreal wordSpacing() const;
219 void setWordSpacing(qreal spacing);
221 void setCapitalization(Capitalization);
222 Capitalization capitalization() const;
224 void setHintingPreference(HintingPreference hintingPreference);
225 HintingPreference hintingPreference() const;
227 // is raw mode still needed?
228 bool rawMode() const;
229 void setRawMode(bool);
231 // dupicated from QFontInfo
232 bool exactMatch() const;
234 QFont &operator=(const QFont &);
235 bool operator==(const QFont &) const;
236 bool operator!=(const QFont &) const;
237 bool operator<(const QFont &) const;
238 operator QVariant() const;
239 bool isCopyOf(const QFont &) const;
240 #ifdef Q_COMPILER_RVALUE_REFS
241 inline QFont &operator=(QFont &&other)
242 { qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask); return *this; }
246 HFONT handle() const;
248 Qt::HANDLE handle() const;
251 quint32 macFontID() const;
253 #if defined(Q_WS_X11) || defined(Q_WS_QWS)
254 FT_Face freetypeFace() const;
258 void setRawName(const QString &);
259 QString rawName() const;
263 QString toString() const;
264 bool fromString(const QString &);
266 static QString substitute(const QString &);
267 static QStringList substitutes(const QString &);
268 static QStringList substitutions();
269 static void insertSubstitution(const QString&, const QString &);
270 static void insertSubstitutions(const QString&, const QStringList &);
271 static void removeSubstitution(const QString &);
272 static void initialize();
273 static void cleanup();
275 static void cacheStatistics();
278 QString defaultFamily() const;
279 QString lastResortFamily() const;
280 QString lastResortFont() const;
282 QFont resolve(const QFont &) const;
283 inline uint resolve() const { return resolve_mask; }
284 inline void resolve(uint mask) { resolve_mask = mask; }
287 static QT3_SUPPORT QFont defaultFont();
288 static QT3_SUPPORT void setDefaultFont(const QFont &);
289 QT3_SUPPORT void setPixelSizeFloat(qreal);
290 QT3_SUPPORT qreal pointSizeFloat() const { return pointSizeF(); }
291 QT3_SUPPORT void setPointSizeFloat(qreal size) { setPointSizeF(size); }
295 QFont(QFontPrivate *);
299 #if defined(Q_WS_MAC)
300 void macSetFont(QPaintDevice *);
301 #elif defined(Q_WS_X11)
302 void x11SetScreen(int screen = -1);
303 int x11Screen() const;
306 friend class QFontPrivate;
307 friend class QFontDialogPrivate;
308 friend class QFontMetrics;
309 friend class QFontMetricsF;
310 friend class QFontInfo;
311 friend class QPainter;
312 friend class QPainterPrivate;
313 friend class QPSPrintEngineFont;
314 friend class QApplication;
315 friend class QWidget;
316 friend class QWidgetPrivate;
317 friend class Q3TextFormatCollection;
318 friend class QTextLayout;
319 friend class QTextEngine;
320 friend class QStackTextEngine;
321 friend class QTextLine;
322 friend struct QScriptLine;
323 friend class QGLContext;
324 friend class QWin32PaintEngine;
325 friend class QAlphaPaintEngine;
326 friend class QPainterPath;
327 friend class QTextItemInt;
328 friend class QPicturePaintEngine;
329 friend class QPainterReplayer;
330 friend class QPaintBufferEngine;
331 friend class QCommandLinkButtonPrivate;
332 friend class QFontEngine;
334 #ifndef QT_NO_DATASTREAM
335 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
336 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
339 QExplicitlySharedDataPointer<QFontPrivate> d;
344 inline bool QFont::bold() const
345 { return weight() > Normal; }
348 inline void QFont::setBold(bool enable)
349 { setWeight(enable ? Bold : Normal); }
351 inline bool QFont::italic() const
353 return (style() != StyleNormal);
356 inline void QFont::setItalic(bool b) {
357 setStyle(b ? StyleItalic : StyleNormal);
361 /*****************************************************************************
362 QFont stream functions
363 *****************************************************************************/
365 #ifndef QT_NO_DATASTREAM
366 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
367 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
370 #ifndef QT_NO_DEBUG_STREAM
371 Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);