1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QFONT_H
5#define QFONT_H
6
7#include <QtCore/qshareddata.h>
8#include <QtGui/qtguiglobal.h>
9#include <QtGui/qwindowdefs.h>
10#include <QtCore/qstring.h>
11
12
13QT_BEGIN_NAMESPACE
14
15
16class QFontPrivate; /* don't touch */
17class QVariant;
18
19class Q_GUI_EXPORT QFont
20{
21 Q_GADGET
22public:
23 enum StyleHint {
24 Helvetica, SansSerif = Helvetica,
25 Times, Serif = Times,
26 Courier, TypeWriter = Courier,
27 OldEnglish, Decorative = OldEnglish,
28 System,
29 AnyStyle,
30 Cursive,
31 Monospace,
32 Fantasy
33 };
34 Q_ENUM(StyleHint)
35
36 enum StyleStrategy {
37 PreferDefault = 0x0001,
38 PreferBitmap = 0x0002,
39 PreferDevice = 0x0004,
40 PreferOutline = 0x0008,
41 ForceOutline = 0x0010,
42 PreferMatch = 0x0020,
43 PreferQuality = 0x0040,
44 PreferAntialias = 0x0080,
45 NoAntialias = 0x0100,
46 NoSubpixelAntialias = 0x0800,
47 PreferNoShaping = 0x1000,
48 NoFontMerging = 0x8000
49 };
50 Q_ENUM(StyleStrategy)
51
52 enum HintingPreference {
53 PreferDefaultHinting = 0,
54 PreferNoHinting = 1,
55 PreferVerticalHinting = 2,
56 PreferFullHinting = 3
57 };
58 Q_ENUM(HintingPreference)
59
60 enum Weight {
61 Thin = 100,
62 ExtraLight = 200,
63 Light = 300,
64 Normal = 400,
65 Medium = 500,
66 DemiBold = 600,
67 Bold = 700,
68 ExtraBold = 800,
69 Black = 900
70 };
71 Q_ENUM(Weight)
72
73 enum Style {
74 StyleNormal,
75 StyleItalic,
76 StyleOblique
77 };
78 Q_ENUM(Style)
79
80 enum Stretch {
81 AnyStretch = 0,
82 UltraCondensed = 50,
83 ExtraCondensed = 62,
84 Condensed = 75,
85 SemiCondensed = 87,
86 Unstretched = 100,
87 SemiExpanded = 112,
88 Expanded = 125,
89 ExtraExpanded = 150,
90 UltraExpanded = 200
91 };
92 Q_ENUM(Stretch)
93
94 enum Capitalization {
95 MixedCase,
96 AllUppercase,
97 AllLowercase,
98 SmallCaps,
99 Capitalize
100 };
101 Q_ENUM(Capitalization)
102
103 enum SpacingType {
104 PercentageSpacing,
105 AbsoluteSpacing
106 };
107 Q_ENUM(SpacingType)
108
109 enum ResolveProperties {
110 NoPropertiesResolved = 0x0000,
111 FamilyResolved = 0x0001,
112 SizeResolved = 0x0002,
113 StyleHintResolved = 0x0004,
114 StyleStrategyResolved = 0x0008,
115 WeightResolved = 0x0010,
116 StyleResolved = 0x0020,
117 UnderlineResolved = 0x0040,
118 OverlineResolved = 0x0080,
119 StrikeOutResolved = 0x0100,
120 FixedPitchResolved = 0x0200,
121 StretchResolved = 0x0400,
122 KerningResolved = 0x0800,
123 CapitalizationResolved = 0x1000,
124 LetterSpacingResolved = 0x2000,
125 WordSpacingResolved = 0x4000,
126 HintingPreferenceResolved = 0x8000,
127 StyleNameResolved = 0x10000,
128 FamiliesResolved = 0x20000,
129 FeaturesResolved = 0x40000,
130 AllPropertiesResolved = 0x7ffff
131 };
132 Q_ENUM(ResolveProperties)
133
134 QFont();
135
136 QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
137 explicit QFont(const QStringList &families, int pointSize = -1, int weight = -1, bool italic = false);
138 QFont(const QFont &font, const QPaintDevice *pd);
139 QFont(const QFont &font);
140 ~QFont();
141
142 void swap(QFont &other) noexcept
143 { d.swap(other&: other.d); std::swap(a&: resolve_mask, b&: other.resolve_mask); }
144
145 QString family() const;
146 void setFamily(const QString &);
147
148 QStringList families() const;
149 void setFamilies(const QStringList &);
150
151 QString styleName() const;
152 void setStyleName(const QString &);
153
154 int pointSize() const;
155 void setPointSize(int);
156 qreal pointSizeF() const;
157 void setPointSizeF(qreal);
158
159 int pixelSize() const;
160 void setPixelSize(int);
161
162 Weight weight() const;
163 void setWeight(Weight weight);
164
165 inline bool bold() const;
166 inline void setBold(bool);
167
168 void setStyle(Style style);
169 Style style() const;
170
171 inline bool italic() const;
172 inline void setItalic(bool b);
173
174 bool underline() const;
175 void setUnderline(bool);
176
177 bool overline() const;
178 void setOverline(bool);
179
180 bool strikeOut() const;
181 void setStrikeOut(bool);
182
183 bool fixedPitch() const;
184 void setFixedPitch(bool);
185
186 bool kerning() const;
187 void setKerning(bool);
188
189 StyleHint styleHint() const;
190 StyleStrategy styleStrategy() const;
191 void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
192 void setStyleStrategy(StyleStrategy s);
193
194 int stretch() const;
195 void setStretch(int);
196
197 qreal letterSpacing() const;
198 SpacingType letterSpacingType() const;
199 void setLetterSpacing(SpacingType type, qreal spacing);
200
201 qreal wordSpacing() const;
202 void setWordSpacing(qreal spacing);
203
204 void setCapitalization(Capitalization);
205 Capitalization capitalization() const;
206
207 void setHintingPreference(HintingPreference hintingPreference);
208 HintingPreference hintingPreference() const;
209
210 // Note: The following set of APIs are preliminary and may change in future releases
211 void setFeature(const char *feature, quint32 value);
212 void setFeature(quint32 tag, quint32 value);
213 void unsetFeature(quint32 tag);
214 void unsetFeature(const char *feature);
215 quint32 featureValue(quint32 tag) const;
216 bool isFeatureSet(quint32 tag) const;
217 QList<quint32> featureTags() const;
218 void clearFeatures();
219
220 static QByteArray tagToString(quint32 tag);
221 static quint32 stringToTag(const char *tagString);
222 // --
223
224 // dupicated from QFontInfo
225 bool exactMatch() const;
226
227 QFont &operator=(const QFont &);
228 bool operator==(const QFont &) const;
229 bool operator!=(const QFont &) const;
230 bool operator<(const QFont &) const;
231 operator QVariant() const;
232 bool isCopyOf(const QFont &) const;
233 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFont)
234
235 QString key() const;
236
237 QString toString() const;
238 bool fromString(const QString &);
239
240 static QString substitute(const QString &);
241 static QStringList substitutes(const QString &);
242 static QStringList substitutions();
243 static void insertSubstitution(const QString&, const QString &);
244 static void insertSubstitutions(const QString&, const QStringList &);
245 static void removeSubstitutions(const QString &);
246 static void initialize();
247 static void cleanup();
248 static void cacheStatistics();
249
250 QString defaultFamily() const;
251
252 QFont resolve(const QFont &) const;
253 inline uint resolveMask() const { return resolve_mask; }
254 inline void setResolveMask(uint mask) { resolve_mask = mask; }
255
256#if QT_DEPRECATED_SINCE(6, 0)
257 QT_DEPRECATED_VERSION_X_6_0("Use setWeight() instead") void setLegacyWeight(int legacyWeight);
258 QT_DEPRECATED_VERSION_X_6_0("Use weight() instead") int legacyWeight() const;
259#endif
260
261private:
262 explicit QFont(QFontPrivate *);
263
264 void detach();
265
266
267 friend class QFontPrivate;
268 friend class QFontDialogPrivate;
269 friend class QFontMetrics;
270 friend class QFontMetricsF;
271 friend class QFontInfo;
272 friend class QPainter;
273 friend class QPainterPrivate;
274 friend class QApplication;
275 friend class QWidget;
276 friend class QWidgetPrivate;
277 friend class QTextLayout;
278 friend class QTextEngine;
279 friend class QStackTextEngine;
280 friend class QTextLine;
281 friend struct QScriptLine;
282 friend class QOpenGLContext;
283 friend class QWin32PaintEngine;
284 friend class QAlphaPaintEngine;
285 friend class QPainterPath;
286 friend class QTextItemInt;
287 friend class QPicturePaintEngine;
288 friend class QPainterReplayer;
289 friend class QPaintBufferEngine;
290 friend class QCommandLinkButtonPrivate;
291 friend class QFontEngine;
292
293#ifndef QT_NO_DATASTREAM
294 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
295 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
296#endif
297
298#ifndef QT_NO_DEBUG_STREAM
299 friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
300#endif
301
302 QExplicitlySharedDataPointer<QFontPrivate> d;
303 uint resolve_mask;
304};
305
306Q_DECLARE_SHARED(QFont)
307
308Q_GUI_EXPORT size_t qHash(const QFont &font, size_t seed = 0) noexcept;
309
310inline bool QFont::bold() const
311{ return weight() > Medium; }
312
313
314inline void QFont::setBold(bool enable)
315{ setWeight(enable ? Bold : Normal); }
316
317inline bool QFont::italic() const
318{
319 return (style() != StyleNormal);
320}
321
322inline void QFont::setItalic(bool b) {
323 setStyle(b ? StyleItalic : StyleNormal);
324}
325
326
327/*****************************************************************************
328 QFont stream functions
329 *****************************************************************************/
330
331#ifndef QT_NO_DATASTREAM
332Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
333Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
334#endif
335
336#ifndef QT_NO_DEBUG_STREAM
337Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
338#endif
339
340QT_END_NAMESPACE
341
342#endif // QFONT_H
343

source code of qtbase/src/gui/text/qfont.h