1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** 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>
55 class QFontPrivate; /* don't touch */
58 class Q3TextFormatCollection;
60 class Q_GUI_EXPORT QFont
63 Q_ENUMS(StyleStrategy)
66 Helvetica, SansSerif = Helvetica,
68 Courier, TypeWriter = Courier,
69 OldEnglish, Decorative = OldEnglish,
78 PreferDefault = 0x0001,
79 PreferBitmap = 0x0002,
80 PreferDevice = 0x0004,
81 PreferOutline = 0x0008,
82 ForceOutline = 0x0010,
84 PreferQuality = 0x0040,
85 PreferAntialias = 0x0080,
87 OpenGLCompatible = 0x0200,
88 ForceIntegerMetrics = 0x0400,
89 NoFontMerging = 0x8000
92 enum HintingPreference {
93 PreferDefaultHinting = 0,
95 PreferVerticalHinting = 2,
125 enum Capitalization {
138 enum ResolveProperties {
139 FamilyResolved = 0x0001,
140 SizeResolved = 0x0002,
141 StyleHintResolved = 0x0004,
142 StyleStrategyResolved = 0x0008,
143 WeightResolved = 0x0010,
144 StyleResolved = 0x0020,
145 UnderlineResolved = 0x0040,
146 OverlineResolved = 0x0080,
147 StrikeOutResolved = 0x0100,
148 FixedPitchResolved = 0x0200,
149 StretchResolved = 0x0400,
150 KerningResolved = 0x0800,
151 CapitalizationResolved = 0x1000,
152 LetterSpacingResolved = 0x2000,
153 WordSpacingResolved = 0x4000,
154 HintingPreferenceResolved = 0x8000,
155 StyleNameResolved = 0x10000,
156 AllPropertiesResolved = 0x1ffff
160 QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
161 QFont(const QFont &, QPaintDevice *pd);
162 QFont(const QFont &);
165 QString family() const;
166 void setFamily(const QString &);
168 QString styleName() const;
169 void setStyleName(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; }
245 Qt::HANDLE handle() const;
248 void setRawName(const QString &);
249 QString rawName() const;
253 QString toString() const;
254 bool fromString(const QString &);
256 static QString substitute(const QString &);
257 static QStringList substitutes(const QString &);
258 static QStringList substitutions();
259 static void insertSubstitution(const QString&, const QString &);
260 static void insertSubstitutions(const QString&, const QStringList &);
261 static void removeSubstitution(const QString &);
262 static void initialize();
263 static void cleanup();
264 static void cacheStatistics();
266 QString defaultFamily() const;
267 QString lastResortFamily() const;
268 QString lastResortFont() const;
270 QFont resolve(const QFont &) const;
271 inline uint resolve() const { return resolve_mask; }
272 inline void resolve(uint mask) { resolve_mask = mask; }
275 explicit QFont(QFontPrivate *);
280 friend class QFontPrivate;
281 friend class QFontDialogPrivate;
282 friend class QFontMetrics;
283 friend class QFontMetricsF;
284 friend class QFontInfo;
285 friend class QPainter;
286 friend class QPainterPrivate;
287 friend class QPSPrintEngineFont;
288 friend class QApplication;
289 friend class QWidget;
290 friend class QWidgetPrivate;
291 friend class Q3TextFormatCollection;
292 friend class QTextLayout;
293 friend class QTextEngine;
294 friend class QStackTextEngine;
295 friend class QTextLine;
296 friend struct QScriptLine;
297 friend class QOpenGLContext;
298 friend class QWin32PaintEngine;
299 friend class QAlphaPaintEngine;
300 friend class QPainterPath;
301 friend class QTextItemInt;
302 friend class QPicturePaintEngine;
303 friend class QPainterReplayer;
304 friend class QPaintBufferEngine;
305 friend class QCommandLinkButtonPrivate;
306 friend class QFontEngine;
308 #ifndef QT_NO_DATASTREAM
309 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
310 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
313 QExplicitlySharedDataPointer<QFontPrivate> d;
318 inline bool QFont::bold() const
319 { return weight() > Normal; }
322 inline void QFont::setBold(bool enable)
323 { setWeight(enable ? Bold : Normal); }
325 inline bool QFont::italic() const
327 return (style() != StyleNormal);
330 inline void QFont::setItalic(bool b) {
331 setStyle(b ? StyleItalic : StyleNormal);
335 /*****************************************************************************
336 QFont stream functions
337 *****************************************************************************/
339 #ifndef QT_NO_DATASTREAM
340 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
341 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
344 #ifndef QT_NO_DEBUG_STREAM
345 Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);