Qt 4.8
qfont.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QFONT_H
43 #define QFONT_H
44 
45 #include <QtGui/qwindowdefs.h>
46 #include <QtCore/qstring.h>
47 #include <QtCore/qsharedpointer.h>
48 
49 #if defined(Q_WS_X11) || defined(Q_WS_QWS)
50 typedef struct FT_FaceRec_* FT_Face;
51 #endif
52 
54 
56 
57 QT_MODULE(Gui)
58 
59 class QFontPrivate; /* don't touch */
60 class QStringList;
61 class QVariant;
62 class Q3TextFormatCollection;
63 
65 {
66  Q_GADGET
68 public:
69  enum StyleHint {
70  Helvetica, SansSerif = Helvetica,
71  Times, Serif = Times,
72  Courier, TypeWriter = Courier,
73  OldEnglish, Decorative = OldEnglish,
78  Fantasy
79  };
80 
82  PreferDefault = 0x0001,
83  PreferBitmap = 0x0002,
84  PreferDevice = 0x0004,
85  PreferOutline = 0x0008,
86  ForceOutline = 0x0010,
87  PreferMatch = 0x0020,
88  PreferQuality = 0x0040,
89  PreferAntialias = 0x0080,
90  NoAntialias = 0x0100,
91  OpenGLCompatible = 0x0200,
92  ForceIntegerMetrics = 0x0400,
93  NoFontMerging = 0x8000
94  };
95 
97  PreferDefaultHinting = 0,
98  PreferNoHinting = 1,
99  PreferVerticalHinting = 2,
100  PreferFullHinting = 3
101  };
102 
103  enum Weight {
104  Light = 25,
105  Normal = 50,
106  DemiBold = 63,
107  Bold = 75,
108  Black = 87
109  };
110 
111  enum Style {
114  StyleOblique
115  };
116 
117  enum Stretch {
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 
134  Capitalize
135  };
136 
137  enum SpacingType {
139  AbsoluteSpacing
140  };
141 
143  FamilyResolved = 0x0001,
144  SizeResolved = 0x0002,
145  StyleHintResolved = 0x0004,
146  StyleStrategyResolved = 0x0008,
147  WeightResolved = 0x0010,
148  StyleResolved = 0x0020,
149  UnderlineResolved = 0x0040,
150  OverlineResolved = 0x0080,
151  StrikeOutResolved = 0x0100,
152  FixedPitchResolved = 0x0200,
153  StretchResolved = 0x0400,
154  KerningResolved = 0x0800,
155  CapitalizationResolved = 0x1000,
156  LetterSpacingResolved = 0x2000,
157  WordSpacingResolved = 0x4000,
158  HintingPreferenceResolved = 0x8000,
159  StyleNameResolved = 0x10000,
160  AllPropertiesResolved = 0x1ffff
161  };
162 
163  QFont();
164  QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
165  QFont(const QFont &, QPaintDevice *pd);
166  QFont(const QFont &);
167  ~QFont();
168 
169  QString family() const;
170  void setFamily(const QString &);
171 
172  QString styleName() const;
173  void setStyleName(const QString &);
174 
175  int pointSize() const;
176  void setPointSize(int);
177  qreal pointSizeF() const;
178  void setPointSizeF(qreal);
179 
180  int pixelSize() const;
181  void setPixelSize(int);
182 
183  int weight() const;
184  void setWeight(int);
185 
186  inline bool bold() const;
187  inline void setBold(bool);
188 
189  void setStyle(Style style);
190  Style style() const;
191 
192  inline bool italic() const;
193  inline void setItalic(bool b);
194 
195  bool underline() const;
196  void setUnderline(bool);
197 
198  bool overline() const;
199  void setOverline(bool);
200 
201  bool strikeOut() const;
202  void setStrikeOut(bool);
203 
204  bool fixedPitch() const;
205  void setFixedPitch(bool);
206 
207  bool kerning() const;
208  void setKerning(bool);
209 
210  StyleHint styleHint() const;
211  StyleStrategy styleStrategy() const;
212  void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
213  void setStyleStrategy(StyleStrategy s);
214 
215  int stretch() const;
216  void setStretch(int);
217 
218  qreal letterSpacing() const;
219  SpacingType letterSpacingType() const;
220  void setLetterSpacing(SpacingType type, qreal spacing);
221 
222  qreal wordSpacing() const;
223  void setWordSpacing(qreal spacing);
224 
225  void setCapitalization(Capitalization);
226  Capitalization capitalization() const;
227 
228  void setHintingPreference(HintingPreference hintingPreference);
229  HintingPreference hintingPreference() const;
230 
231  // is raw mode still needed?
232  bool rawMode() const;
233  void setRawMode(bool);
234 
235  // dupicated from QFontInfo
236  bool exactMatch() const;
237 
238  QFont &operator=(const QFont &);
239  bool operator==(const QFont &) const;
240  bool operator!=(const QFont &) const;
241  bool operator<(const QFont &) const;
242  operator QVariant() const;
243  bool isCopyOf(const QFont &) const;
244 #ifdef Q_COMPILER_RVALUE_REFS
245  inline QFont &operator=(QFont &&other)
246  { qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask); return *this; }
247 #endif
248 
249 #ifdef Q_WS_WIN
250  HFONT handle() const;
251 #else // !Q_WS_WIN
252  Qt::HANDLE handle() const;
253 #endif // Q_WS_WIN
254 #ifdef Q_WS_MAC
255  quint32 macFontID() const;
256 #endif
257 #if defined(Q_WS_X11) || defined(Q_WS_QWS)
258  FT_Face freetypeFace() const;
259 #endif
260 
261  // needed for X11
262  void setRawName(const QString &);
263  QString rawName() const;
264 
265  QString key() const;
266 
267  QString toString() const;
268  bool fromString(const QString &);
269 
270  static QString substitute(const QString &);
271  static QStringList substitutes(const QString &);
272  static QStringList substitutions();
273  static void insertSubstitution(const QString&, const QString &);
274  static void insertSubstitutions(const QString&, const QStringList &);
275  static void removeSubstitution(const QString &);
276  static void initialize();
277  static void cleanup();
278 #ifndef Q_WS_QWS
279  static void cacheStatistics();
280 #endif
281 
282  QString defaultFamily() const;
283  QString lastResortFamily() const;
284  QString lastResortFont() const;
285 
286  QFont resolve(const QFont &) const;
287  inline uint resolve() const { return resolve_mask; }
288  inline void resolve(uint mask) { resolve_mask = mask; }
289 
290 #ifdef QT3_SUPPORT
291  static QT3_SUPPORT QFont defaultFont();
292  static QT3_SUPPORT void setDefaultFont(const QFont &);
293  QT3_SUPPORT void setPixelSizeFloat(qreal);
294  QT3_SUPPORT qreal pointSizeFloat() const { return pointSizeF(); }
295  QT3_SUPPORT void setPointSizeFloat(qreal size) { setPointSizeF(size); }
296 #endif
297 
298 private:
299  QFont(QFontPrivate *);
300 
301  void detach();
302 
303 #if defined(Q_WS_MAC)
304  void macSetFont(QPaintDevice *);
305 #elif defined(Q_WS_X11)
306  void x11SetScreen(int screen = -1);
307  int x11Screen() const;
308 #endif
309 
310  friend class QFontPrivate;
311  friend class QFontDialogPrivate;
312  friend class QFontMetrics;
313  friend class QFontMetricsF;
314  friend class QFontInfo;
315  friend class QPainter;
316  friend class QPainterPrivate;
317  friend class QPSPrintEngineFont;
318  friend class QApplication;
319  friend class QWidget;
320  friend class QWidgetPrivate;
321  friend class Q3TextFormatCollection;
322  friend class QTextLayout;
323  friend class QTextEngine;
324  friend class QStackTextEngine;
325  friend class QTextLine;
326  friend struct QScriptLine;
327  friend class QGLContext;
328  friend class QWin32PaintEngine;
329  friend class QAlphaPaintEngine;
330  friend class QPainterPath;
331  friend class QTextItemInt;
332  friend class QPicturePaintEngine;
333  friend class QPainterReplayer;
334  friend class QPaintBufferEngine;
336  friend class QFontEngine;
337 
338 #ifndef QT_NO_DATASTREAM
341 #endif
342 
345 };
346 
347 
348 inline bool QFont::bold() const
349 { return weight() > Normal; }
350 
351 
352 inline void QFont::setBold(bool enable)
353 { setWeight(enable ? Bold : Normal); }
354 
355 inline bool QFont::italic() const
356 {
357  return (style() != StyleNormal);
358 }
359 
360 inline void QFont::setItalic(bool b) {
361  setStyle(b ? StyleItalic : StyleNormal);
362 }
363 
364 
365 /*****************************************************************************
366  QFont stream functions
367  *****************************************************************************/
368 
369 #ifndef QT_NO_DATASTREAM
372 #endif
373 
374 #ifndef QT_NO_DEBUG_STREAM
376 #endif
377 
379 
381 
382 #endif // QFONT_H
uint resolve() const
Definition: qfont.h:287
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
double d
Definition: qnumeric_p.h:62
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
HintingPreference
This enum describes the different levels of hinting that can be applied to glyphs to improve legibili...
Definition: qfont.h:96
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
Weight
Qt uses a weighting scale from 0 to 99 similar to, but not the same as, the scales used in Windows or...
Definition: qfont.h:103
bool operator!=(QBool b1, bool b2)
Definition: qglobal.h:2026
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setItalic(bool b)
Sets the style() of the font to QFont::StyleItalic if enable is true; otherwise the style is set to Q...
Definition: qfont.h:360
Stretch
Predefined stretch values that follow the CSS naming convention.
Definition: qfont.h:117
Capitalization
Rendering option for text this font applies to.
Definition: qfont.h:129
bool operator<(int priority, const QPair< QRunnable *, int > &p)
Definition: qthreadpool.cpp:50
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
static QString toString(Register *reg, int type, bool *ok=0)
void resolve(uint mask)
Definition: qfont.h:288
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setBold(bool)
If enable is true sets the font&#39;s weight to QFont::Bold ; otherwise sets the weight to QFont::Normal...
Definition: qfont.h:352
struct FT_FaceRec_ * FT_Face
Definition: qfont.h:50
static float pixelSize(const QFontDef &request, int dpi)
Definition: qfont_win.cpp:80
uint resolve_mask
Definition: qfont.h:344
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
ResolveProperties
This enum describes the properties of a QFont that can be set on a font individually and then conside...
Definition: qfont.h:142
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
const char * styleHint(const QFontDef &request)
Internal QTextItem.
unsigned int uint
Definition: qglobal.h:996
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QFont &)
SpacingType
Definition: qfont.h:137
void * HANDLE
Definition: qnamespace.h:1671
The QFontInfo class provides general information about fonts.
Definition: qfontinfo.h:54
Style
This enum describes the different styles of glyphs that are used to display text. ...
Definition: qfont.h:111
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
#define Q_GADGET
Definition: qobjectdefs.h:173
bool bold() const
Returns true if weight() is a value greater than QFont::Normal ; otherwise returns false...
Definition: qfont.h:348
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
StyleHint
Style hints are used by the font matching algorithm to find an appropriate default family if a select...
Definition: qfont.h:69
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
int key
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfont.h:343
unsigned int quint32
Definition: qglobal.h:938
static void cleanup()
Definition: qpicture.cpp:1508
StyleStrategy
The style strategy tells the font matching algorithm what type of fonts should be used to find an app...
Definition: qfont.h:81
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QFont &)
bool italic() const
Returns true if the style() of the font is not QFont::StyleNormal.
Definition: qfont.h:355
The QFontMetricsF class provides font metrics information.
Definition: qfontmetrics.h:145
static QFixed kerning(int left, int right, const QFontEngine::KernPair *pairs, int numPairs)
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
#define QT_END_HEADER
Definition: qglobal.h:137
bool operator==(QBool b1, bool b2)
Definition: qglobal.h:2023
static float pointSize(const QFontDef &fd, int dpi)
Definition: qfont_win.cpp:90