1 | /****************************************************************************
|
---|
2 | ** $Id: qfontdata_p.h 8 2005-11-16 19:36:46Z dmik $
|
---|
3 | **
|
---|
4 | ** Definition of internal QFontData struct
|
---|
5 | **
|
---|
6 | ** Created : 941229
|
---|
7 | **
|
---|
8 | ** Copyright (C) 1992-2002 Trolltech AS. 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 AS 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 QFONTDATA_P_H
|
---|
39 | #define QFONTDATA_P_H
|
---|
40 |
|
---|
41 | //
|
---|
42 | // W A R N I N G
|
---|
43 | // -------------
|
---|
44 | //
|
---|
45 | // This file is not part of the Qt API. It exists for the convenience
|
---|
46 | // of internal files. This header file may change from version to version
|
---|
47 | // without notice, or even be removed.
|
---|
48 | //
|
---|
49 | // We mean it.
|
---|
50 | //
|
---|
51 | //
|
---|
52 |
|
---|
53 | #include "qobject.h"
|
---|
54 | #include "qfont.h"
|
---|
55 |
|
---|
56 | // forwards
|
---|
57 | class QFontEngine;
|
---|
58 | class QPaintDevice;
|
---|
59 |
|
---|
60 |
|
---|
61 | struct QFontDef
|
---|
62 | {
|
---|
63 | inline QFontDef()
|
---|
64 | : pointSize( -1 ), pixelSize( -1 ),
|
---|
65 | styleHint( QFont::AnyStyle ), styleStrategy( QFont::PreferDefault ),
|
---|
66 | weight( 50 ), italic( FALSE ), fixedPitch( FALSE ), stretch( 100 ),
|
---|
67 | ignorePitch(TRUE)
|
---|
68 | {
|
---|
69 | }
|
---|
70 |
|
---|
71 | QString family;
|
---|
72 |
|
---|
73 | #ifdef Q_WS_X11
|
---|
74 | QString addStyle;
|
---|
75 | #endif // Q_WS_X11
|
---|
76 |
|
---|
77 | int pointSize;
|
---|
78 | int pixelSize;
|
---|
79 |
|
---|
80 | uint styleHint : 8;
|
---|
81 | uint styleStrategy : 16;
|
---|
82 |
|
---|
83 | uint weight : 7; // 0-99
|
---|
84 | uint italic : 1;
|
---|
85 | uint fixedPitch : 1;
|
---|
86 | uint stretch : 12; // 0-400
|
---|
87 |
|
---|
88 | uint ignorePitch : 1;
|
---|
89 | uint fixedPitchComputed : 1; // for Mac OS X only
|
---|
90 | uint reserved : 14; // for future extensions
|
---|
91 |
|
---|
92 | bool operator==( const QFontDef &other ) const;
|
---|
93 | inline bool operator<( const QFontDef &other ) const
|
---|
94 | {
|
---|
95 | if ( pixelSize != other.pixelSize ) return pixelSize < other.pixelSize;
|
---|
96 | if ( weight != other.weight ) return weight < other.weight;
|
---|
97 | if ( italic != other.italic ) return italic < other.italic;
|
---|
98 | if ( stretch != other.stretch ) return stretch < other.stretch;
|
---|
99 | if ( styleHint != other.styleHint ) return styleHint < other.styleHint;
|
---|
100 | if ( styleStrategy != other.styleStrategy ) return styleStrategy < other.styleStrategy;
|
---|
101 | if ( family != other.family ) return family < other.family;
|
---|
102 |
|
---|
103 | #if defined(Q_WS_X11)
|
---|
104 | if ( addStyle != other.addStyle ) return addStyle < other.addStyle;
|
---|
105 | #elif defined(Q_WS_PM)
|
---|
106 | if ( pointSize != other.pointSize ) return pointSize < other.pointSize;
|
---|
107 | #endif
|
---|
108 | return FALSE;
|
---|
109 | }
|
---|
110 | };
|
---|
111 |
|
---|
112 | class QFontEngineData : public QShared
|
---|
113 | {
|
---|
114 | public:
|
---|
115 | QFontEngineData();
|
---|
116 | ~QFontEngineData();
|
---|
117 |
|
---|
118 | uint lineWidth;
|
---|
119 |
|
---|
120 | #if defined(Q_WS_X11) || defined(Q_WS_WIN)
|
---|
121 | QFontEngine *engines[QFont::LastPrivateScript];
|
---|
122 | #else
|
---|
123 | QFontEngine *engine;
|
---|
124 | #endif // Q_WS_X11 || Q_WS_WIN
|
---|
125 | #ifndef Q_WS_MAC
|
---|
126 | enum { widthCacheSize = 0x500 };
|
---|
127 | uchar widthCache[widthCacheSize];
|
---|
128 | #endif
|
---|
129 | };
|
---|
130 |
|
---|
131 |
|
---|
132 | class QFontPrivate : public QShared
|
---|
133 | {
|
---|
134 | public:
|
---|
135 | static QFont::Script defaultScript;
|
---|
136 | #ifdef Q_WS_X11
|
---|
137 | static int defaultEncodingID;
|
---|
138 | #endif // Q_WS_X11
|
---|
139 |
|
---|
140 | QFontPrivate();
|
---|
141 | QFontPrivate( const QFontPrivate &other );
|
---|
142 | ~QFontPrivate();
|
---|
143 |
|
---|
144 | void load( QFont::Script script );
|
---|
145 | QFontEngine *engineForScript( QFont::Script script ) const {
|
---|
146 | if ( script == QFont::NoScript )
|
---|
147 | script = QFontPrivate::defaultScript;
|
---|
148 | #if defined(Q_WS_X11) || defined(Q_WS_WIN)
|
---|
149 | if ( ! engineData || ! engineData->engines[script] )
|
---|
150 | ((QFontPrivate *) this)->load( script );
|
---|
151 | return engineData->engines[script];
|
---|
152 | #else
|
---|
153 | if ( ! engineData || ! engineData->engine )
|
---|
154 | ((QFontPrivate *) this)->load( script );
|
---|
155 | return engineData->engine;
|
---|
156 | #endif // Q_WS_X11 || Q_WS_WIN
|
---|
157 | }
|
---|
158 |
|
---|
159 | QFontDef request;
|
---|
160 | QFontEngineData *engineData;
|
---|
161 | QPaintDevice *paintdevice;
|
---|
162 | int screen;
|
---|
163 |
|
---|
164 | uint rawMode : 1;
|
---|
165 | uint underline : 1;
|
---|
166 | uint overline : 1;
|
---|
167 | uint strikeOut : 1;
|
---|
168 |
|
---|
169 | enum {
|
---|
170 | Family = 0x0001,
|
---|
171 | Size = 0x0002,
|
---|
172 | StyleHint = 0x0004,
|
---|
173 | StyleStrategy = 0x0008,
|
---|
174 | Weight = 0x0010,
|
---|
175 | Italic = 0x0020,
|
---|
176 | Underline = 0x0040,
|
---|
177 | Overline = 0x0080,
|
---|
178 | StrikeOut = 0x0100,
|
---|
179 | FixedPitch = 0x0200,
|
---|
180 | Stretch = 0x0400,
|
---|
181 | Complete = 0x07ff
|
---|
182 | };
|
---|
183 |
|
---|
184 | uint mask;
|
---|
185 |
|
---|
186 | void resolve( const QFontPrivate *other );
|
---|
187 | };
|
---|
188 |
|
---|
189 |
|
---|
190 | class QFontCache : public QObject
|
---|
191 | {
|
---|
192 | public:
|
---|
193 | static QFontCache *instance;
|
---|
194 |
|
---|
195 | QFontCache();
|
---|
196 | ~QFontCache();
|
---|
197 |
|
---|
198 | #ifdef Q_WS_QWS
|
---|
199 | void clear();
|
---|
200 | #endif
|
---|
201 | // universal key structure. QFontEngineDatas and QFontEngines are cached using
|
---|
202 | // the same keys
|
---|
203 | struct Key {
|
---|
204 | Key() : screen( 0 ) { }
|
---|
205 | Key( const QFontDef &d, QFont::Script c, int s = 0 )
|
---|
206 | : def( d ), script( c ), screen( s ) { }
|
---|
207 |
|
---|
208 | QFontDef def;
|
---|
209 | int script;
|
---|
210 | int screen;
|
---|
211 |
|
---|
212 | inline bool operator<( const Key &other ) const
|
---|
213 | {
|
---|
214 | if ( script != other.script ) return script < other.script;
|
---|
215 | if ( screen != other.screen ) return screen < other.screen;
|
---|
216 | return def < other.def;
|
---|
217 | }
|
---|
218 | inline bool operator==( const Key &other ) const
|
---|
219 | { return def == other.def && script == other.script && screen == other.screen; }
|
---|
220 | };
|
---|
221 |
|
---|
222 | // QFontEngineData cache
|
---|
223 | typedef QMap<Key,QFontEngineData*> EngineDataCache;
|
---|
224 | EngineDataCache engineDataCache;
|
---|
225 |
|
---|
226 | QFontEngineData *findEngineData( const Key &key ) const;
|
---|
227 | void insertEngineData( const Key &key, QFontEngineData *engineData );
|
---|
228 |
|
---|
229 | // QFontEngine cache
|
---|
230 | struct Engine {
|
---|
231 | Engine() : data( 0 ), timestamp( 0 ), hits( 0 ) { }
|
---|
232 | Engine( QFontEngine *d ) : data( d ), timestamp( 0 ), hits( 0 ) { }
|
---|
233 |
|
---|
234 | QFontEngine *data;
|
---|
235 | uint timestamp;
|
---|
236 | uint hits;
|
---|
237 | };
|
---|
238 |
|
---|
239 | typedef QMap<Key,Engine> EngineCache;
|
---|
240 | EngineCache engineCache;
|
---|
241 |
|
---|
242 | QFontEngine *findEngine( const Key &key );
|
---|
243 | void insertEngine( const Key &key, QFontEngine *engine );
|
---|
244 |
|
---|
245 | #if defined(Q_WS_WIN) || defined(Q_WS_PM) || defined(Q_WS_QWS)
|
---|
246 | void cleanupPrinterFonts();
|
---|
247 | #endif
|
---|
248 |
|
---|
249 | private:
|
---|
250 | void increaseCost( uint cost );
|
---|
251 | void decreaseCost( uint cost );
|
---|
252 | void timerEvent( QTimerEvent *event );
|
---|
253 |
|
---|
254 | static const uint min_cost;
|
---|
255 | uint total_cost, max_cost;
|
---|
256 | uint current_timestamp;
|
---|
257 | bool fast;
|
---|
258 | int timer_id;
|
---|
259 | };
|
---|
260 |
|
---|
261 | #endif // QFONTDATA_P_H
|
---|