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

Last change on this file since 318 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 9.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department 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
48#if defined(Q_WS_X11) || defined(Q_WS_QWS)
49typedef struct FT_FaceRec_* FT_Face;
50#endif
51
52QT_BEGIN_HEADER
53
54QT_BEGIN_NAMESPACE
55
56QT_MODULE(Gui)
57
58class QFontPrivate; /* don't touch */
59class QStringList;
60class QVariant;
61class Q3TextFormatCollection;
62
63class Q_GUI_EXPORT QFont
64{
65 Q_GADGET
66 Q_ENUMS(StyleStrategy)
67public:
68 enum StyleHint {
69 Helvetica, SansSerif = Helvetica,
70 Times, Serif = Times,
71 Courier, TypeWriter = Courier,
72 OldEnglish, Decorative = OldEnglish,
73 System,
74 AnyStyle
75 };
76
77 enum StyleStrategy {
78 PreferDefault = 0x0001,
79 PreferBitmap = 0x0002,
80 PreferDevice = 0x0004,
81 PreferOutline = 0x0008,
82 ForceOutline = 0x0010,
83 PreferMatch = 0x0020,
84 PreferQuality = 0x0040,
85 PreferAntialias = 0x0080,
86 NoAntialias = 0x0100,
87 OpenGLCompatible = 0x0200,
88 NoFontMerging = 0x8000
89 };
90
91 enum Weight {
92 Light = 25,
93 Normal = 50,
94 DemiBold = 63,
95 Bold = 75,
96 Black = 87
97 };
98
99 enum Style {
100 StyleNormal,
101 StyleItalic,
102 StyleOblique
103 };
104
105 enum Stretch {
106 UltraCondensed = 50,
107 ExtraCondensed = 62,
108 Condensed = 75,
109 SemiCondensed = 87,
110 Unstretched = 100,
111 SemiExpanded = 112,
112 Expanded = 125,
113 ExtraExpanded = 150,
114 UltraExpanded = 200
115 };
116
117 enum Capitalization {
118 MixedCase,
119 AllUppercase,
120 AllLowercase,
121 SmallCaps,
122 Capitalize
123 };
124
125 enum SpacingType {
126 PercentageSpacing,
127 AbsoluteSpacing
128 };
129
130 enum ResolveProperties {
131 FamilyResolved = 0x0001,
132 SizeResolved = 0x0002,
133 StyleHintResolved = 0x0004,
134 StyleStrategyResolved = 0x0008,
135 WeightResolved = 0x0010,
136 StyleResolved = 0x0020,
137 UnderlineResolved = 0x0040,
138 OverlineResolved = 0x0080,
139 StrikeOutResolved = 0x0100,
140 FixedPitchResolved = 0x0200,
141 StretchResolved = 0x0400,
142 KerningResolved = 0x0800,
143 CapitalizationResolved = 0x1000,
144 LetterSpacingResolved = 0x2000,
145 WordSpacingResolved = 0x4000,
146 AllPropertiesResolved = 0x7fff
147 };
148
149 QFont();
150 QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
151 QFont(const QFont &, QPaintDevice *pd);
152 QFont(const QFont &);
153 ~QFont();
154
155 QString family() const;
156 void setFamily(const QString &);
157
158 int pointSize() const;
159 void setPointSize(int);
160 qreal pointSizeF() const;
161 void setPointSizeF(qreal);
162
163 int pixelSize() const;
164 void setPixelSize(int);
165
166 int weight() const;
167 void setWeight(int);
168
169 inline bool bold() const;
170 inline void setBold(bool);
171
172 void setStyle(Style style);
173 Style style() const;
174
175 inline bool italic() const;
176 inline void setItalic(bool b);
177
178 bool underline() const;
179 void setUnderline(bool);
180
181 bool overline() const;
182 void setOverline(bool);
183
184 bool strikeOut() const;
185 void setStrikeOut(bool);
186
187 bool fixedPitch() const;
188 void setFixedPitch(bool);
189
190 bool kerning() const;
191 void setKerning(bool);
192
193 StyleHint styleHint() const;
194 StyleStrategy styleStrategy() const;
195 void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
196 void setStyleStrategy(StyleStrategy s);
197
198 int stretch() const;
199 void setStretch(int);
200
201 qreal letterSpacing() const;
202 SpacingType letterSpacingType() const;
203 void setLetterSpacing(SpacingType type, qreal spacing);
204
205 qreal wordSpacing() const;
206 void setWordSpacing(qreal spacing);
207
208 void setCapitalization(Capitalization);
209 Capitalization capitalization() const;
210
211 // is raw mode still needed?
212 bool rawMode() const;
213 void setRawMode(bool);
214
215 // dupicated from QFontInfo
216 bool exactMatch() const;
217
218 QFont &operator=(const QFont &);
219 bool operator==(const QFont &) const;
220 bool operator!=(const QFont &) const;
221 bool operator<(const QFont &) const;
222 operator QVariant() const;
223 bool isCopyOf(const QFont &) const;
224
225
226#ifdef Q_WS_WIN
227 HFONT handle() const;
228#else // !Q_WS_WIN
229 Qt::HANDLE handle() const;
230#endif // Q_WS_WIN
231#ifdef Q_WS_MAC
232 quint32 macFontID() const;
233#endif
234#if defined(Q_WS_X11) || defined(Q_WS_QWS)
235 FT_Face freetypeFace() const;
236#endif
237
238 // needed for X11
239 void setRawName(const QString &);
240 QString rawName() const;
241
242 QString key() const;
243
244 QString toString() const;
245 bool fromString(const QString &);
246
247 static QString substitute(const QString &);
248 static QStringList substitutes(const QString &);
249 static QStringList substitutions();
250 static void insertSubstitution(const QString&, const QString &);
251 static void insertSubstitutions(const QString&, const QStringList &);
252 static void removeSubstitution(const QString &);
253 static void initialize();
254 static void cleanup();
255#ifndef Q_WS_QWS
256 static void cacheStatistics();
257#endif
258
259 QString defaultFamily() const;
260 QString lastResortFamily() const;
261 QString lastResortFont() const;
262
263 QFont resolve(const QFont &) const;
264 inline uint resolve() const { return resolve_mask; }
265 inline void resolve(uint mask) { resolve_mask = mask; }
266
267#ifdef QT3_SUPPORT
268 static QT3_SUPPORT QFont defaultFont();
269 static QT3_SUPPORT void setDefaultFont(const QFont &);
270 QT3_SUPPORT void setPixelSizeFloat(qreal);
271 QT3_SUPPORT qreal pointSizeFloat() const { return pointSizeF(); }
272 QT3_SUPPORT void setPointSizeFloat(qreal size) { setPointSizeF(size); }
273#endif
274
275private:
276 QFont(QFontPrivate *);
277
278 void detach();
279
280#if defined(Q_WS_MAC)
281 void macSetFont(QPaintDevice *);
282#elif defined(Q_WS_X11)
283 void x11SetScreen(int screen = -1);
284 int x11Screen() const;
285#endif
286
287 friend class QFontPrivate;
288 friend class QFontDialogPrivate;
289 friend class QFontMetrics;
290 friend class QFontMetricsF;
291 friend class QFontInfo;
292 friend class QPainter;
293 friend class QPSPrintEngineFont;
294 friend class QApplication;
295 friend class QWidget;
296 friend class QWidgetPrivate;
297 friend class Q3TextFormatCollection;
298 friend class QTextLayout;