1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
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.
56 #include "QtGui/qfont.h"
57 #include "QtCore/qmap.h"
58 #include "QtCore/qobject.h"
59 #include "QtCore/qstringlist.h"
60 #include <private/qunicodetables_p.h>
61 #include <QtGui/qfontdatabase.h>
62 #include "private/qfixed_p.h"
73 : pointSize(-1.0), pixelSize(-1),
74 styleStrategy(QFont::PreferDefault), styleHint(QFont::AnyStyle),
75 weight(50), fixedPitch(false), style(QFont::StyleNormal), stretch(100),
76 ignorePitch(true), hintingPreference(QFont::PreferDefaultHinting)
83 QStringList fallBackFamilies;
88 uint styleStrategy : 16;
91 uint weight : 7; // 0-99
94 uint stretch : 12; // 0-400
97 uint hintingPreference : 2;
98 uint fixedPitchComputed : 1; // for Mac OS X only
99 int reserved : 14; // for future extensions
101 bool exactMatch(const QFontDef &other) const;
102 bool operator==(const QFontDef &other) const
104 return pixelSize == other.pixelSize
105 && weight == other.weight
106 && style == other.style
107 && stretch == other.stretch
108 && styleHint == other.styleHint
109 && styleStrategy == other.styleStrategy
110 && ignorePitch == other.ignorePitch && fixedPitch == other.fixedPitch
111 && family == other.family
112 && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName)
113 && hintingPreference == other.hintingPreference
116 inline bool operator<(const QFontDef &other) const
118 if (pixelSize != other.pixelSize) return pixelSize < other.pixelSize;
119 if (weight != other.weight) return weight < other.weight;
120 if (style != other.style) return style < other.style;
121 if (stretch != other.stretch) return stretch < other.stretch;
122 if (styleHint != other.styleHint) return styleHint < other.styleHint;
123 if (styleStrategy != other.styleStrategy) return styleStrategy < other.styleStrategy;
124 if (family != other.family) return family < other.family;
125 if (!styleName.isEmpty() && !other.styleName.isEmpty() && styleName != other.styleName)
126 return styleName < other.styleName;
127 if (hintingPreference != other.hintingPreference) return hintingPreference < other.hintingPreference;
130 if (ignorePitch != other.ignorePitch) return ignorePitch < other.ignorePitch;
131 if (fixedPitch != other.fixedPitch) return fixedPitch < other.fixedPitch;
136 class QFontEngineData
143 QFontCache *fontCache;
145 QFontEngine *engines[QUnicodeTables::ScriptCount];
149 class Q_GUI_EXPORT QFontPrivate
154 QFontPrivate(const QFontPrivate &other);
157 QFontEngine *engineForScript(int script) const;
158 void alterCharForCapitalization(QChar &c) const;
162 mutable QFontEngineData *engineData;
173 bool letterSpacingIsAbsolute : 1;
175 QFixed letterSpacing;
178 mutable QFontPrivate *scFont;
179 QFont smallCapsFont() const { return QFont(smallCapsFontPrivate()); }
180 QFontPrivate *smallCapsFontPrivate() const;
182 static QFontPrivate *get(const QFont &font)
184 return font.d.data();
187 void resolve(uint mask, const QFontPrivate *other);
189 QFontPrivate &operator=(const QFontPrivate &) { return *this; }
193 class QFontCache : public QObject
197 // note: these static functions work on a per-thread basis
198 static QFontCache *instance();
199 static void cleanup();
205 // universal key structure. QFontEngineDatas and QFontEngines are cached using
208 Key() : script(0), screen(0) { }
209 Key(const QFontDef &d, int c, int s = 0)
210 : def(d), script(c), screen(s) { }
216 inline bool operator<(const Key &other) const
218 if (script != other.script) return script < other.script;
219 if (screen != other.screen) return screen < other.screen;
220 return def < other.def;
222 inline bool operator==(const Key &other) const
223 { return def == other.def && script == other.script && screen == other.screen; }
226 // QFontEngineData cache
227 typedef QMap<QFontDef, QFontEngineData*> EngineDataCache;
228 EngineDataCache engineDataCache;
230 QFontEngineData *findEngineData(const QFontDef &def) const;
231 void insertEngineData(const QFontDef &def, QFontEngineData *engineData);
235 Engine() : data(0), timestamp(0), hits(0) { }
236 Engine(QFontEngine *d) : data(d), timestamp(0), hits(0) { }
243 typedef QMap<Key,Engine> EngineCache;
244 EngineCache engineCache;
246 QFontEngine *findEngine(const Key &key);
248 void updateHitCountAndTimeStamp(Engine &value);
249 void insertEngine(const Key &key, QFontEngine *engine, bool insertMulti = false);
252 void increaseCost(uint cost);
253 void decreaseCost(uint cost);
254 void timerEvent(QTimerEvent *event);
256 static const uint min_cost;
257 uint total_cost, max_cost;
258 uint current_timestamp;
263 Q_GUI_EXPORT int qt_defaultDpiX();
264 Q_GUI_EXPORT int qt_defaultDpiY();
265 Q_GUI_EXPORT int qt_defaultDpi();