QtGui/qfont.h Source File

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 
64 class Q_GUI_EXPORT QFont
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;
335  friend class QCommandLinkButtonPrivate;
336  friend class QFontEngine;
337 
338 #ifndef QT_NO_DATASTREAM
339  friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
340  friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
341 #endif
342 
344  uint resolve_mask;
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) {
362 }
363 
364 
365 /*****************************************************************************
366  QFont stream functions
367  *****************************************************************************/
368 
369 #ifndef QT_NO_DATASTREAM
370 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
371 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
372 #endif
373 
374 #ifndef QT_NO_DEBUG_STREAM
375 Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
376 #endif
377 
379 
381 
382 #endif // QFONT_H
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
Capitalization
Definition: qfont.h:129
#define QT_END_NAMESPACE
Definition: qglobal.h:128
StyleHint
Definition: qfont.h:69
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
Style
Definition: qfont.h:111
SpacingType
Definition: qfont.h:137
int screen
Definition: GLee.h:10533
void setBold(bool)
Definition: qfont.h:352
bool italic() const
Definition: qfont.h:355
Style style() const
Definition: qdebug.h:62
ResolveProperties
Definition: qfont.h:142
int weight() const
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
bool operator==(const Attribute &cA, const AttributeInstance< type > &cB)
This operator compares the two attributes and NOT their values.
Definition: node.h:577
void setWeight(int)
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
StyleStrategy
Definition: qfont.h:81
struct FT_FaceRec_ * FT_Face
Definition: qfont.h:50
Definition: qfont.h:64
void resolve(uint mask)
Definition: qfont.h:288
Q_INLINE_TEMPLATE void qSwap(QScopedPointer< T, Cleanup > &p1, QScopedPointer< T, Cleanup > &p2)
Weight
Definition: qfont.h:103
void setItalic(bool b)
Definition: qfont.h:360
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QFont &)
void setStyle(Style style)
bool operator!=(const QByteArray &a1, const QByteArray &a2)
Definition: qbytearray.h:533
#define Q_GADGET
Definition: qobjectdefs.h:173
GLubyte GLubyte b
Definition: GLee.h:5404
unsigned long HANDLE
Definition: qnamespace.h:1675
HintingPreference
Definition: qfont.h:96
unsigned int quint32
Definition: qglobal.h:938
bool bold() const
Definition: qfont.h:348
Stretch
Definition: qfont.h:117
bool operator<(const QByteArray &a1, const QByteArray &a2)
Definition: qbytearray.h:539
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QFont &)
uint resolve() const
Definition: qfont.h:287
GLdouble s
Definition: GLee.h:1173
GLenum GLint GLuint mask
Definition: GLee.h:1701
#define QT_END_HEADER
Definition: qglobal.h:142
GLsizeiptr size
Definition: GLee.h:1561