1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** 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)
77 ,fixedPitchComputed(false)
92 uint styleStrategy : 16;
95 uint weight : 7; // 0-99
98 uint stretch : 12; // 0-400
100 uint ignorePitch : 1;
101 uint hintingPreference : 2;
102 uint fixedPitchComputed : 1; // for Mac OS X only
103 int reserved : 14; // for future extensions
105 bool exactMatch(const QFontDef &other) const;
106 bool operator==(const QFontDef &other) const
108 return pixelSize == other.pixelSize
109 && weight == other.weight
110 && style == other.style
111 && stretch == other.stretch
112 && styleHint == other.styleHint
113 && styleStrategy == other.styleStrategy
114 && ignorePitch == other.ignorePitch && fixedPitch == other.fixedPitch
115 && family == other.family
116 && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName)
117 && hintingPreference == other.hintingPreference
119 && addStyle == other.addStyle
123 inline bool operator<(const QFontDef &other) const
125 if (pixelSize != other.pixelSize) return pixelSize < other.pixelSize;
126 if (weight != other.weight) return weight < other.weight;
127 if (style != other.style) return style < other.style;
128 if (stretch != other.stretch) return stretch < other.stretch;
129 if (styleHint != other.styleHint) return styleHint < other.styleHint;
130 if (styleStrategy != other.styleStrategy) return styleStrategy < other.styleStrategy;
131 if (family != other.family) return family < other.family;
132 if (!styleName.isEmpty() && !other.styleName.isEmpty() && styleName != other.styleName)
133 return styleName < other.styleName;
134 if (hintingPreference != other.hintingPreference) return hintingPreference < other.hintingPreference;
137 if (addStyle != other.addStyle) return addStyle < other.addStyle;
140 if (ignorePitch != other.ignorePitch) return ignorePitch < other.ignorePitch;
141 if (fixedPitch != other.fixedPitch) return fixedPitch < other.fixedPitch;
146 class QFontEngineData
153 QFontCache *fontCache;
155 #if !defined(Q_WS_MAC)
156 QFontEngine *engines[QUnicodeTables::ScriptCount];
163 class Q_GUI_EXPORT QFontPrivate
167 static int defaultEncodingID;
171 QFontPrivate(const QFontPrivate &other);
174 QFontEngine *engineForScript(int script) const;
175 void alterCharForCapitalization(QChar &c) const;
179 mutable QFontEngineData *engineData;
193 bool letterSpacingIsAbsolute : 1;
195 QFixed letterSpacing;
198 mutable QFontPrivate *scFont;
199 QFont smallCapsFont() const { return QFont(smallCapsFontPrivate()); }
200 QFontPrivate *smallCapsFontPrivate() const;
202 static QFontPrivate *get(const QFont &font)
204 return font.d.data();
207 void resolve(uint mask, const QFontPrivate *other);
209 QFontPrivate &operator=(const QFontPrivate &) { return *this; }
213 class QFontCache : public QObject
217 // note: these static functions work on a per-thread basis
218 static QFontCache *instance();
219 static void cleanup();
225 #if defined(Q_WS_QWS) && !defined(QT_NO_QWS_QPF2)
226 void removeEngineForFont(const QByteArray &fontName);
228 // universal key structure. QFontEngineDatas and QFontEngines are cached using
231 Key() : script(0), screen(0) { }
232 Key(const QFontDef &d, int c, int s = 0)
233 : def(d), script(c), screen(s) { }
239 inline bool operator<(const Key &other) const
241 if (script != other.script) return script < other.script;
242 if (screen != other.screen) return screen < other.screen;
243 return def < other.def;
245 inline bool operator==(const Key &other) const
246 { return def == other.def && script == other.script && screen == other.screen; }
249 // QFontEngineData cache
250 typedef QMap<Key,QFontEngineData*> EngineDataCache;
251 EngineDataCache engineDataCache;
253 QFontEngineData *findEngineData(const Key &key) const;
254 void insertEngineData(const Key &key, QFontEngineData *engineData);
258 Engine() : data(0), timestamp(0), hits(0) { }
259 Engine(QFontEngine *d) : data(d), timestamp(0), hits(0) { }
266 typedef QMap<Key,Engine> EngineCache;
267 EngineCache engineCache;
269 QFontEngine *findEngine(const Key &key);
270 void insertEngine(const Key &key, QFontEngine *engine);
272 #if defined(Q_WS_WIN) || defined(Q_WS_QWS)
273 void cleanupPrinterFonts();
277 void increaseCost(uint cost);
278 void decreaseCost(uint cost);
279 void timerEvent(QTimerEvent *event);
281 static const uint min_cost;
282 uint total_cost, max_cost;
283 uint current_timestamp;
288 Q_GUI_EXPORT int qt_defaultDpiX();
289 Q_GUI_EXPORT int qt_defaultDpiY();
290 Q_GUI_EXPORT int qt_defaultDpi();