1 /****************************************************************************
2 ** $Id: qt/qfont.h   3.3.8   edited Jan 11 14:38 $
3 **
4 ** Definition of QFont class
5 **
6 ** Created : 940514
7 **
8 ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
9 **
10 ** This file is part of the kernel module of the Qt GUI Toolkit.
11 **
12 ** This file may be distributed under the terms of the Q Public License
13 ** as defined by Trolltech ASA of Norway and appearing in the file
14 ** LICENSE.QPL included in the packaging of this file.
15 **
16 ** This file may be distributed and/or modified under the terms of the
17 ** GNU General Public License version 2 as published by the Free Software
18 ** Foundation and appearing in the file LICENSE.GPL included in the
19 ** packaging of this file.
20 **
21 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22 ** licenses may use this file in accordance with the Qt Commercial License
23 ** Agreement provided with the Software.
24 **
25 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27 **
28 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29 **   information about Qt Commercial License Agreements.
30 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
31 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
32 **
33 ** Contact info@trolltech.com if any conditions of this licensing are
34 ** not clear to you.
35 **
36 **********************************************************************/
37 
38 #ifndef QFONT_H
39 #define QFONT_H
40 
41 #ifndef QT_H
42 #include "qwindowdefs.h"
43 #include "qstring.h"
44 #endif // QT_H
45 
46 
47 class QFontPrivate;                                     /* don't touch */
48 class QStringList;
49 class QTextFormatCollection;
50 
51 class Q_EXPORT QFont
52 {
53 public:
54     enum StyleHint {
55 	Helvetica,  SansSerif = Helvetica,
56 	Times,      Serif = Times,
57 	Courier,    TypeWriter = Courier,
58 	OldEnglish, Decorative = OldEnglish,
59 	System,
60 	AnyStyle
61     };
62 
63     enum StyleStrategy {
64 	PreferDefault    = 0x0001,
65 	PreferBitmap     = 0x0002,
66 	PreferDevice     = 0x0004,
67 	PreferOutline    = 0x0008,
68 	ForceOutline     = 0x0010,
69 	PreferMatch      = 0x0020,
70 	PreferQuality    = 0x0040,
71 	PreferAntialias  = 0x0080,
72 	NoAntialias      = 0x0100,
73 	OpenGLCompatible = 0x0200
74     };
75 
76     enum Weight {
77 	Light    = 25,
78 	Normal   = 50,
79 	DemiBold = 63,
80 	Bold     = 75,
81 	Black	 = 87
82     };
83 
84     enum Stretch {
85 	UltraCondensed =  50,
86 	ExtraCondensed =  62,
87 	Condensed      =  75,
88 	SemiCondensed  =  87,
89 	Unstretched    = 100,
90 	SemiExpanded   = 112,
91 	Expanded       = 125,
92 	ExtraExpanded  = 150,
93 	UltraExpanded  = 200
94     };
95 
96     // default font
97     QFont();
98     // specific font
99 #ifdef Q_QDOC
100     QFont( const QString &family, int pointSize = 12, int weight = Normal,
101 	   bool italic = FALSE );
102 #else
103     QFont( const QString &family, int pointSize = -1, int weight = -1,
104 	   bool italic = FALSE );
105 #endif
106     // copy constructor
107     QFont( const QFont & );
108 
109     ~QFont();
110 
111     QString family() const;
112     void setFamily( const QString &);
113 
114     int pointSize() const;
115     float pointSizeFloat() const;
116     void setPointSize( int );
117     void setPointSizeFloat( float );
118 
119     int pixelSize() const;
120     void setPixelSize( int );
121     void setPixelSizeFloat( float );
122 
123     int weight() const;
124     void setWeight( int );
125 
126     bool bold() const;
127     void setBold( bool );
128 
129     bool italic() const;
130     void setItalic( bool );
131 
132     bool underline() const;
133     void setUnderline( bool );
134 
135     bool overline() const;
136     void setOverline( bool );
137 
138     bool strikeOut() const;
139     void setStrikeOut( bool );
140 
141     bool fixedPitch() const;
142     void setFixedPitch( bool );
143 
144     StyleHint styleHint() const;
145     StyleStrategy styleStrategy() const;
146     void setStyleHint( StyleHint, StyleStrategy = PreferDefault );
147     void setStyleStrategy( StyleStrategy s );
148 
149     int stretch() const;
150     void setStretch( int );
151 
152     // is raw mode still needed?
153     bool rawMode() const;
154     void setRawMode( bool );
155 
156     // dupicated from QFontInfo
157     bool exactMatch() const;
158 
159     QFont &operator=( const QFont & );
160     bool operator==( const QFont & ) const;
161     bool operator!=( const QFont & ) const;
162     bool isCopyOf( const QFont & ) const;
163 
164 
165 #ifdef Q_WS_WIN
166     HFONT handle() const;
167 #else // !Q_WS_WIN
168     Qt::HANDLE handle() const;
169 #endif // Q_WS_WIN
170 
171 
172     // needed for X11
173     void setRawName( const QString & );
174     QString rawName() const;
175 
176     QString key() const;
177 
178     QString toString() const;
179     bool fromString(const QString &);
180 
181 #ifndef QT_NO_STRINGLIST
182     static QString substitute(const QString &);
183     static QStringList substitutes(const QString &);
184     static QStringList substitutions();
185     static void insertSubstitution(const QString&, const QString &);
186     static void insertSubstitutions(const QString&, const QStringList &);
187     static void removeSubstitution(const QString &);
188 #endif //QT_NO_STRINGLIST
189     static void initialize();
190     static void cleanup();
191 #ifndef Q_WS_QWS
192     static void cacheStatistics();
193 #endif
194 
195 #if defined(Q_WS_QWS)
196     void qwsRenderToDisk(bool all=TRUE);
197 #endif
198 
199 
200     // a copy of this lives in qunicodetables.cpp, as we can't include
201     // qfont.h it in tools/. Do not modify without changing the script
202     // enum in qunicodetable_p.h aswell.
203     enum Script {
204 	// European Alphabetic Scripts
205 	Latin,
206 	Greek,
207 	Cyrillic,
208 	Armenian,
209 	Georgian,
210 	Runic,
211 	Ogham,
212 	SpacingModifiers,
213 	CombiningMarks,
214 
215 	// Middle Eastern Scripts
216 	Hebrew,
217 	Arabic,
218 	Syriac,
219 	Thaana,
220 
221 	// South and Southeast Asian Scripts
222 	Devanagari,
223 	Bengali,
224 	Gurmukhi,
225 	Gujarati,
226 	Oriya,
227 	Tamil,
228 	Telugu,
229 	Kannada,
230 	Malayalam,
231 	Sinhala,
232 	Thai,
233 	Lao,
234 	Tibetan,
235 	Myanmar,
236 	Khmer,
237 
238 	// East Asian Scripts
239 	Han,
240 	Hiragana,
241 	Katakana,
242 	Hangul,
243 	Bopomofo,
244 	Yi,
245 
246 	// Additional Scripts
247 	Ethiopic,
248 	Cherokee,
249 	CanadianAboriginal,
250 	Mongolian,
251 
252 	// Symbols
253 	CurrencySymbols,
254 	LetterlikeSymbols,
255 	NumberForms,
256 	MathematicalOperators,
257 	TechnicalSymbols,
258 	GeometricSymbols,
259 	MiscellaneousSymbols,
260 	EnclosedAndSquare,
261 	Braille,
262 
263 	Unicode,
264 
265 	// some scripts added in Unicode 3.2
266 	Tagalog,
267 	Hanunoo,
268 	Buhid,
269 	Tagbanwa,
270 
271 	KatakanaHalfWidth,
272 
273 	// from Unicode 4.0
274 	Limbu,
275 	TaiLe,
276 
277 	// End
278 #if !defined(Q_QDOC)
279 	NScripts,
280 	UnknownScript = NScripts,
281 
282 	NoScript,
283 
284 	// ----------------------------------------
285 	// Dear User, you can see values > NScript,
286 	// but they are internal - do not touch.
287 
288 	Han_Japanese,
289 	Han_SimplifiedChinese,
290 	Han_TraditionalChinese,
291 	Han_Korean,
292 
293 	LastPrivateScript
294 #endif
295     };
296 
297     QString defaultFamily() const;
298     QString lastResortFamily() const;
299     QString lastResortFont() const;
300 
301 #ifndef QT_NO_COMPAT
302 
303     static QFont defaultFont();
304     static void setDefaultFont( const QFont & );
305 
306 #endif // QT_NO_COMPAT
307 
308     QFont resolve( const QFont & ) const;
309 
310 protected:
311     // why protected?
312     bool dirty() const;
313     int deciPointSize() const;
314 
315 private:
316     QFont( QFontPrivate *, QPaintDevice *pd );
317 
318     void detach();
319 
320 #if defined(Q_WS_MAC)
321     void macSetFont(QPaintDevice *);
322 #elif defined(Q_WS_X11)
323     void x11SetScreen( int screen = -1 );
324     int x11Screen() const;
325 #endif
326 
327     friend class QFontMetrics;
328     friend class QFontInfo;
329     friend class QPainter;
330     friend class QPSPrinterFont;
331     friend class QApplication;
332     friend class QWidget;
333     friend class QTextFormatCollection;
334     friend class QTextLayout;
335     friend class QTextItem;
336     friend class QGLContext;
337 #if defined(Q_WS_X11) && !defined(QT_NO_XFTFREETYPE)
338     friend Qt::HANDLE qt_xft_handle(const QFont &font);
339 #endif
340 #ifndef QT_NO_DATASTREAM
341     friend Q_EXPORT QDataStream &operator<<( QDataStream &, const QFont & );
342     friend Q_EXPORT QDataStream &operator>>( QDataStream &, QFont & );
343 #endif
344 
345     QFontPrivate *d;
346 };
347 
348 
bold()349 inline bool QFont::bold() const
350 { return weight() > Normal; }
351 
352 
setBold(bool enable)353 inline void QFont::setBold( bool enable )
354 { setWeight( enable ? Bold : Normal ); }
355 
356 
357 
358 
359 /*****************************************************************************
360   QFont stream functions
361  *****************************************************************************/
362 
363 #ifndef QT_NO_DATASTREAM
364 Q_EXPORT QDataStream &operator<<( QDataStream &, const QFont & );
365 Q_EXPORT QDataStream &operator>>( QDataStream &, QFont & );
366 #endif
367 
368 
369 #endif // QFONT_H
370