1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QFONT_H
41#define QFONT_H
42
43#include <QtGui/qtguiglobal.h>
44#include <QtGui/qwindowdefs.h>
45#include <QtCore/qstring.h>
46#include <QtCore/qsharedpointer.h>
47
48
49QT_BEGIN_NAMESPACE
50
51
52class QFontPrivate; /* don't touch */
53class QStringList;
54class QVariant;
55
56class Q_GUI_EXPORT QFont
57{
58 Q_GADGET
59public:
60 enum StyleHint {
61 Helvetica, SansSerif = Helvetica,
62 Times, Serif = Times,
63 Courier, TypeWriter = Courier,
64 OldEnglish, Decorative = OldEnglish,
65 System,
66 AnyStyle,
67 Cursive,
68 Monospace,
69 Fantasy
70 };
71 Q_ENUM(StyleHint)
72
73 enum StyleStrategy {
74 PreferDefault = 0x0001,
75 PreferBitmap = 0x0002,
76 PreferDevice = 0x0004,
77 PreferOutline = 0x0008,
78 ForceOutline = 0x0010,
79 PreferMatch = 0x0020,
80 PreferQuality = 0x0040,
81 PreferAntialias = 0x0080,
82 NoAntialias = 0x0100,
83 OpenGLCompatible = 0x0200,
84 ForceIntegerMetrics = 0x0400,
85 NoSubpixelAntialias = 0x0800,
86 PreferNoShaping = 0x1000,
87 NoFontMerging = 0x8000
88 };
89 Q_ENUM(StyleStrategy)
90
91 enum HintingPreference {
92 PreferDefaultHinting = 0,
93 PreferNoHinting = 1,
94 PreferVerticalHinting = 2,
95 PreferFullHinting = 3
96 };
97 Q_ENUM(HintingPreference)
98
99 // Mapping OpenType weight value.
100 enum Weight {
101 Thin = 0, // 100
102 ExtraLight = 12, // 200
103 Light = 25, // 300
104 Normal = 50, // 400
105 Medium = 57, // 500
106 DemiBold = 63, // 600
107 Bold = 75, // 700
108 ExtraBold = 81, // 800
109 Black = 87 // 900
110 };
111 Q_ENUM(Weight)
112
113 enum Style {
114 StyleNormal,
115 StyleItalic,
116 StyleOblique
117 };
118 Q_ENUM(Style)
119
120 enum Stretch {
121 AnyStretch = 0,
122 UltraCondensed = 50,
123 ExtraCondensed = 62,
124 Condensed = 75,
125 SemiCondensed = 87,
126 Unstretched = 100,
127 SemiExpanded = 112,
128 Expanded = 125,
129 ExtraExpanded = 150,
130 UltraExpanded = 200
131 };
132 Q_ENUM(Stretch)
133
134 enum Capitalization {
135 MixedCase,
136 AllUppercase,
137 AllLowercase,
138 SmallCaps,
139 Capitalize
140 };
141 Q_ENUM(Capitalization)
142
143 enum SpacingType {
144 PercentageSpacing,
145 AbsoluteSpacing
146 };
147 Q_ENUM(SpacingType)
148
149 enum ResolveProperties {
150 FamilyResolved = 0x0001,
151 SizeResolved = 0x0002,
152 StyleHintResolved = 0x0004,
153 StyleStrategyResolved = 0x0008,
154 WeightResolved = 0x0010,
155 StyleResolved = 0x0020,
156 UnderlineResolved = 0x0040,
157 OverlineResolved = 0x0080,
158 StrikeOutResolved = 0x0100,
159 FixedPitchResolved = 0x0200,
160 StretchResolved = 0x0400,
161 KerningResolved = 0x0800,
162 CapitalizationResolved = 0x1000,
163 LetterSpacingResolved = 0x2000,
164 WordSpacingResolved = 0x4000,
165 HintingPreferenceResolved = 0x8000,
166 StyleNameResolved = 0x10000,
167 AllPropertiesResolved = 0x1ffff
168 };
169
170 QFont();
171 QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
172 QFont(const QFont &, QPaintDevice *pd);
173 QFont(const QFont &);
174 ~QFont();
175
176 void swap(QFont &other)
177 { qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask); }
178
179 QString family() const;
180 void setFamily(const QString &);
181
182 QString styleName() const;
183 void setStyleName(const QString &);
184
185 int pointSize() const;
186 void setPointSize(int);
187 qreal pointSizeF() const;
188 void setPointSizeF(qreal);
189
190 int pixelSize() const;
191 void setPixelSize(int);
192
193 int weight() const;
194 void setWeight(int);
195
196 inline bool bold() const;
197 inline void setBold(bool);
198
199 void setStyle(Style style);
200 Style style() const;
201
202 inline bool italic() const;
203 inline void setItalic(bool b);
204
205 bool underline() const;
206 void setUnderline(bool);
207
208 bool overline() const;
209 void setOverline(bool);
210
211 bool strikeOut() const;
212 void setStrikeOut(bool);
213
214 bool fixedPitch() const;
215 void setFixedPitch(bool);
216
217 bool kerning() const;
218 void setKerning(bool);
219
220 StyleHint styleHint() const;
221 StyleStrategy styleStrategy() const;
222 void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
223 void setStyleStrategy(StyleStrategy s);
224
225 int stretch() const;
226 void setStretch(int);
227
228 qreal letterSpacing() const;
229 SpacingType letterSpacingType() const;
230 void setLetterSpacing(SpacingType type, qreal spacing);
231
232 qreal wordSpacing() const;
233 void setWordSpacing(qreal spacing);
234
235 void setCapitalization(Capitalization);
236 Capitalization capitalization() const;
237
238 void setHintingPreference(HintingPreference hintingPreference);
239 HintingPreference hintingPreference() const;
240
241#if QT_DEPRECATED_SINCE(5, 5)
242 bool rawMode() const;
243 void setRawMode(bool);
244#endif
245
246 // dupicated from QFontInfo
247 bool exactMatch() const;
248
249 QFont &operator=(const QFont &);
250 bool operator==(const QFont &) const;
251 bool operator!=(const QFont &) const;
252 bool operator<(const QFont &) const;
253 operator QVariant() const;
254 bool isCopyOf(const QFont &) const;
255#ifdef Q_COMPILER_RVALUE_REFS
256 inline QFont &operator=(QFont &&other) Q_DECL_NOEXCEPT
257 { qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask); return *this; }
258#endif
259
260#if QT_DEPRECATED_SINCE(5, 3)
261 // needed for X11
262 QT_DEPRECATED void setRawName(const QString &);
263 QT_DEPRECATED QString rawName() const;
264#endif
265
266 QString key() const;
267
268 QString toString() const;
269 bool fromString(const QString &);
270
271 static QString substitute(const QString &);
272 static QStringList substitutes(const QString &);
273 static QStringList substitutions();
274 static void insertSubstitution(const QString&, const QString &);
275 static void insertSubstitutions(const QString&, const QStringList &);
276 static void removeSubstitutions(const QString &);
277#if QT_DEPRECATED_SINCE(5, 0)
278 static QT_DEPRECATED void removeSubstitution(const QString &family) { removeSubstitutions(family); }
279#endif
280 static void initialize();
281 static void cleanup();
282 static void cacheStatistics();
283
284 QString defaultFamily() const;
285 QString lastResortFamily() const;
286 QString lastResortFont() const;
287
288 QFont resolve(const QFont &) const;
289 inline uint resolve() const { return resolve_mask; }
290 inline void resolve(uint mask) { resolve_mask = mask; }
291
292private:
293 explicit QFont(QFontPrivate *);
294
295 void detach();
296
297
298 friend class QFontPrivate;
299 friend class QFontDialogPrivate;
300 friend class QFontMetrics;
301 friend class QFontMetricsF;
302 friend class QFontInfo;
303 friend class QPainter;
304 friend class QPainterPrivate;
305 friend class QApplication;
306 friend class QWidget;
307 friend class QWidgetPrivate;
308 friend class QTextLayout;
309 friend class QTextEngine;
310 friend class QStackTextEngine;
311 friend class QTextLine;
312 friend struct QScriptLine;
313 friend class QOpenGLContext;
314 friend class QWin32PaintEngine;
315 friend class QAlphaPaintEngine;
316 friend class QPainterPath;
317 friend class QTextItemInt;
318 friend class QPicturePaintEngine;
319 friend class QPainterReplayer;
320 friend class QPaintBufferEngine;
321 friend class QCommandLinkButtonPrivate;
322 friend class QFontEngine;
323
324#ifndef QT_NO_DATASTREAM
325 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
326 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
327#endif
328
329 QExplicitlySharedDataPointer<QFontPrivate> d;
330 uint resolve_mask;
331};
332
333Q_DECLARE_SHARED(QFont)
334
335Q_GUI_EXPORT uint qHash(const QFont &font, uint seed = 0) Q_DECL_NOTHROW;
336
337inline bool QFont::bold() const
338{ return weight() > Medium; }
339
340
341inline void QFont::setBold(bool enable)
342{ setWeight(enable ? Bold : Normal); }
343
344inline bool QFont::italic() const
345{
346 return (style() != StyleNormal);
347}
348
349inline void QFont::setItalic(bool b) {
350 setStyle(b ? StyleItalic : StyleNormal);
351}
352
353
354/*****************************************************************************
355 QFont stream functions
356 *****************************************************************************/
357
358#ifndef QT_NO_DATASTREAM
359Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
360Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
361#endif
362
363#ifndef QT_NO_DEBUG_STREAM
364Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
365#endif
366
367QT_END_NAMESPACE
368
369#endif // QFONT_H
370