QtBase  v6.3.1
qfont.h
Go to the documentation of this file.
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 
50 
51 
52 class QFontPrivate; /* don't touch */
53 class QVariant;
54 
55 class Q_GUI_EXPORT QFont
56 {
57  Q_GADGET
58 public:
59  enum StyleHint {
60  Helvetica, SansSerif = Helvetica,
61  Times, Serif = Times,
62  Courier, TypeWriter = Courier,
63  OldEnglish, Decorative = OldEnglish,
68  Fantasy
69  };
70  Q_ENUM(StyleHint)
71 
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 
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 {
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 
135  Capitalize
136  };
137  Q_ENUM(Capitalization)
138 
139  enum SpacingType {
141  AbsoluteSpacing
142  };
143  Q_ENUM(SpacingType)
144 
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 
171  QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
172  explicit QFont(const QStringList &families, int pointSize = -1, int weight = -1, bool italic = false);
173  QFont(const QFont &font, const QPaintDevice *pd);
174  QFont(const QFont &font);
175  ~QFont();
176 
177  void swap(QFont &other) noexcept
178  { d.swap(other.d); std::swap(resolve_mask, other.resolve_mask); }
179 
180  QString family() const;
181  void setFamily(const QString &);
182 
183  QStringList families() const;
184  void setFamilies(const QStringList &);
185 
186  QString styleName() const;
187  void setStyleName(const QString &);
188 
189  int pointSize() const;
190  void setPointSize(int);
191  qreal pointSizeF() const;
192  void setPointSizeF(qreal);
193 
194  int pixelSize() const;
195  void setPixelSize(int);
196 
197  Weight weight() const;
198  void setWeight(Weight weight);
199 
200  inline bool bold() const;
201  inline void setBold(bool);
202 
203  void setStyle(Style style);
204  Style style() const;
205 
206  inline bool italic() const;
207  inline void setItalic(bool b);
208 
209  bool underline() const;
210  void setUnderline(bool);
211 
212  bool overline() const;
213  void setOverline(bool);
214 
215  bool strikeOut() const;
216  void setStrikeOut(bool);
217 
218  bool fixedPitch() const;
219  void setFixedPitch(bool);
220 
221  bool kerning() const;
222  void setKerning(bool);
223 
224  StyleHint styleHint() const;
225  StyleStrategy styleStrategy() const;
226  void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
227  void setStyleStrategy(StyleStrategy s);
228 
229  int stretch() const;
230  void setStretch(int);
231 
232  qreal letterSpacing() const;
233  SpacingType letterSpacingType() const;
234  void setLetterSpacing(SpacingType type, qreal spacing);
235 
236  qreal wordSpacing() const;
237  void setWordSpacing(qreal spacing);
238 
239  void setCapitalization(Capitalization);
240  Capitalization capitalization() const;
241 
242  void setHintingPreference(HintingPreference hintingPreference);
243  HintingPreference hintingPreference() const;
244 
245  // dupicated from QFontInfo
246  bool exactMatch() const;
247 
248  QFont &operator=(const QFont &);
249  bool operator==(const QFont &) const;
250  bool operator!=(const QFont &) const;
251  bool operator<(const QFont &) const;
252  operator QVariant() const;
253  bool isCopyOf(const QFont &) const;
255 
256  QString key() const;
257 
258  QString toString() const;
259  bool fromString(const QString &);
260 
261  static QString substitute(const QString &);
262  static QStringList substitutes(const QString &);
263  static QStringList substitutions();
264  static void insertSubstitution(const QString&, const QString &);
265  static void insertSubstitutions(const QString&, const QStringList &);
266  static void removeSubstitutions(const QString &);
267  static void initialize();
268  static void cleanup();
269  static void cacheStatistics();
270 
271  QString defaultFamily() const;
272 
273  QFont resolve(const QFont &) const;
274  inline uint resolveMask() const { return resolve_mask; }
275  inline void setResolveMask(uint mask) { resolve_mask = mask; }
276 
277 #if QT_DEPRECATED_SINCE(6, 0)
278  QT_DEPRECATED_VERSION_X_6_0("Use setWeight() instead") void setLegacyWeight(int legacyWeight);
279  QT_DEPRECATED_VERSION_X_6_0("Use weight() instead") int legacyWeight() const;
280 #endif
281 
282 private:
283  explicit QFont(QFontPrivate *);
284 
285  void detach();
286 
287 
288  friend class QFontPrivate;
289  friend class QFontDialogPrivate;
290  friend class QFontMetrics;
291  friend class QFontMetricsF;
292  friend class QFontInfo;
293  friend class QPainter;
294  friend class QPainterPrivate;
295  friend class QApplication;
296  friend class QWidget;
297  friend class QWidgetPrivate;
298  friend class QTextLayout;
299  friend class QTextEngine;
300  friend class QStackTextEngine;
301  friend class QTextLine;
302  friend struct QScriptLine;
303  friend class QOpenGLContext;
304  friend class QWin32PaintEngine;
305  friend class QAlphaPaintEngine;
306  friend class QPainterPath;
307  friend class QTextItemInt;
308  friend class QPicturePaintEngine;
309  friend class QPainterReplayer;
310  friend class QPaintBufferEngine;
312  friend class QFontEngine;
313 
314 #ifndef QT_NO_DATASTREAM
315  friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
316  friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
317 #endif
318 
319 #ifndef QT_NO_DEBUG_STREAM
320  friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
321 #endif
322 
324  uint resolve_mask;
325 };
326 
328 
329 Q_GUI_EXPORT size_t qHash(const QFont &font, size_t seed = 0) noexcept;
330 
331 inline bool QFont::bold() const
332 { return weight() > Medium; }
333 
334 
335 inline void QFont::setBold(bool enable)
336 { setWeight(enable ? Bold : Normal); }
337 
338 inline bool QFont::italic() const
339 {
340  return (style() != StyleNormal);
341 }
342 
343 inline void QFont::setItalic(bool b) {
345 }
346 
347 
348 /*****************************************************************************
349  QFont stream functions
350  *****************************************************************************/
351 
352 #ifndef QT_NO_DATASTREAM
353 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
355 #endif
356 
357 #ifndef QT_NO_DEBUG_STREAM
358 Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
359 #endif
360 
362 
363 #endif // QFONT_H
Arabic default style
Definition: afstyles.h:94
The QApplication class manages the GUI application's control flow and main settings.
Definition: qapplication.h:68
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:66
operator>>(QDataStream &ds, qfloat16 &f)
Definition: qfloat16.cpp:344
operator<<(QDataStream &ds, qfloat16 f)
Definition: qfloat16.cpp:327
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
template< typename Enum > size_t qHash(QFlags< Enum > flags, size_t seed=0) noexcept
The QFont class specifies a query for a font used for drawing text.
Definition: qfont.h:56
StyleHint
Definition: qfont.h:59
@ Helvetica
Definition: qfont.h:60
@ AnyStyle
Definition: qfont.h:65
@ Monospace
Definition: qfont.h:67
@ System
Definition: qfont.h:64
@ Courier
Definition: qfont.h:62
@ Cursive
Definition: qfont.h:66
void setStyle(Style style)
Definition: qfont.cpp:1136
bool italic() const
Definition: qfont.h:338
void swap(QFont &other) noexcept
Definition: qfont.h:177
Capitalization
Definition: qfont.h:130
@ AllLowercase
Definition: qfont.h:133
@ AllUppercase
Definition: qfont.h:132
@ MixedCase
Definition: qfont.h:131
@ SmallCaps
Definition: qfont.h:134
SpacingType
Definition: qfont.h:139
@ PercentageSpacing
Definition: qfont.h:140
ResolveProperties
Definition: qfont.h:145
void setBold(bool)
Definition: qfont.h:335
void setItalic(bool b)
Definition: qfont.h:343
HintingPreference
Definition: qfont.h:88
void setResolveMask(uint mask)
Definition: qfont.h:275
uint resolveMask() const
Definition: qfont.h:274
Stretch
Definition: qfont.h:116
Style style() const
Definition: qfont.cpp:1125
StyleStrategy
Definition: qfont.h:72
Weight
Definition: qfont.h:96
@ Bold
Definition: qfont.h:103
@ Normal
Definition: qfont.h:100
void setWeight(Weight weight)
Definition: qfont.cpp:1225
@ StyleItalic
Definition: qfont.h:111
@ StyleNormal
Definition: qfont.h:110
The QFontInfo class provides general information about fonts. \inmodule QtGui.
Definition: qfontinfo.h:51
The QFontMetricsF class provides font metrics information.
Definition: qfontmetrics.h:127
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:56
The QOpenGLContext class represents a native OpenGL context, enabling OpenGL rendering on a QSurface.
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:82
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:65
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QStringList class provides a list of strings.
Internal QTextItem.
The QTextLayout class is used to lay out and render text. \inmodule QtGui.
Definition: qtextlayout.h:106
The QTextLine class represents a line of text inside a QTextLayout. \inmodule QtGui.
Definition: qtextlayout.h:208
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
Definition: main.cpp:626
qreal spacing
auto it unsigned count const
Definition: hb-iter.hh:848
#define inline
Definition: md4c.c:45
QT_BEGIN_NAMESPACE bool operator<(const QMimeType &t1, const QMimeType &t2)
constexpr QColor Black
Definition: qcolor.h:315
void swap(SimpleVector< T > &v1, SimpleVector< T > &v2)
Definition: simplevector.h:331
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld cleanup[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld SRC pixld MASK if DST_R else pixld DST_R endif if src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head if pixblock_size cache_preload_simple endif process_pixblock_tail pixinterleave dst_w_basereg irp if pixblock_size chunk_size tst beq if DST_W else pixst DST_W else mov ORIG_W endif add lsl if lsl endif if lsl endif lsl endif lsl endif lsl endif subs mov DST_W if regs_shortage str endif bge start_of_loop_label endm macro generate_composite_function
void
Definition: png.h:1080
constexpr bool operator!=(const timespec &t1, const timespec &t2)
Definition: qcore_unix_p.h:124
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QFont &)
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QFont &)
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
unsigned int uint
Definition: qglobal.h:334
#define QT_DEPRECATED_VERSION_X_6_0(text)
Definition: qglobal.h:444
#define QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(Class)
Definition: qglobal.h:563
bool operator==(const QMakeBaseKey &one, const QMakeBaseKey &two)
GLenum type
Definition: qopengl.h:270
GLboolean GLboolean GLboolean b
GLuint64 key
GLuint GLuint GLfloat weight
GLboolean enable
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLdouble s
[6]
Definition: qopenglext.h:235
#define Q_ENUM(x)
Definition: qtmetamacros.h:104
#define Q_GADGET
Definition: qtmetamacros.h:193
#define Q_DECLARE_SHARED(TYPE)
Definition: qtypeinfo.h:197
QSharedPointer< T > other(t)
[5]
font setBold(false)
widget setStyle(proxy)
socketLayer initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv4Protocol)
FT_UInt FT_UInt FT_Vector * kerning
Definition: ttdriver.c:206