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 NoPropertiesResolved = 0x0000,
151 FamilyResolved = 0x0001,
152 SizeResolved = 0x0002,
153 StyleHintResolved = 0x0004,
154 StyleStrategyResolved = 0x0008,
155 WeightResolved = 0x0010,
156 StyleResolved = 0x0020,
157 UnderlineResolved = 0x0040,
158 OverlineResolved = 0x0080,
159 StrikeOutResolved = 0x0100,
160 FixedPitchResolved = 0x0200,
161 StretchResolved = 0x0400,
162 KerningResolved = 0x0800,
163 CapitalizationResolved = 0x1000,
164 LetterSpacingResolved = 0x2000,
165 WordSpacingResolved = 0x4000,
166 HintingPreferenceResolved = 0x8000,
167 StyleNameResolved = 0x10000,
168 FamiliesResolved = 0x20000,
169 AllPropertiesResolved = 0x3ffff
170 };
171 Q_ENUM(ResolveProperties)
172
173 QFont();
174 QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
175#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
176 QFont(const QFont &font, QPaintDevice *pd);
177#endif
178 QFont(const QFont &font, const QPaintDevice *pd);
179 QFont(const QFont &font);
180 ~QFont();
181
182 void swap(QFont &other)
183 { qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask); }
184
185 QString family() const;
186 void setFamily(const QString &);
187
188 QStringList families() const;
189 void setFamilies(const QStringList &);
190
191 QString styleName() const;
192 void setStyleName(const QString &);
193
194 int pointSize() const;
195 void setPointSize(int);
196 qreal pointSizeF() const;
197 void setPointSizeF(qreal);
198
199 int pixelSize() const;
200 void setPixelSize(int);
201
202 int weight() const;
203 void setWeight(int);
204
205 inline bool bold() const;
206 inline void setBold(bool);
207
208 void setStyle(Style style);
209 Style style() const;
210
211 inline bool italic() const;
212 inline void setItalic(bool b);
213
214 bool underline() const;
215 void setUnderline(bool);
216
217 bool overline() const;
218 void setOverline(bool);
219
220 bool strikeOut() const;
221 void setStrikeOut(bool);
222
223 bool fixedPitch() const;
224 void setFixedPitch(bool);
225
226 bool kerning() const;
227 void setKerning(bool);
228
229 StyleHint styleHint() const;
230 StyleStrategy styleStrategy() const;
231 void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
232 void setStyleStrategy(StyleStrategy s);
233
234 int stretch() const;
235 void setStretch(int);
236
237 qreal letterSpacing() const;
238 SpacingType letterSpacingType() const;
239 void setLetterSpacing(SpacingType type, qreal spacing);
240
241 qreal wordSpacing() const;
242 void setWordSpacing(qreal spacing);
243
244 void setCapitalization(Capitalization);
245 Capitalization capitalization() const;
246
247 void setHintingPreference(HintingPreference hintingPreference);
248 HintingPreference hintingPreference() const;
249
250#if QT_DEPRECATED_SINCE(5, 5)
251 bool rawMode() const;
252 void setRawMode(bool);
253#endif
254
255 // dupicated from QFontInfo
256 bool exactMatch() const;
257
258 QFont &operator=(const QFont &);
259 bool operator==(const QFont &) const;
260 bool operator!=(const QFont &) const;
261 bool operator<(const QFont &) const;
262 operator QVariant() const;
263 bool isCopyOf(const QFont &) const;
264 inline QFont &operator=(QFont &&other) noexcept
265 { qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask); return *this; }
266
267#if QT_DEPRECATED_SINCE(5, 3)
268 // needed for X11
269 QT_DEPRECATED void setRawName(const QString &);
270 QT_DEPRECATED QString rawName() const;
271#endif
272
273 QString key() const;
274
275 QString toString() const;
276 bool fromString(const QString &);
277
278 static QString substitute(const QString &);
279 static QStringList substitutes(const QString &);
280 static QStringList substitutions();
281 static void insertSubstitution(const QString&, const QString &);
282 static void insertSubstitutions(const QString&, const QStringList &);
283 static void removeSubstitutions(const QString &);
284#if QT_DEPRECATED_SINCE(5, 0)
285 static QT_DEPRECATED void removeSubstitution(const QString &family) { removeSubstitutions(family); }
286#endif
287 static void initialize();
288 static void cleanup();
289 static void cacheStatistics();
290
291 QString defaultFamily() const;
292#if QT_DEPRECATED_SINCE(5, 13)
293 QT_DEPRECATED QString lastResortFamily() const;
294 QT_DEPRECATED QString lastResortFont() const;
295#endif
296
297 QFont resolve(const QFont &) const;
298 inline uint resolve() const { return resolve_mask; }
299 inline void resolve(uint mask) { resolve_mask = mask; }
300
301private:
302 explicit QFont(QFontPrivate *);
303
304 void detach();
305
306
307 friend class QFontPrivate;
308 friend class QFontDialogPrivate;
309 friend class QFontMetrics;
310 friend class QFontMetricsF;
311 friend class QFontInfo;
312 friend class QPainter;
313 friend class QPainterPrivate;
314 friend class QApplication;
315 friend class QWidget;
316 friend class QWidgetPrivate;
317 friend class QTextLayout;
318 friend class QTextEngine;
319 friend class QStackTextEngine;
320 friend class QTextLine;
321 friend struct QScriptLine;
322 friend class QOpenGLContext;
323 friend class QWin32PaintEngine;
324 friend class QAlphaPaintEngine;
325 friend class QPainterPath;
326 friend class QTextItemInt;
327 friend class QPicturePaintEngine;
328 friend class QPainterReplayer;
329 friend class QPaintBufferEngine;
330 friend class QCommandLinkButtonPrivate;
331 friend class QFontEngine;
332
333#ifndef QT_NO_DATASTREAM
334 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
335 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
336#endif
337
338#ifndef QT_NO_DEBUG_STREAM
339 friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
340#endif
341
342 QExplicitlySharedDataPointer<QFontPrivate> d;
343 uint resolve_mask;
344};
345
346Q_DECLARE_SHARED(QFont)
347
348Q_GUI_EXPORT uint qHash(const QFont &font, uint seed = 0) noexcept;
349
350inline bool QFont::bold() const
351{ return weight() > Medium; }
352
353
354inline void QFont::setBold(bool enable)
355{ setWeight(enable ? Bold : Normal); }
356
357inline bool QFont::italic() const
358{
359 return (style() != StyleNormal);
360}
361
362inline void QFont::setItalic(bool b) {
363 setStyle(b ? StyleItalic : StyleNormal);
364}
365
366
367/*****************************************************************************
368 QFont stream functions
369 *****************************************************************************/
370
371#ifndef QT_NO_DATASTREAM
372Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
373Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
374#endif
375
376#ifndef QT_NO_DEBUG_STREAM
377Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
378#endif
379
380QT_END_NAMESPACE
381
382#endif // QFONT_H
383