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 QVariant;
54
55class Q_GUI_EXPORT QFont
56{
57 Q_GADGET
58public:
59 enum StyleHint {
60 Helvetica, SansSerif = Helvetica,
61 Times, Serif = Times,
62 Courier, TypeWriter = Courier,
63 OldEnglish, Decorative = OldEnglish,
64 System,
65 AnyStyle,
66 Cursive,
67 Monospace,
68 Fantasy
69 };
70 Q_ENUM(StyleHint)
71
72 enum StyleStrategy {
73 PreferDefault = 0x0001,
74 PreferBitmap = 0x0002,
75 PreferDevice = 0x0004,
76 PreferOutline = 0x0008,
77 ForceOutline = 0x0010,
78 PreferMatch = 0x0020,
79 PreferQuality = 0x0040,
80 PreferAntialias = 0x0080,
81 NoAntialias = 0x0100,
82 NoSubpixelAntialias = 0x0800,
83 PreferNoShaping = 0x1000,
84 NoFontMerging = 0x8000
85 };
86 Q_ENUM(StyleStrategy)
87
88 enum HintingPreference {
89 PreferDefaultHinting = 0,
90 PreferNoHinting = 1,
91 PreferVerticalHinting = 2,
92 PreferFullHinting = 3
93 };
94 Q_ENUM(HintingPreference)
95
96 enum Weight {
97 Thin = 100,
98 ExtraLight = 200,
99 Light = 300,
100 Normal = 400,
101 Medium = 500,
102 DemiBold = 600,
103 Bold = 700,
104 ExtraBold = 800,
105 Black = 900
106 };
107 Q_ENUM(Weight)
108
109 enum Style {
110 StyleNormal,
111 StyleItalic,
112 StyleOblique
113 };
114 Q_ENUM(Style)
115
116 enum Stretch {
117 AnyStretch = 0,
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 Q_ENUM(Stretch)
129
130 enum Capitalization {
131 MixedCase,
132 AllUppercase,
133 AllLowercase,
134 SmallCaps,
135 Capitalize
136 };
137 Q_ENUM(Capitalization)
138
139 enum SpacingType {
140 PercentageSpacing,
141 AbsoluteSpacing
142 };
143 Q_ENUM(SpacingType)
144
145 enum ResolveProperties {
146 NoPropertiesResolved = 0x0000,
147 FamilyResolved = 0x0001,
148 SizeResolved = 0x0002,
149 StyleHintResolved = 0x0004,
150 StyleStrategyResolved = 0x0008,
151 WeightResolved = 0x0010,
152 StyleResolved = 0x0020,
153 UnderlineResolved = 0x0040,
154 OverlineResolved = 0x0080,
155 StrikeOutResolved = 0x0100,
156 FixedPitchResolved = 0x0200,
157 StretchResolved = 0x0400,
158 KerningResolved = 0x0800,
159 CapitalizationResolved = 0x1000,
160 LetterSpacingResolved = 0x2000,
161 WordSpacingResolved = 0x4000,
162 HintingPreferenceResolved = 0x8000,
163 StyleNameResolved = 0x10000,
164 FamiliesResolved = 0x20000,
165 AllPropertiesResolved = 0x3ffff
166 };
167 Q_ENUM(ResolveProperties)
168
169 QFont();
170 QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
171#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
172 QFont(const QFont &font, QPaintDevice *pd);
173#endif
174 QFont(const QFont &font, const QPaintDevice *pd);
175 QFont(const QFont &font);
176 ~QFont();
177
178 void swap(QFont &other)
179 { qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask); }
180
181 QString family() const;
182 void setFamily(const QString &);
183
184 QStringList families() const;
185 void setFamilies(const QStringList &);
186
187 QString styleName() const;
188 void setStyleName(const QString &);
189
190 int pointSize() const;
191 void setPointSize(int);
192 qreal pointSizeF() const;
193 void setPointSizeF(qreal);
194
195 int pixelSize() const;
196 void setPixelSize(int);
197
198 Weight weight() const;
199 void setWeight(Weight weight);
200
201 inline bool bold() const;
202 inline void setBold(bool);
203
204 void setStyle(Style style);
205 Style style() const;
206
207 inline bool italic() const;
208 inline void setItalic(bool b);
209
210 bool underline() const;
211 void setUnderline(bool);
212
213 bool overline() const;
214 void setOverline(bool);
215
216 bool strikeOut() const;
217 void setStrikeOut(bool);
218
219 bool fixedPitch() const;
220 void setFixedPitch(bool);
221
222 bool kerning() const;
223 void setKerning(bool);
224
225 StyleHint styleHint() const;
226 StyleStrategy styleStrategy() const;
227 void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
228 void setStyleStrategy(StyleStrategy s);
229
230 int stretch() const;
231 void setStretch(int);
232
233 qreal letterSpacing() const;
234 SpacingType letterSpacingType() const;
235 void setLetterSpacing(SpacingType type, qreal spacing);
236
237 qreal wordSpacing() const;
238 void setWordSpacing(qreal spacing);
239
240 void setCapitalization(Capitalization);
241 Capitalization capitalization() const;
242
243 void setHintingPreference(HintingPreference hintingPreference);
244 HintingPreference hintingPreference() const;
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 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFont)
256
257 QString key() const;
258
259 QString toString() const;
260 bool fromString(const QString &);
261
262 static QString substitute(const QString &);
263 static QStringList substitutes(const QString &);
264 static QStringList substitutions();
265 static void insertSubstitution(const QString&, const QString &);
266 static void insertSubstitutions(const QString&, const QStringList &);
267 static void removeSubstitutions(const QString &);
268 static void initialize();
269 static void cleanup();
270 static void cacheStatistics();
271
272 QString defaultFamily() const;
273
274 QFont resolve(const QFont &) const;
275 inline uint resolveMask() const { return resolve_mask; }
276 inline void setResolveMask(uint mask) { resolve_mask = mask; }
277
278private:
279 explicit QFont(QFontPrivate *);
280
281 void detach();
282
283
284 friend class QFontPrivate;
285 friend class QFontDialogPrivate;
286 friend class QFontMetrics;
287 friend class QFontMetricsF;
288 friend class QFontInfo;
289 friend class QPainter;
290 friend class QPainterPrivate;
291 friend class QApplication;
292 friend class QWidget;
293 friend class QWidgetPrivate;
294 friend class QTextLayout;
295 friend class QTextEngine;
296 friend class QStackTextEngine;
297 friend class QTextLine;
298 friend struct QScriptLine;
299 friend class QOpenGLContext;
300 friend class QWin32PaintEngine;
301 friend class QAlphaPaintEngine;
302 friend class QPainterPath;
303 friend class QTextItemInt;
304 friend class QPicturePaintEngine;
305 friend class QPainterReplayer;
306 friend class QPaintBufferEngine;
307 friend class QCommandLinkButtonPrivate;
308 friend class QFontEngine;
309
310#ifndef QT_NO_DATASTREAM
311 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
312 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
313#endif
314
315#ifndef QT_NO_DEBUG_STREAM
316 friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
317#endif
318
319 QExplicitlySharedDataPointer<QFontPrivate> d;
320 uint resolve_mask;
321};
322
323Q_DECLARE_SHARED(QFont)
324
325Q_GUI_EXPORT size_t qHash(const QFont &font, size_t seed = 0) noexcept;
326
327inline bool QFont::bold() const
328{ return weight() > Medium; }
329
330
331inline void QFont::setBold(bool enable)
332{ setWeight(enable ? Bold : Normal); }
333
334inline bool QFont::italic() const
335{
336 return (style() != StyleNormal);
337}
338
339inline void QFont::setItalic(bool b) {
340 setStyle(b ? StyleItalic : StyleNormal);
341}
342
343
344/*****************************************************************************
345 QFont stream functions
346 *****************************************************************************/
347
348#ifndef QT_NO_DATASTREAM
349Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
350Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
351#endif
352
353#ifndef QT_NO_DEBUG_STREAM
354Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
355#endif
356
357QT_END_NAMESPACE
358
359#endif // QFONT_H
360