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 
49 QT_BEGIN_NAMESPACE
50 
51 
52 class QFontPrivate;                                     /* don't touch */
53 class QStringList;
54 class QVariant;
55 
56 class Q_GUI_EXPORT QFont
57 {
58     Q_GADGET
59 public:
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 #if QT_DEPRECATED_SINCE(5, 15)
84         OpenGLCompatible Q_DECL_ENUMERATOR_DEPRECATED = 0x0200,
85         ForceIntegerMetrics Q_DECL_ENUMERATOR_DEPRECATED = 0x0400,
86 #endif
87         NoSubpixelAntialias = 0x0800,
88         PreferNoShaping     = 0x1000,
89         NoFontMerging       = 0x8000
90     };
91     Q_ENUM(StyleStrategy)
92 
93     enum HintingPreference {
94         PreferDefaultHinting        = 0,
95         PreferNoHinting             = 1,
96         PreferVerticalHinting       = 2,
97         PreferFullHinting           = 3
98     };
99     Q_ENUM(HintingPreference)
100 
101     // Mapping OpenType weight value.
102     enum Weight {
103         Thin     = 0,    // 100
104         ExtraLight = 12, // 200
105         Light    = 25,   // 300
106         Normal   = 50,   // 400
107         Medium   = 57,   // 500
108         DemiBold = 63,   // 600
109         Bold     = 75,   // 700
110         ExtraBold = 81,  // 800
111         Black    = 87    // 900
112     };
113     Q_ENUM(Weight)
114 
115     enum Style {
116         StyleNormal,
117         StyleItalic,
118         StyleOblique
119     };
120     Q_ENUM(Style)
121 
122     enum Stretch {
123         AnyStretch     =   0,
124         UltraCondensed =  50,
125         ExtraCondensed =  62,
126         Condensed      =  75,
127         SemiCondensed  =  87,
128         Unstretched    = 100,
129         SemiExpanded   = 112,
130         Expanded       = 125,
131         ExtraExpanded  = 150,
132         UltraExpanded  = 200
133     };
134     Q_ENUM(Stretch)
135 
136     enum Capitalization {
137         MixedCase,
138         AllUppercase,
139         AllLowercase,
140         SmallCaps,
141         Capitalize
142     };
143     Q_ENUM(Capitalization)
144 
145     enum SpacingType {
146         PercentageSpacing,
147         AbsoluteSpacing
148     };
149     Q_ENUM(SpacingType)
150 
151     enum ResolveProperties {
152         NoPropertiesResolved        = 0x0000,
153         FamilyResolved              = 0x0001,
154         SizeResolved                = 0x0002,
155         StyleHintResolved           = 0x0004,
156         StyleStrategyResolved       = 0x0008,
157         WeightResolved              = 0x0010,
158         StyleResolved               = 0x0020,
159         UnderlineResolved           = 0x0040,
160         OverlineResolved            = 0x0080,
161         StrikeOutResolved           = 0x0100,
162         FixedPitchResolved          = 0x0200,
163         StretchResolved             = 0x0400,
164         KerningResolved             = 0x0800,
165         CapitalizationResolved      = 0x1000,
166         LetterSpacingResolved       = 0x2000,
167         WordSpacingResolved         = 0x4000,
168         HintingPreferenceResolved   = 0x8000,
169         StyleNameResolved           = 0x10000,
170         FamiliesResolved            = 0x20000,
171         AllPropertiesResolved       = 0x3ffff
172     };
173     Q_ENUM(ResolveProperties)
174 
175     QFont();
176     QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
177 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
178     QFont(const QFont &font, QPaintDevice *pd);
179 #endif
180     QFont(const QFont &font, const QPaintDevice *pd);
181     QFont(const QFont &font);
182     ~QFont();
183 
swap(QFont & other)184     void swap(QFont &other)
185     { qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask); }
186 
187     QString family() const;
188     void setFamily(const QString &);
189 
190     QStringList families() const;
191     void setFamilies(const QStringList &);
192 
193     QString styleName() const;
194     void setStyleName(const QString &);
195 
196     int pointSize() const;
197     void setPointSize(int);
198     qreal pointSizeF() const;
199     void setPointSizeF(qreal);
200 
201     int pixelSize() const;
202     void setPixelSize(int);
203 
204     int weight() const;
205     void setWeight(int);
206 
207     inline bool bold() const;
208     inline void setBold(bool);
209 
210     void setStyle(Style style);
211     Style style() const;
212 
213     inline bool italic() const;
214     inline void setItalic(bool b);
215 
216     bool underline() const;
217     void setUnderline(bool);
218 
219     bool overline() const;
220     void setOverline(bool);
221 
222     bool strikeOut() const;
223     void setStrikeOut(bool);
224 
225     bool fixedPitch() const;
226     void setFixedPitch(bool);
227 
228     bool kerning() const;
229     void setKerning(bool);
230 
231     StyleHint styleHint() const;
232     StyleStrategy styleStrategy() const;
233     void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
234     void setStyleStrategy(StyleStrategy s);
235 
236     int stretch() const;
237     void setStretch(int);
238 
239     qreal letterSpacing() const;
240     SpacingType letterSpacingType() const;
241     void setLetterSpacing(SpacingType type, qreal spacing);
242 
243     qreal wordSpacing() const;
244     void setWordSpacing(qreal spacing);
245 
246     void setCapitalization(Capitalization);
247     Capitalization capitalization() const;
248 
249     void setHintingPreference(HintingPreference hintingPreference);
250     HintingPreference hintingPreference() const;
251 
252 #if QT_DEPRECATED_SINCE(5, 5)
253     bool rawMode() const;
254     void setRawMode(bool);
255 #endif
256 
257     // dupicated from QFontInfo
258     bool exactMatch() const;
259 
260     QFont &operator=(const QFont &);
261     bool operator==(const QFont &) const;
262     bool operator!=(const QFont &) const;
263     bool operator<(const QFont &) const;
264     operator QVariant() const;
265     bool isCopyOf(const QFont &) const;
266     inline QFont &operator=(QFont &&other) noexcept
267     { qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask);  return *this; }
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)
removeSubstitution(const QString & family)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;
resolve()300     inline uint resolve() const { return resolve_mask; }
resolve(uint mask)301     inline void resolve(uint mask) { resolve_mask = mask; }
302 
303 private:
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 
348 Q_DECLARE_SHARED(QFont)
349 
350 Q_GUI_EXPORT uint qHash(const QFont &font, uint seed = 0) noexcept;
351 
bold()352 inline bool QFont::bold() const
353 { return weight() > Medium; }
354 
355 
setBold(bool enable)356 inline void QFont::setBold(bool enable)
357 { setWeight(enable ? Bold : Normal); }
358 
italic()359 inline bool QFont::italic() const
360 {
361     return (style() != StyleNormal);
362 }
363 
setItalic(bool b)364 inline 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
374 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
375 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
376 #endif
377 
378 #ifndef QT_NO_DEBUG_STREAM
379 Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
380 #endif
381 
382 QT_END_NAMESPACE
383 
384 #endif // QFONT_H
385