Remove dead code.
[profile/ivi/qtbase.git] / src / gui / text / qfont_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
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), hintingPreference(QFont::PreferDefaultHinting)
76     {
77     }
78
79     QString family;
80     QString styleName;
81
82
83     qreal pointSize;
84     qreal pixelSize;
85
86     uint styleStrategy : 16;
87     uint styleHint     : 8;
88
89     uint weight     :  7; // 0-99
90     uint fixedPitch :  1;
91     uint style      :  2;
92     uint stretch    : 12; // 0-400
93
94     uint ignorePitch : 1;
95     uint hintingPreference : 2;
96     uint fixedPitchComputed : 1; // for Mac OS X only
97     int reserved   : 14; // for future extensions
98
99     bool exactMatch(const QFontDef &other) const;
100     bool operator==(const QFontDef &other) const
101     {
102         return pixelSize == other.pixelSize
103                     && weight == other.weight
104                     && style == other.style
105                     && stretch == other.stretch
106                     && styleHint == other.styleHint
107                     && styleStrategy == other.styleStrategy
108                     && ignorePitch == other.ignorePitch && fixedPitch == other.fixedPitch
109                     && family == other.family
110                     && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName)
111                     && hintingPreference == other.hintingPreference
112                           ;
113     }
114     inline bool operator<(const QFontDef &other) const
115     {
116         if (pixelSize != other.pixelSize) return pixelSize < other.pixelSize;
117         if (weight != other.weight) return weight < other.weight;
118         if (style != other.style) return style < other.style;
119         if (stretch != other.stretch) return stretch < other.stretch;
120         if (styleHint != other.styleHint) return styleHint < other.styleHint;
121         if (styleStrategy != other.styleStrategy) return styleStrategy < other.styleStrategy;
122         if (family != other.family) return family < other.family;
123         if (!styleName.isEmpty() && !other.styleName.isEmpty() && styleName != other.styleName)
124             return styleName < other.styleName;
125         if (hintingPreference != other.hintingPreference) return hintingPreference < other.hintingPreference;
126
127
128         if (ignorePitch != other.ignorePitch) return ignorePitch < other.ignorePitch;
129         if (fixedPitch != other.fixedPitch) return fixedPitch < other.fixedPitch;
130         return false;
131     }
132 };
133
134 class QFontEngineData
135 {
136 public:
137     QFontEngineData();
138     ~QFontEngineData();
139
140     QAtomicInt ref;
141     QFontCache *fontCache;
142
143     QFontEngine *engines[QUnicodeTables::ScriptCount];
144 };
145
146
147 class Q_GUI_EXPORT QFontPrivate
148 {
149 public:
150
151     QFontPrivate();
152     QFontPrivate(const QFontPrivate &other);
153     ~QFontPrivate();
154
155     QFontEngine *engineForScript(int script) const;
156     void alterCharForCapitalization(QChar &c) const;
157
158     QAtomicInt ref;
159     QFontDef request;
160     mutable QFontEngineData *engineData;
161     int dpi;
162     int screen;
163
164
165     uint rawMode    :  1;
166     uint underline  :  1;
167     uint overline   :  1;
168     uint strikeOut  :  1;
169     uint kerning    :  1;
170     uint capital    :  3;
171     bool letterSpacingIsAbsolute : 1;
172
173     QFixed letterSpacing;
174     QFixed wordSpacing;
175
176     mutable QFontPrivate *scFont;
177     QFont smallCapsFont() const { return QFont(smallCapsFontPrivate()); }
178     QFontPrivate *smallCapsFontPrivate() const;
179
180     static QFontPrivate *get(const QFont &font)
181     {
182         return font.d.data();
183     }
184
185     void resolve(uint mask, const QFontPrivate *other);
186 private:
187     QFontPrivate &operator=(const QFontPrivate &) { return *this; }
188 };
189
190
191 class QFontCache : public QObject
192 {
193     Q_OBJECT
194 public:
195     // note: these static functions work on a per-thread basis
196     static QFontCache *instance();
197     static void cleanup();
198
199     QFontCache();
200     ~QFontCache();
201
202     void clear();
203     // universal key structure.  QFontEngineDatas and QFontEngines are cached using
204     // the same keys
205     struct Key {
206         Key() : script(0), screen(0) { }
207         Key(const QFontDef &d, int c, int s = 0)
208             : def(d), script(c), screen(s) { }
209
210         QFontDef def;
211         int script;
212         int screen;
213
214         inline bool operator<(const Key &other) const
215         {
216             if (script != other.script) return script < other.script;
217             if (screen != other.screen) return screen < other.screen;
218             return def < other.def;
219         }
220         inline bool operator==(const Key &other) const
221         { return def == other.def && script == other.script && screen == other.screen; }
222     };
223
224     // QFontEngineData cache
225     typedef QMap<QFontDef, QFontEngineData*> EngineDataCache;
226     EngineDataCache engineDataCache;
227
228     QFontEngineData *findEngineData(const QFontDef &def) const;
229     void insertEngineData(const QFontDef &def, QFontEngineData *engineData);
230
231     // QFontEngine cache
232     struct Engine {
233         Engine() : data(0), timestamp(0), hits(0) { }
234         Engine(QFontEngine *d) : data(d), timestamp(0), hits(0) { }
235
236         QFontEngine *data;
237         uint timestamp;
238         uint hits;
239     };
240
241     typedef QMap<Key,Engine> EngineCache;
242     EngineCache engineCache;
243
244     QFontEngine *findEngine(const Key &key);
245
246     void updateHitCountAndTimeStamp(Engine &value);
247     void insertEngine(const Key &key, QFontEngine *engine, bool insertMulti = false);
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 Q_GUI_EXPORT int qt_defaultDpiX();
262 Q_GUI_EXPORT int qt_defaultDpiY();
263 Q_GUI_EXPORT int qt_defaultDpi();
264
265 QT_END_NAMESPACE
266
267 #endif // QFONT_P_H