source: trunk/src/kernel/qfontdata_p.h@ 7

Last change on this file since 7 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 7.0 KB
Line 
1/****************************************************************************
2** $Id: qfontdata_p.h 2 2005-11-16 15:49:26Z 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
57class QFontEngine;
58class QPaintDevice;
59
60
61struct 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#ifdef Q_WS_X11
104 if ( addStyle != other.addStyle ) return addStyle < other.addStyle;
105#endif // Q_WS_X11
106
107 return FALSE;
108 }
109};
110
111class QFontEngineData : public QShared
112{
113public:
114 QFontEngineData();
115 ~QFontEngineData();
116
117 uint lineWidth;
118
119#if defined(Q_WS_X11) || defined(Q_WS_WIN)
120 QFontEngine *engines[QFont::LastPrivateScript];
121#else
122 QFontEngine *engine;
123#endif // Q_WS_X11 || Q_WS_WIN
124#ifndef Q_WS_MAC
125 enum { widthCacheSize = 0x500 };
126 uchar widthCache[widthCacheSize];
127#endif
128};
129
130
131class QFontPrivate : public QShared
132{
133public:
134 static QFont::Script defaultScript;
135#ifdef Q_WS_X11
136 static int defaultEncodingID;
137#endif // Q_WS_X11
138
139 QFontPrivate();
140 QFontPrivate( const QFontPrivate &other );
141 ~QFontPrivate();
142
143 void load( QFont::Script script );
144 QFontEngine *engineForScript( QFont::Script script ) const {
145 if ( script == QFont::NoScript )
146 script = QFontPrivate::defaultScript;
147#if defined(Q_WS_X11) || defined(Q_WS_WIN)
148 if ( ! engineData || ! engineData->engines[script] )
149 ((QFontPrivate *) this)->load( script );
150 return engineData->engines[script];
151#else
152 if ( ! engineData || ! engineData->engine )
153 ((QFontPrivate *) this)->load( script );
154 return engineData->engine;
155#endif // Q_WS_X11 || Q_WS_WIN
156 }
157
158 QFontDef request;
159 QFontEngineData *engineData;
160 QPaintDevice *paintdevice;
161 int screen;
162
163 uint rawMode : 1;
164 uint underline : 1;
165 uint overline : 1;
166 uint strikeOut : 1;
167
168 enum {
169 Family = 0x0001,
170 Size = 0x0002,
171 StyleHint = 0x0004,
172 StyleStrategy = 0x0008,
173 Weight = 0x0010,
174 Italic = 0x0020,
175 Underline = 0x0040,
176 Overline = 0x0080,
177 StrikeOut = 0x0100,
178 FixedPitch = 0x0200,
179 Stretch = 0x0400,
180 Complete = 0x07ff
181 };
182
183 uint mask;
184
185 void resolve( const QFontPrivate *other );
186};
187
188
189class QFontCache : public QObject
190{
191public:
192 static QFontCache *instance;
193
194 QFontCache();
195 ~QFontCache();
196
197#ifdef Q_WS_QWS
198 void clear();
199#endif
200 // universal key structure. QFontEngineDatas and QFontEngines are cached using
201 // the same keys
202 struct Key {
203 Key() : screen( 0 ) { }
204 Key( const QFontDef &d, QFont::Script c, int s = 0 )
205 : def( d ), script( c ), screen( s ) { }
206
207 QFontDef def;
208 int script;
209 int screen;
210
211 inline bool operator<( const Key &other ) const
212 {
213 if ( script != other.script ) return script < other.script;
214 if ( screen != other.screen ) return screen < other.screen;
215 return def < other.def;
216 }
217 inline bool operator==( const Key &other ) const
218 { return def == other.def && script == other.script && screen == other.screen; }
219 };
220
221 // QFontEngineData cache
222 typedef QMap<Key,QFontEngineData*> EngineDataCache;
223 EngineDataCache engineDataCache;
224
225 QFontEngineData *findEngineData( const Key &key ) const;
226 void insertEngineData( const Key &key, QFontEngineData *engineData );
227
228 // QFontEngine cache
229 struct Engine {
230 Engine() : data( 0 ), timestamp( 0 ), hits( 0 ) { }
231 Engine( QFontEngine *d ) : data( d ), timestamp( 0 ), hits( 0 ) { }
232
233 QFontEngine *data;
234 uint timestamp;
235 uint hits;
236 };
237
238 typedef QMap<Key,Engine> EngineCache;
239 EngineCache engineCache;
240
241 QFontEngine *findEngine( const Key &key );
242 void insertEngine( const Key &key, QFontEngine *engine );
243
244#if defined(Q_WS_WIN) || defined(Q_WS_QWS)
245 void cleanupPrinterFonts();
246#endif
247
248 private:
249 void increaseCost( uint cost );
250 void decreaseCost( uint cost );
251 void timerEvent( QTimerEvent *event );
252
253 static const uint min_cost;
254 uint total_cost, max_cost;
255 uint current_timestamp;
256 bool fast;
257 int timer_id;
258};
259
260#endif // QFONTDATA_P_H
Note: See TracBrowser for help on using the repository browser.