1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
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#include <QtCore/qsharedpointer.h>
48
49#if defined(Q_WS_X11) || defined(Q_WS_QWS)
50typedef struct FT_FaceRec_* FT_Face;
51#endif
52
53QT_BEGIN_HEADER
54
55QT_BEGIN_NAMESPACE
56
57QT_MODULE(Gui)
58
59class QFontPrivate; /* don't touch */
60class QStringList;
61class QVariant;
62class Q3TextFormatCollection;
63
64class Q_GUI_EXPORT QFont
65{
66 Q_GADGET
67 Q_ENUMS(StyleStrategy)
68public:
69 enum StyleHint {
70 Helvetica, SansSerif = Helvetica,
71 Times, Serif = Times,
72 Courier, TypeWriter = Courier,
73 OldEnglish, Decorative = OldEnglish,
74 System,
75 AnyStyle,
76 Cursive,
77 Monospace,
78 Fantasy
79 };
80
81 enum StyleStrategy {
82 PreferDefault = 0x0001,
83 PreferBitmap = 0x0002,
84 PreferDevice = 0x0004,
85 PreferOutline = 0x0008,
86 ForceOutline = 0x0010,
87 PreferMatch = 0x0020,
88 PreferQuality = 0x0040,
89 PreferAntialias = 0x0080,
90 NoAntialias = 0x0100,
91 OpenGLCompatible = 0x0200,
92 ForceIntegerMetrics = 0x0400,
93 NoFontMerging = 0x8000
94 };
95
96 enum HintingPreference {
97 PreferDefaultHinting = 0,
98 PreferNoHinting = 1,
99 PreferVerticalHinting = 2,
100 PreferFullHinting = 3
101 };
102
103 enum Weight {
104 Light = 25,
105 Normal = 50,
106 DemiBold = 63,
107 Bold = 75,
108 Black = 87
109 };
110
111 enum Style {
112 StyleNormal,
113 StyleItalic,
114 StyleOblique
115 };
116
117 enum Stretch {
118 UltraCondensed = 50,
119 ExtraCondensed = 62,
120 Condensed = 75,
121 SemiCondensed = 87,
122 Unstretched = 100,
123 SemiExpanded = 112,
124 Expanded = 125,
125 ExtraExpanded = 150,
126 UltraExpanded = 200
127 };
128
129 enum Capitalization {
130 MixedCase,
131 AllUppercase,
132 AllLowercase,
133 SmallCaps,
134 Capitalize
135 };
136
137 enum SpacingType {
138 PercentageSpacing,
139 AbsoluteSpacing
140 };
141
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
161 };
162
163 QFont();
164 QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
165 QFont(const QFont &, QPaintDevice *pd);
166 QFont(const QFont &);
167 ~QFont();
168
169 QString family() const;
170 void setFamily(const QString &);
171
172 QString styleName() const;
173 void setStyleName(const QString &);
174
175 int pointSize() const;
176 void setPointSize(int);
177 qreal pointSizeF() const;
178 void setPointSizeF(qreal);
179
180 int pixelSize() const;
181 void setPixelSize(int);
182
183 int weight() const;
184 void setWeight(int);
185
186 inline bool bold() const;
187 inline void setBold(bool);
188
189 void setStyle(Style style);
190 Style style() const;
191
192 inline bool italic() const;
193 inline void setItalic(bool b);
194
195 bool underline() const;
196 void setUnderline(bool);
197
198 bool overline() const;
199 void setOverline(bool);
200
201 bool strikeOut() const;
202 void setStrikeOut(bool);
203
204 bool fixedPitch() const;
205 void setFixedPitch(bool);
206
207 bool kerning() const;
208 void setKerning(bool);
209
210 StyleHint styleHint() const;
211 StyleStrategy styleStrategy() const;
212 void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
213 void setStyleStrategy(StyleStrategy s);
214
215 int stretch() const;
216 void setStretch(int);
217
218 qreal letterSpacing() const;
219 SpacingType letterSpacingType() const;
220 void setLetterSpacing(SpacingType type, qreal spacing);
221
222 qreal wordSpacing() const;
223 void setWordSpacing(qreal spacing);
224
225 void setCapitalization(Capitalization);
226 Capitalization capitalization() const;
227
228 void setHintingPreference(HintingPreference hintingPreference);
229 HintingPreference hintingPreference() const;
230
231 // is raw mode still needed?
232 bool rawMode() const;
233 void setRawMode(bool);
234
235 // dupicated from QFontInfo
236 bool exactMatch() const;
237
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; }
247#endif
248
249#ifdef Q_WS_WIN
250 HFONT handle() const;
251#else // !Q_WS_WIN
252 Qt::HANDLE handle() const;
253#endif // Q_WS_WIN
254#ifdef Q_WS_MAC
255 quint32 macFontID() const;
256#endif
257#if defined(Q_WS_X11) || defined(Q_WS_QWS)
258 FT_Face freetypeFace() const;
259#endif
260
261 // needed for X11
262 void setRawName(const QString &);
263 QString rawName() const;
264
265 QString key() const;
266
267 QString toString() const;
268 bool fromString(const QString &);
269
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();
278#ifndef Q_WS_QWS
279 static void cacheStatistics();
280#endif
281
282 QString defaultFamily() const;
283 QString lastResortFamily() const;
284 QString lastResortFont() const;
285
286 QFont resolve(const QFont &) const;
287 inline uint resolve() const { return resolve_mask; }
288 inline void resolve(uint mask) { resolve_mask = mask; }
289
290#ifdef QT3_SUPPORT
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); }
296#endif
297
298private:
299 QFont(QFontPrivate *);
300
301 void detach();
302
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;
308#endif
309
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;
337
338#ifndef QT_NO_DATASTREAM
339 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
340 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
341#endif
342
343 QExplicitlySharedDataPointer<QFontPrivate> d;
344 uint resolve_mask;
345};
346
347
348inline bool QFont::bold() const
349{ return weight() > Normal; }
350
351
352inline void QFont::setBold(bool enable)
353{ setWeight(enable ? Bold : Normal); }
354
355inline bool QFont::italic() const
356{
357 return (style() != StyleNormal);
358}
359
360inline void QFont::setItalic(bool b) {
361 setStyle(b ? StyleItalic : StyleNormal);
362}
363
364
365/*****************************************************************************
366 QFont stream functions
367 *****************************************************************************/
368
369#ifndef QT_NO_DATASTREAM
370Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
371Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
372#endif
373
374#ifndef QT_NO_DEBUG_STREAM
375Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
376#endif
377
378QT_END_NAMESPACE
379
380QT_END_HEADER
381
382#endif // QFONT_H
383