Qt 4.8
qfont_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
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 #ifdef Q_WS_MAC
77  ,fixedPitchComputed(false)
78 #endif
79  {
80  }
81 
84 
85 #ifdef Q_WS_X11
87 #endif // Q_WS_X11
88 
91 
94 
95  uint weight : 7; // 0-99
97  uint style : 2;
98  uint stretch : 12; // 0-400
99 
102  uint fixedPitchComputed : 1; // for Mac OS X only
103  int reserved : 14; // for future extensions
104 
105  bool exactMatch(const QFontDef &other) const;
106  bool operator==(const QFontDef &other) const
107  {
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)
118 #ifdef Q_WS_X11
119  && addStyle == other.addStyle
120 #endif
121  ;
122  }
123  inline bool operator<(const QFontDef &other) const
124  {
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;
135 
136 #ifdef Q_WS_X11
137  if (addStyle != other.addStyle) return addStyle < other.addStyle;
138 #endif // Q_WS_X11
139 
140  if (ignorePitch != other.ignorePitch) return ignorePitch < other.ignorePitch;
141  if (fixedPitch != other.fixedPitch) return fixedPitch < other.fixedPitch;
142  return false;
143  }
144 };
145 
147 {
148 public:
149  QFontEngineData();
150  ~QFontEngineData();
151 
154 
155 #if !defined(Q_WS_MAC)
157 #else
159 #endif
160 };
161 
162 
164 {
165 public:
166 #ifdef Q_WS_X11
167  static int defaultEncodingID;
168 #endif // Q_WS_X11
169 
170  QFontPrivate();
171  QFontPrivate(const QFontPrivate &other);
172  ~QFontPrivate();
173 
174  QFontEngine *engineForScript(int script) const;
175  void alterCharForCapitalization(QChar &c) const;
176 
180  int dpi;
181  int screen;
182 
183 #ifdef Q_WS_WIN
184  HDC hdc;
185 #endif
186 
194 
197 
199  QFont smallCapsFont() const { return QFont(smallCapsFontPrivate()); }
200  QFontPrivate *smallCapsFontPrivate() const;
201 
202  static QFontPrivate *get(const QFont &font)
203  {
204  return font.d.data();
205  }
206 
207  void resolve(uint mask, const QFontPrivate *other);
208 private:
209  QFontPrivate &operator=(const QFontPrivate &) { return *this; }
210 };
211 
212 
213 class QFontCache : public QObject
214 {
215  Q_OBJECT
216 public:
217  // note: these static functions work on a per-thread basis
218  static QFontCache *instance();
219  static void cleanup();
220 
221  QFontCache();
222  ~QFontCache();
223 
224  void clear();
225 #if defined(Q_WS_QWS) && !defined(QT_NO_QWS_QPF2)
226  void removeEngineForFont(const QByteArray &fontName);
227 #endif
228  // universal key structure. QFontEngineDatas and QFontEngines are cached using
229  // the same keys
230  struct Key {
231  Key() : script(0), screen(0) { }
232  Key(const QFontDef &d, int c, int s = 0)
233  : def(d), script(c), screen(s) { }
234 
236  int script;
237  int screen;
238 
239  inline bool operator<(const Key &other) const
240  {
241  if (script != other.script) return script < other.script;
242  if (screen != other.screen) return screen < other.screen;
243  return def < other.def;
244  }
245  inline bool operator==(const Key &other) const
246  { return def == other.def && script == other.script && screen == other.screen; }
247  };
248 
249  // QFontEngineData cache
251  EngineDataCache engineDataCache;
252 
253  QFontEngineData *findEngineData(const Key &key) const;
254  void insertEngineData(const Key &key, QFontEngineData *engineData);
255 
256  // QFontEngine cache
257  struct Engine {
258  Engine() : data(0), timestamp(0), hits(0) { }
259  Engine(QFontEngine *d) : data(d), timestamp(0), hits(0) { }
260 
264  };
265 
267  EngineCache engineCache;
268 
269  QFontEngine *findEngine(const Key &key);
270  void insertEngine(const Key &key, QFontEngine *engine);
271 
272 #if defined(Q_WS_WIN) || defined(Q_WS_QWS)
273  void cleanupPrinterFonts();
274 #endif
275 
276  private:
277  void increaseCost(uint cost);
278  void decreaseCost(uint cost);
279  void timerEvent(QTimerEvent *event);
280 
281  static const uint min_cost;
282  uint total_cost, max_cost;
284  bool fast;
285  int timer_id;
286 };
287 
291 
293 
294 #endif // QFONT_P_H
uint fixedPitch
Definition: qfont_p.h:96
Q_GUI_EXPORT int qt_defaultDpiX()
Definition: qfont.cpp:162
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
uint fixedPitchComputed
Definition: qfont_p.h:102
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool operator==(const Key &other) const
Definition: qfont_p.h:245
EventRef event
bool letterSpacingIsAbsolute
Definition: qfont_p.h:193
qreal pointSize
Definition: qfont_p.h:89
QMap< Key, QFontEngineData * > EngineDataCache
Definition: qfont_p.h:250
The QAtomicInt class provides platform-independent atomic operations on integers. ...
Definition: qatomic.h:55
static const uint min_cost
Definition: qfont_p.h:281
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
EngineCache engineCache
Definition: qfont_p.h:267
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
QFontCache * fontCache
Definition: qfont_p.h:153
bool operator<(const QFontDef &other) const
Definition: qfont_p.h:123
static int defaultEncodingID
Definition: qfont_p.h:167
The QString class provides a Unicode character string.
Definition: qstring.h:83
QFontPrivate & operator=(const QFontPrivate &)
Definition: qfont_p.h:209
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QFixed wordSpacing
Definition: qfont_p.h:196
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
int reserved
Definition: qfont_p.h:103
Q_GUI_EXPORT int qt_defaultDpi()
Definition: qfont.cpp:240
uint rawMode
Definition: qfont_p.h:187
uint overline
Definition: qfont_p.h:189
uint underline
Definition: qfont_p.h:188
Key(const QFontDef &d, int c, int s=0)
Definition: qfont_p.h:232
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QFontDef def
Definition: qfont_p.h:235
QFontEngine * data
Definition: qfont_p.h:261
static QList< QAxEngineDescriptor > engines
Definition: qaxscript.cpp:69
bool operator<(const Key &other) const
Definition: qfont_p.h:239
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QFontDef request
Definition: qfont_p.h:178
uint capital
Definition: qfont_p.h:192
Engine(QFontEngine *d)
Definition: qfont_p.h:259
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
uint weight
Definition: qfont_p.h:95
uint total_cost
Definition: qfont_p.h:282
EngineDataCache engineDataCache
Definition: qfont_p.h:251
QMap< Key, Engine > EngineCache
Definition: qfont_p.h:266
QAtomicInt ref
Definition: qfont_p.h:152
uint ignorePitch
Definition: qfont_p.h:100
QFixed letterSpacing
Definition: qfont_p.h:195
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
#define Q_OBJECT
Definition: qobjectdefs.h:157
qreal pixelSize
Definition: qfont_p.h:90
QFontDef()
Definition: qfont_p.h:71
bool operator==(const QFontDef &other) const
Definition: qfont_p.h:106
uint current_timestamp
Definition: qfont_p.h:283
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
uint style
Definition: qfont_p.h:97
int key
QString styleName
Definition: qfont_p.h:83
static void cleanup()
Definition: qpicture.cpp:1508
if(void) toggleToolbarShown
uint stretch
Definition: qfont_p.h:98
int screen
Definition: qfont_p.h:181
bool exactMatch(const QFontDef &other) const
Definition: qfont.cpp:102
QAtomicInt ref
Definition: qfont_p.h:177
QFont smallCapsFont() const
Definition: qfont_p.h:199
QFontPrivate * scFont
Definition: qfont_p.h:198
QFontEngine * engine
Definition: qfont_p.h:158
uint kerning
Definition: qfont_p.h:191
QString addStyle
Definition: qfont_p.h:86
QString family
Definition: qfont_p.h:82
int timer_id
Definition: qfont_p.h:285
Q_GUI_EXPORT int qt_defaultDpiY()
Definition: qfont.cpp:201
QFontEngineData * engineData
Definition: qfont_p.h:179
uint hintingPreference
Definition: qfont_p.h:101
bool fast
Definition: qfont_p.h:284
uint styleHint
Definition: qfont_p.h:93
uint styleStrategy
Definition: qfont_p.h:92
uint strikeOut
Definition: qfont_p.h:190