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 <private/qunicodetables_p.h>
60 #include <QtGui/qfontdatabase.h>
61 #include "private/qfixed_p.h"
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)
86 uint styleStrategy : 16;
89 uint weight : 7; // 0-99
92 uint stretch : 12; // 0-400
95 uint hintingPreference : 2;
96 uint fixedPitchComputed : 1; // for Mac OS X only
97 int reserved : 14; // for future extensions
99 bool exactMatch(const QFontDef &other) const;
100 bool operator==(const QFontDef &other) const
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
114 inline bool operator<(const QFontDef &other) const
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;
128 if (ignorePitch != other.ignorePitch) return ignorePitch < other.ignorePitch;
129 if (fixedPitch != other.fixedPitch) return fixedPitch < other.fixedPitch;
134 class QFontEngineData
141 QFontCache *fontCache;
143 QFontEngine *engines[QUnicodeTables::ScriptCount];
147 class Q_GUI_EXPORT QFontPrivate
152 QFontPrivate(const QFontPrivate &other);
155 QFontEngine *engineForScript(int script) const;
156 void alterCharForCapitalization(QChar &c) const;
160 mutable QFontEngineData *engineData;
171 bool letterSpacingIsAbsolute : 1;
173 QFixed letterSpacing;
176 mutable QFontPrivate *scFont;
177 QFont smallCapsFont() const { return QFont(smallCapsFontPrivate()); }
178 QFontPrivate *smallCapsFontPrivate() const;
180 static QFontPrivate *get(const QFont &font)
182 return font.d.data();
185 void resolve(uint mask, const QFontPrivate *other);
187 QFontPrivate &operator=(const QFontPrivate &) { return *this; }
191 class QFontCache : public QObject
195 // note: these static functions work on a per-thread basis
196 static QFontCache *instance();
197 static void cleanup();
203 // universal key structure. QFontEngineDatas and QFontEngines are cached using
206 Key() : script(0), screen(0) { }
207 Key(const QFontDef &d, int c, int s = 0)
208 : def(d), script(c), screen(s) { }
214 inline bool operator<(const Key &other) const
216 if (script != other.script) return script < other.script;
217 if (screen != other.screen) return screen < other.screen;
218 return def < other.def;
220 inline bool operator==(const Key &other) const
221 { return def == other.def && script == other.script && screen == other.screen; }
224 // QFontEngineData cache
225 typedef QMap<QFontDef, QFontEngineData*> EngineDataCache;
226 EngineDataCache engineDataCache;
228 QFontEngineData *findEngineData(const QFontDef &def) const;
229 void insertEngineData(const QFontDef &def, QFontEngineData *engineData);
233 Engine() : data(0), timestamp(0), hits(0) { }
234 Engine(QFontEngine *d) : data(d), timestamp(0), hits(0) { }
241 typedef QMap<Key,Engine> EngineCache;
242 EngineCache engineCache;
244 QFontEngine *findEngine(const Key &key);
246 void updateHitCountAndTimeStamp(Engine &value);
247 void insertEngine(const Key &key, QFontEngine *engine, bool insertMulti = false);
250 void increaseCost(uint cost);
251 void decreaseCost(uint cost);
252 void timerEvent(QTimerEvent *event);
254 static const uint min_cost;
255 uint total_cost, max_cost;
256 uint current_timestamp;
261 Q_GUI_EXPORT int qt_defaultDpiX();
262 Q_GUI_EXPORT int qt_defaultDpiY();
263 Q_GUI_EXPORT int qt_defaultDpi();