source: trunk/src/gui/text/qfont.h@ 858

Last change on this file since 858 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 9.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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)
50typedef struct FT_FaceRec_* FT_Face;
51#endif
52
53QT_BEGIN_HEADER
54
55QT_BEGIN_NAMESPACE
56
57QT_MODULE(Gui)
58
59class QFontPrivate; /* don't touch */
60class QStringList;
61class QVariant;
62class Q3TextFormatCollection;
63
64class Q_GUI_EXPORT QFont
65{
66 Q_GADGET
67 Q_ENUMS(StyleStrategy)
68public:
69 enum StyleHint {
70 Helvetica, SansSerif = Helvetica,
71 Times, Serif = Times,
72 Courier, TypeWriter = Courier,
73 OldEnglish, Decorative = OldEnglish,
74 System,
75 AnyStyle,
76 Cursive,
77 Monospace,
78 Fantasy
79 };
80
81 enum StyleStrategy {
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
96 enum Weight {
97 Light = 25,
98 Normal = 50,
99 DemiBold = 63,
100 Bold = 75,
101 Black = 87
102 };
103
104 enum Style {
105 StyleNormal,
106 StyleItalic,
107 StyleOblique
108 };
109
110 enum Stretch {
111 UltraCondensed = 50,
112 ExtraCondensed = 62,
113 Condensed = 75,
114 SemiCondensed = 87,
115 Unstretched = 100,
116 SemiExpanded = 112,
117 Expanded = 125,
118 ExtraExpanded = 150,
119 UltraExpanded = 200
120 };
121
122 enum Capitalization {
123 MixedCase,
124 AllUppercase,
125 AllLowercase,
126 SmallCaps,
127 Capitalize
128 };
129
130 enum SpacingType {
131 PercentageSpacing,
132 AbsoluteSpacing
133 };
134
135 enum ResolveProperties {
136 FamilyResolved = 0x0001,
137 SizeResolved = 0x0002,
138 StyleHintResolved = 0x0004,
139 StyleStrategyResolved = 0x0008,
140 WeightResolved = 0x0010,
141 StyleResolved = 0x0020,
142 UnderlineResolved = 0x0040,
143 OverlineResolved = 0x0080,
144 StrikeOutResolved = 0x0100,
145 FixedPitchResolved = 0x0200,
146 StretchResolved = 0x0400,
147 KerningResolved = 0x0800,
148 CapitalizationResolved = 0x1000,
149 LetterSpacingResolved = 0x2000,
150 WordSpacingResolved = 0x4000,
151 AllPropertiesResolved = 0x7fff
152 };
153
154 QFont();
155 QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
156 QFont(const QFont &, QPaintDevice *pd);
157 QFont(const QFont &);
158 ~QFont();
159
160 QString family() const;
161 void setFamily(const QString &);
162
163 int pointSize() const;
164 void setPointSize(int);
165 qreal pointSizeF() const;
166 void setPointSizeF(qreal);
167
168 int pixelSize() const;
169 void setPixelSize(int);
170
171 int weight() const;
172 void setWeight(int);
173
174 inline bool bold() const;
175 inline void setBold(bool);
176
177 void setStyle(Style style);
178 Style style() const;
179
180 inline bool italic() const;
181 inline void setItalic(bool b);
182
183 bool underline() const;
184 void setUnderline(bool);
185
186 bool overline() const;
187 void setOverline(bool);
188
189 bool strikeOut() const;
190 void setStrikeOut(bool);
191
192 bool fixedPitch() const;
193 void setFixedPitch(bool);
194
195 bool kerning() const;
196 void setKerning(bool);
197
198 StyleHint styleHint() const;
199 StyleStrategy styleStrategy() const;
200 void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
201 void setStyleStrategy(StyleStrategy s);
202
203 int stretch() const;
204 void setStretch(int);
205
206 qreal letterSpacing() const;
207 SpacingType letterSpacingType() const;
208 void setLetterSpacing(SpacingType type, qreal spacing);
209
210 qreal wordSpacing() const;
211 void setWordSpacing(qreal spacing);
212
213 void setCapitalization(Capitalization);
214 Capitalization capitalization() const;
215
216 // is raw mode still needed?
217 bool rawMode() const;
218 void setRawMode(bool);
219
220 // dupicated from QFontInfo
221 bool exactMatch() const;
222
223 QFont &operator=(const QFont &);
224 bool operator==(const QFont &) const;
225 bool operator!=(const QFont &) const;
226 bool operator<(const QFont &) const;
227 operator QVariant() const;
228 bool isCopyOf(const QFont &) const;
229
230
231#ifdef Q_WS_WIN
232 HFONT handle() const;
233#else // !Q_WS_WIN
234 Qt::HANDLE handle() const;
235#endif // Q_WS_WIN
236#ifdef Q_WS_MAC
237 quint32 macFontID() const;
238#endif
239#if defined(Q_WS_X11) || defined(Q_WS_QWS)
240 FT_Face freetypeFace() const;
241#endif
242
243 // needed for X11
244 void setRawName(const QString &);
245 QString rawName() const;
246
247 QString key() const;
248
249 QString toString() const;
250 bool fromString(const QString &);
251
252 static QString substitute(const QString &);
253 static QStringList substitutes(const QString &);
254 static QStringList substitutions();
255 static void insertSubstitution(const QString&, const QString &);
256 static void insertSubstitutions(const QString&, const QStringList &);
257 static void removeSubstitution(const QString &);
258 static void initialize();
259 static void cleanup();
260#ifndef Q_WS_QWS
261 static void cacheStatistics();
262#endif
263
264 QString defaultFamily() const;
265 QString lastResortFamily() const;
266 QString lastResortFont() const;
267
268 QFont resolve(const QFont &) const;
269 inline uint resolve() const { return resolve_mask; }
270 inline void resolve(uint mask) { resolve_mask = mask; }
271
272#ifdef QT3_SUPPORT
273 static QT3_SUPPORT QFont defaultFont();
274 static QT3_SUPPORT void setDefaultFont(const QFont &);
275 QT3_SUPPORT void setPixelSizeFloat(qreal);
276 QT3_SUPPORT qreal pointSizeFloat() const { return pointSizeF(); }
277 QT3_SUPPORT void setPointSizeFloat(qreal size) { setPointSizeF(size); }
278#endif
279
280private:
281 QFont(QFontPrivate *);
282
283 void detach();
284
285#if defined(Q_WS_MAC)
286 void macSetFont(QPaintDevice *);
287#elif defined(Q_WS_X11)
288 void x11SetScreen(int screen = -1);
289 int x11Screen() const;
290#endif
291
292 friend class QFontPrivate;
293 friend class QFontDialogPrivate;
294 friend class QFontMetrics;
295 friend class QFontMetricsF;
296 friend class QFontInfo;
297 friend class QPainter;
298 friend class QPainterPrivate;
299 friend class QPSPrintEngineFont;
300 friend class QApplication;
301 friend class QWidget;
302 friend class QWidgetPrivate;
303 friend class Q3TextFormatCollection;
304 friend class QTextLayout;
305 friend class QTextEngine;
306 friend class QStackTextEngine;
307 friend class QTextLine;
308 friend struct QScriptLine;
309 friend class QGLContext;
310 friend class QWin32PaintEngine;
311 friend class QAlphaPaintEngine;
312 friend class QPainterPath;
313 friend class QTextItemInt;
314 friend class QPicturePaintEngine;
315 friend class QPainterReplayer;
316 friend class QPaintBufferEngine;
317 friend class QCommandLinkButtonPrivate;
318
319#ifndef QT_NO_DATASTREAM
320 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
321 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
322#endif
323
324 QExplicitlySharedDataPointer<QFontPrivate> d;
325 uint resolve_mask;
326};
327
328
329inline bool QFont::bold() const
330{ return weight() > Normal; }
331
332
333inline void QFont::setBold(bool enable)
334{ setWeight(enable ? Bold : Normal); }
335
336inline bool QFont::italic() const
337{
338 return (style() != StyleNormal);
339}
340
341inline void QFont::setItalic(bool b) {
342 setStyle(b ? StyleItalic : StyleNormal);
343}
344
345
346/*****************************************************************************
347 QFont stream functions
348 *****************************************************************************/
349
350#ifndef QT_NO_DATASTREAM
351Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
352Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
353#endif
354
355#ifndef QT_NO_DEBUG_STREAM
356Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
357#endif
358
359QT_END_NAMESPACE
360
361QT_END_HEADER
362
363#endif // QFONT_H
Note: See TracBrowser for help on using the repository browser.