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_P_H
|
---|
43 | #define QFONT_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists for the convenience
|
---|
50 | // of internal files. This header file may change from version to version
|
---|
51 | // without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include "QtGui/qfont.h"
|
---|
57 | #include "QtCore/qmap.h"
|
---|
58 | #include "QtCore/qobject.h"
|
---|
59 | #include <private/qunicodetables_p.h>
|
---|
60 | #include <QtGui/qfontdatabase.h>
|
---|
61 | #include "private/qfixed_p.h"
|
---|
62 |
|
---|
63 | QT_BEGIN_NAMESPACE
|
---|
64 |
|
---|
65 | // forwards
|
---|
66 | class QFontCache;
|
---|
67 | class QFontEngine;
|
---|
68 |
|
---|
69 | struct QFontDef
|
---|
70 | {
|
---|
71 | inline QFontDef()
|
---|
72 | : pointSize(-1.0), pixelSize(-1),
|
---|
73 | styleStrategy(QFont::PreferDefault), styleHint(QFont::AnyStyle),
|
---|
74 | weight(50), fixedPitch(false), style(QFont::StyleNormal), stretch(100),
|
---|
75 | ignorePitch(true)
|
---|
76 | #ifdef Q_WS_MAC
|
---|
77 | ,fixedPitchComputed(false)
|
---|
78 | #endif
|
---|
79 | {
|
---|
80 | }
|
---|
81 |
|
---|
82 | QString family;
|
---|
83 |
|
---|
84 | #ifdef Q_WS_X11
|
---|
85 | QString addStyle;
|
---|
86 | #endif // Q_WS_X11
|
---|
87 |
|
---|
88 | qreal pointSize;
|
---|
89 | qreal pixelSize;
|
---|
90 |
|
---|
91 | uint styleStrategy : 16;
|
---|
92 | uint styleHint : 8;
|
---|
93 |
|
---|
94 | uint weight : 7; // 0-99
|
---|
95 | uint fixedPitch : 1;
|
---|
96 | uint style : 2;
|
---|
97 | uint stretch : 12; // 0-400
|
---|
98 |
|
---|
99 | uint ignorePitch : 1;
|
---|
100 | uint fixedPitchComputed : 1; // for Mac OS X only
|
---|
101 | int reserved : 16; // for future extensions
|
---|
102 |
|
---|
103 | bool exactMatch(const QFontDef &other) const;
|
---|
104 | bool operator==(const QFontDef &other) const
|
---|
105 | {
|
---|
106 | return pixelSize == other.pixelSize
|
---|
107 | && weight == other.weight
|
---|
108 | && style == other.style
|
---|
109 | && stretch == other.stretch
|
---|
110 | && styleHint == other.styleHint
|
---|
111 | && styleStrategy == other.styleStrategy
|
---|
112 | && ignorePitch == other.ignorePitch && fixedPitch == other.fixedPitch
|
---|
113 | && family == other.family
|
---|
114 | #ifdef Q_WS_X11
|
---|
115 | && addStyle == other.addStyle
|
---|
116 | #endif
|
---|
117 | ;
|
---|
118 | }
|
---|
119 | inline bool operator<(const QFontDef &other) const
|
---|
120 | {
|
---|
121 | if (pixelSize != other.pixelSize) return pixelSize < other.pixelSize;
|
---|
122 | if (weight != other.weight) return weight < other.weight;
|
---|
123 | if (style != other.style) return style < other.style;
|
---|
124 | if (stretch != other.stretch) return stretch < other.stretch;
|
---|
125 | if (styleHint != other.styleHint) return styleHint < other.styleHint;
|
---|
126 | if (styleStrategy != other.styleStrategy) return styleStrategy < other.styleStrategy;
|
---|
127 | if (family != other.family) return family < other.family;
|
---|
128 |
|
---|
129 | #ifdef Q_WS_X11
|
---|
130 | if (addStyle != other.addStyle) return addStyle < other.addStyle;
|
---|
131 | #endif // Q_WS_X11
|
---|
132 |
|
---|
133 | if (ignorePitch != other.ignorePitch) return ignorePitch < other.ignorePitch;
|
---|
134 | if (fixedPitch != other.fixedPitch) return fixedPitch < other.fixedPitch;
|
---|
135 | return false;
|
---|
136 | }
|
---|
137 | };
|
---|
138 |
|
---|
139 | class QFontEngineData
|
---|
140 | {
|
---|
141 | public:
|
---|
142 | QFontEngineData();
|
---|
143 | ~QFontEngineData();
|
---|
144 |
|
---|
145 | QAtomicInt ref;
|
---|
146 | QFontCache *fontCache;
|
---|
147 |
|
---|
148 | #if !defined(Q_WS_MAC)
|
---|
149 | QFontEngine *engines[QUnicodeTables::ScriptCount];
|
---|
150 | #else
|
---|
151 | QFontEngine *engine;
|
---|
152 | #endif
|
---|
153 | };
|
---|
154 |
|
---|
155 |
|
---|
156 | class Q_GUI_EXPORT QFontPrivate
|
---|
157 | {
|
---|
158 | public:
|
---|
159 | #ifdef Q_WS_X11
|
---|
160 | static int defaultEncodingID;
|
---|
161 | #endif // Q_WS_X11
|
---|
162 |
|
---|
163 | QFontPrivate();
|
---|
164 | QFontPrivate(const QFontPrivate &other);
|
---|
165 | ~QFontPrivate();
|
---|
166 |
|
---|
167 | QFontEngine *engineForScript(int script) const;
|
---|
168 | void alterCharForCapitalization(QChar &c) const;
|
---|
169 |
|
---|
170 | QAtomicInt ref;
|
---|
171 | QFontDef request;
|
---|
172 | mutable QFontEngineData *engineData;
|
---|
173 | int dpi;
|
---|
174 | int screen;
|
---|
175 |
|
---|
176 | #ifdef Q_WS_WIN
|
---|
177 | HDC hdc;
|
---|
178 | #endif
|
---|
179 |
|
---|
180 | uint rawMode : 1;
|
---|
181 | uint underline : 1;
|
---|
182 | uint overline : 1;
|
---|
183 | uint strikeOut : 1;
|
---|
184 | uint kerning : 1;
|
---|
185 | uint capital : 3;
|
---|
186 | bool letterSpacingIsAbsolute : 1;
|
---|
187 |
|
---|
188 | QFixed letterSpacing;
|
---|
189 | QFixed wordSpacing;
|
---|
190 |
|
---|
191 | mutable QFontPrivate *scFont;
|
---|
192 | QFont smallCapsFont() const { return QFont(smallCapsFontPrivate()); }
|
---|
193 | QFontPrivate *smallCapsFontPrivate() const;
|
---|
194 |
|
---|
195 | void resolve(uint mask, const QFontPrivate *other);
|
---|
196 | private:
|
---|
197 | QFontPrivate &operator=(const QFontPrivate &) { return *this; }
|
---|
198 | };
|
---|
199 |
|
---|
200 |
|
---|
201 | class QFontCache : public QObject
|
---|
202 | {
|
---|
203 | Q_OBJECT
|
---|
204 | public:
|
---|
205 | // note: these static functions work on a per-thread basis
|
---|
206 | static QFontCache *instance();
|
---|
207 | static void cleanup();
|
---|
208 |
|
---|
209 | QFontCache();
|
---|
210 | ~QFontCache();
|
---|
211 |
|
---|
212 | void clear();
|
---|
213 | #if defined(Q_WS_QWS) && !defined(QT_NO_QWS_QPF2)
|
---|
214 | void removeEngineForFont(const QByteArray &fontName);
|
---|
215 | #endif
|
---|
216 | // universal key structure. QFontEngineDatas and QFontEngines are cached using
|
---|
217 | // the same keys
|
---|
218 | struct Key {
|
---|
219 | Key() : script(0), screen(0) { }
|
---|
220 | Key(const QFontDef &d, int c, int s = 0)
|
---|
221 | : def(d), script(c), screen(s) { }
|
---|
222 |
|
---|
223 | QFontDef def;
|
---|
224 | int script;
|
---|
225 | int screen;
|
---|
226 |
|
---|
227 | inline bool operator<(const Key &other) const
|
---|
228 | {
|
---|
229 | if (script != other.script) return script < other.script;
|
---|
230 | if (screen != other.screen) return screen < other.screen;
|
---|
231 | return def < other.def;
|
---|
232 | }
|
---|
233 | inline bool operator==(const Key &other) const
|
---|
234 | { return def == other.def && script == other.script && screen == other.screen; }
|
---|
235 | };
|
---|
236 |
|
---|
237 | // QFontEngineData cache
|
---|
238 | typedef QMap<Key,QFontEngineData*> EngineDataCache;
|
---|
239 | EngineDataCache engineDataCache;
|
---|
240 |
|
---|
241 | QFontEngineData *findEngineData(const Key &key) const;
|
---|
242 | void insertEngineData(const Key &key, QFontEngineData *engineData);
|
---|
243 |
|
---|
244 | // QFontEngine cache
|
---|
245 | struct Engine {
|
---|
246 | Engine() : data(0), timestamp(0), hits(0) { }
|
---|
247 | Engine(QFontEngine *d) : data(d), timestamp(0), hits(0) { }
|
---|
248 |
|
---|
249 | QFontEngine *data;
|
---|
250 | uint timestamp;
|
---|
251 | uint hits;
|
---|
252 | };
|
---|
253 |
|
---|
254 | typedef QMap<Key,Engine> EngineCache;
|
---|
255 | EngineCache engineCache;
|
---|
256 |
|
---|
257 | QFontEngine *findEngine(const Key &key);
|
---|
258 | void insertEngine(const Key &key, QFontEngine *engine);
|
---|
259 |
|
---|
260 | #if defined(Q_WS_WIN) || defined(Q_WS_QWS)
|
---|
261 | void cleanupPrinterFonts();
|
---|
262 | #endif
|
---|
263 |
|
---|
264 | private:
|
---|
265 | void increaseCost(uint cost);
|
---|
266 | void decreaseCost(uint cost);
|
---|
267 | void timerEvent(QTimerEvent *event);
|
---|
268 |
|
---|
269 | static const uint min_cost;
|
---|
270 | uint total_cost, max_cost;
|
---|
271 | uint current_timestamp;
|
---|
272 | bool fast;
|
---|
273 | int timer_id;
|
---|
274 | };
|
---|
275 |
|
---|
276 | #ifdef Q_WS_PM
|
---|
277 | Q_GUI_EXPORT const char *qt_fontFamilyFromStyleHint(const QFontDef &request);
|
---|
278 | #endif
|
---|
279 |
|
---|
280 | QT_END_NAMESPACE
|
---|
281 |
|
---|
282 | #endif // QFONT_P_H
|
---|