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#ifdef Q_COMPILER_RVALUE_REFS
265 inline QFont &operator=(QFont &&other) Q_DECL_NOEXCEPT
266 { qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask); return *this; }
267#endif
268
269#if QT_DEPRECATED_SINCE(5, 3)
270 // needed for X11
271 QT_DEPRECATED void setRawName(const QString &);
272 QT_DEPRECATED QString rawName() const;
273#endif
274
275 QString key() const;
276
277 QString toString() const;
278 bool fromString(const QString &);
279
280 static QString substitute(const QString &);
281 static QStringList substitutes(const QString &);
282 static QStringList substitutions();
283 static void insertSubstitution(const QString&, const QString &);
284 static void insertSubstitutions(const QString&, const QStringList &);
285 static void removeSubstitutions(const QString &);
286#if QT_DEPRECATED_SINCE(5, 0)
287 static QT_DEPRECATED void removeSubstitution(const QString &family) { removeSubstitutions(family); }
288#endif
289 static void initialize();
290 static void cleanup();
291 static void cacheStatistics();
292
293 QString defaultFamily() const;
294#if QT_DEPRECATED_SINCE(5, 13)
295 QT_DEPRECATED QString lastResortFamily() const;
296 QT_DEPRECATED QString lastResortFont() const;
297#endif
298
299 QFont resolve(const QFont &) const;
300 inline uint resolve() const { return resolve_mask; }
301 inline void resolve(uint mask) { resolve_mask = mask; }
302
303private:
304 explicit QFont(QFontPrivate *);
305
306 void detach();
307
308
309 friend class QFontPrivate;
310 friend class QFontDialogPrivate;
311 friend class QFontMetrics;
312 friend class QFontMetricsF;
313 friend class QFontInfo;
314 friend class QPainter;
315 friend class QPainterPrivate;
316 friend class QApplication;
317 friend class QWidget;
318 friend class QWidgetPrivate;
319 friend class QTextLayout;
320 friend class QTextEngine;
321 friend class QStackTextEngine;
322 friend class QTextLine;
323 friend struct QScriptLine;
324 friend class QOpenGLContext;
325 friend class QWin32PaintEngine;
326 friend class QAlphaPaintEngine;
327 friend class QPainterPath;
328 friend class QTextItemInt;
329 friend class QPicturePaintEngine;
330 friend class QPainterReplayer;
331 friend class QPaintBufferEngine;
332 friend class QCommandLinkButtonPrivate;
333 friend class QFontEngine;
334
335#ifndef QT_NO_DATASTREAM
336 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
337 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
338#endif
339
340#ifndef QT_NO_DEBUG_STREAM
341 friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
342#endif
343
344 QExplicitlySharedDataPointer<QFontPrivate> d;
345 uint resolve_mask;
346};
347
348Q_DECLARE_SHARED(QFont)
349
350Q_GUI_EXPORT uint qHash(const QFont &font, uint seed = 0) Q_DECL_NOTHROW;
351
352inline bool QFont::bold() const
353{ return weight() > Medium; }
354
355
356inline void QFont::setBold(bool enable)
357{ setWeight(enable ? Bold : Normal); }
358
359inline bool QFont::italic() const
360{
361 return (style() != StyleNormal);
362}
363
364inline void QFont::setItalic(bool b) {
365 setStyle(b ? StyleItalic : StyleNormal);
366}
367
368
369/*****************************************************************************
370 QFont stream functions
371 *****************************************************************************/
372
373#ifndef QT_NO_DATASTREAM
374Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
375Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
376#endif
377
378#ifndef QT_NO_DEBUG_STREAM
379Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
380#endif
381
382QT_END_NAMESPACE
383
384#endif // QFONT_H
385