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 */
59 class Q_GUI_EXPORT QFont
62 Q_ENUMS(StyleStrategy)
65 Helvetica, SansSerif = Helvetica,
67 Courier, TypeWriter = Courier,
68 OldEnglish, Decorative = OldEnglish,
77 PreferDefault = 0x0001,
78 PreferBitmap = 0x0002,
79 PreferDevice = 0x0004,
80 PreferOutline = 0x0008,
81 ForceOutline = 0x0010,
83 PreferQuality = 0x0040,
84 PreferAntialias = 0x0080,
86 OpenGLCompatible = 0x0200,
87 ForceIntegerMetrics = 0x0400,
88 NoFontMerging = 0x8000
91 enum HintingPreference {
92 PreferDefaultHinting = 0,
94 PreferVerticalHinting = 2,
124 enum Capitalization {
137 enum ResolveProperties {
138 FamilyResolved = 0x0001,
139 SizeResolved = 0x0002,
140 StyleHintResolved = 0x0004,
141 StyleStrategyResolved = 0x0008,
142 WeightResolved = 0x0010,
143 StyleResolved = 0x0020,
144 UnderlineResolved = 0x0040,
145 OverlineResolved = 0x0080,
146 StrikeOutResolved = 0x0100,
147 FixedPitchResolved = 0x0200,
148 StretchResolved = 0x0400,
149 KerningResolved = 0x0800,
150 CapitalizationResolved = 0x1000,
151 LetterSpacingResolved = 0x2000,
152 WordSpacingResolved = 0x4000,
153 HintingPreferenceResolved = 0x8000,
154 StyleNameResolved = 0x10000,
155 AllPropertiesResolved = 0x1ffff
159 QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
160 QFont(const QFont &, QPaintDevice *pd);
161 QFont(const QFont &);
164 QString family() const;
165 void setFamily(const QString &);
167 QString styleName() const;
168 void setStyleName(const QString &);
170 int pointSize() const;
171 void setPointSize(int);
172 qreal pointSizeF() const;
173 void setPointSizeF(qreal);
175 int pixelSize() const;
176 void setPixelSize(int);
181 inline bool bold() const;
182 inline void setBold(bool);
184 void setStyle(Style style);
187 inline bool italic() const;
188 inline void setItalic(bool b);
190 bool underline() const;
191 void setUnderline(bool);
193 bool overline() const;
194 void setOverline(bool);
196 bool strikeOut() const;
197 void setStrikeOut(bool);
199 bool fixedPitch() const;
200 void setFixedPitch(bool);
202 bool kerning() const;
203 void setKerning(bool);
205 StyleHint styleHint() const;
206 StyleStrategy styleStrategy() const;
207 void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
208 void setStyleStrategy(StyleStrategy s);
211 void setStretch(int);
213 qreal letterSpacing() const;
214 SpacingType letterSpacingType() const;
215 void setLetterSpacing(SpacingType type, qreal spacing);
217 qreal wordSpacing() const;
218 void setWordSpacing(qreal spacing);
220 void setCapitalization(Capitalization);
221 Capitalization capitalization() const;
223 void setHintingPreference(HintingPreference hintingPreference);
224 HintingPreference hintingPreference() const;
226 // is raw mode still needed?
227 bool rawMode() const;
228 void setRawMode(bool);
230 // dupicated from QFontInfo
231 bool exactMatch() const;
233 QFont &operator=(const QFont &);
234 bool operator==(const QFont &) const;
235 bool operator!=(const QFont &) const;
236 bool operator<(const QFont &) const;
237 operator QVariant() const;
238 bool isCopyOf(const QFont &) const;
239 #ifdef Q_COMPILER_RVALUE_REFS
240 inline QFont &operator=(QFont &&other)
241 { qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask); return *this; }
245 void setRawName(const QString &);
246 QString rawName() const;
250 QString toString() const;
251 bool fromString(const QString &);
253 static QString substitute(const QString &);
254 static QStringList substitutes(const QString &);
255 static QStringList substitutions();
256 static void insertSubstitution(const QString&, const QString &);
257 static void insertSubstitutions(const QString&, const QStringList &);
258 static void removeSubstitutions(const QString &);
259 #if QT_DEPRECATED_SINCE(5, 0)
260 static QT_DEPRECATED void removeSubstitution(const QString &family) { removeSubstitutions(family); }
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 QTextLayout;
292 friend class QTextEngine;
293 friend class QStackTextEngine;
294 friend class QTextLine;
295 friend struct QScriptLine;
296 friend class QOpenGLContext;
297 friend class QWin32PaintEngine;
298 friend class QAlphaPaintEngine;
299 friend class QPainterPath;
300 friend class QTextItemInt;
301 friend class QPicturePaintEngine;
302 friend class QPainterReplayer;
303 friend class QPaintBufferEngine;
304 friend class QCommandLinkButtonPrivate;
305 friend class QFontEngine;
307 #ifndef QT_NO_DATASTREAM
308 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
309 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
312 QExplicitlySharedDataPointer<QFontPrivate> d;
317 inline bool QFont::bold() const
318 { return weight() > Normal; }
321 inline void QFont::setBold(bool enable)
322 { setWeight(enable ? Bold : Normal); }
324 inline bool QFont::italic() const
326 return (style() != StyleNormal);
329 inline void QFont::setItalic(bool b) {
330 setStyle(b ? StyleItalic : StyleNormal);
334 /*****************************************************************************
335 QFont stream functions
336 *****************************************************************************/
338 #ifndef QT_NO_DATASTREAM
339 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
340 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
343 #ifndef QT_NO_DEBUG_STREAM
344 Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);