Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qfont_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QFONT_P_H
5#define QFONT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of internal files. This header file may change from version to version
13// without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtGui/private/qtguiglobal_p.h>
19#include "QtGui/qfont.h"
20#include "QtCore/qmap.h"
21#include "QtCore/qhash.h"
22#include "QtCore/qobject.h"
23#include "QtCore/qstringlist.h"
24#include <QtGui/qfontdatabase.h>
25#include "private/qfixed_p.h"
26
28
29// forwards
30class QFontCache;
31class QFontEngine;
32
33#define QFONT_WEIGHT_MIN 1
34#define QFONT_WEIGHT_MAX 1000
35
37{
38 inline QFontDef()
39 : pointSize(-1.0),
40 pixelSize(-1),
41 styleStrategy(QFont::PreferDefault),
42 stretch(QFont::AnyStretch),
43 style(QFont::StyleNormal),
44 hintingPreference(QFont::PreferDefaultHinting),
45 styleHint(QFont::AnyStyle),
48 ignorePitch(true),
50 reserved(0)
51 {
52 }
53
56
58
61
62 // Note: Variable ordering matters to make sure no variable overlaps two 32-bit registers.
64 uint stretch : 12; // 0-4000
67
69 uint weight : 10; // 1-1000
72 uint fixedPitchComputed : 1; // for Mac OS X only
73 uint reserved : 11; // for future extensions
74
75 bool exactMatch(const QFontDef &other) const;
76 bool operator==(const QFontDef &other) const
77 {
78 return pixelSize == other.pixelSize
79 && weight == other.weight
80 && style == other.style
81 && stretch == other.stretch
82 && styleHint == other.styleHint
83 && styleStrategy == other.styleStrategy
84 && ignorePitch == other.ignorePitch && fixedPitch == other.fixedPitch
85 && families == other.families
86 && styleName == other.styleName
87 && hintingPreference == other.hintingPreference
88 ;
89 }
90 inline bool operator<(const QFontDef &other) const
91 {
92 if (pixelSize != other.pixelSize) return pixelSize < other.pixelSize;
93 if (weight != other.weight) return weight < other.weight;
94 if (style != other.style) return style < other.style;
95 if (stretch != other.stretch) return stretch < other.stretch;
96 if (styleHint != other.styleHint) return styleHint < other.styleHint;
97 if (styleStrategy != other.styleStrategy) return styleStrategy < other.styleStrategy;
98 if (families != other.families) return families < other.families;
99 if (styleName != other.styleName)
100 return styleName < other.styleName;
101 if (hintingPreference != other.hintingPreference) return hintingPreference < other.hintingPreference;
102
103
104 if (ignorePitch != other.ignorePitch) return ignorePitch < other.ignorePitch;
105 if (fixedPitch != other.fixedPitch) return fixedPitch < other.fixedPitch;
106 return false;
107 }
108};
109
110inline size_t qHash(const QFontDef &fd, size_t seed = 0) noexcept
111{
112 return qHashMulti(seed,
113 qRound64(fd.pixelSize*10000), // use only 4 fractional digits
114 fd.weight,
115 fd.style,
116 fd.stretch,
117 fd.styleHint,
118 fd.styleStrategy,
119 fd.ignorePitch,
120 fd.fixedPitch,
121 fd.families,
122 fd.styleName,
123 fd.hintingPreference);
124}
125
127{
128public:
131
133 const int fontCacheId;
134
136
137private:
138 Q_DISABLE_COPY_MOVE(QFontEngineData)
139};
140
141
142class Q_GUI_EXPORT QFontPrivate
143{
144public:
145
146 QFontPrivate();
149
150 QFontEngine *engineForScript(int script) const;
151 void alterCharForCapitalization(QChar &c) const;
152
156 int dpi;
157
164
168
170 QFont smallCapsFont() const { return QFont(smallCapsFontPrivate()); }
171 QFontPrivate *smallCapsFontPrivate() const;
172
173 static QFontPrivate *get(const QFont &font)
174 {
175 return font.d.data();
176 }
177
178 void resolve(uint mask, const QFontPrivate *other);
179
180 static void detachButKeepEngineData(QFont *font);
181
182 void setFeature(quint32 tag, quint32 value);
183 void unsetFeature(quint32 tag);
184
185private:
186 QFontPrivate &operator=(const QFontPrivate &) { return *this; }
187};
188
189
190class Q_GUI_EXPORT QFontCache : public QObject
191{
192public:
193 // note: these static functions work on a per-thread basis
194 static QFontCache *instance();
195 static void cleanup();
196
197 QFontCache();
198 ~QFontCache();
199
200 int id() const { return m_id; }
201
202 void clear();
203
204 struct Key {
205 Key() : script(0), multi(0) { }
206 Key(const QFontDef &d, uchar c, bool m = 0)
207 : def(d), script(c), multi(m) { }
208
212
213 inline bool operator<(const Key &other) const
214 {
215 if (script != other.script) return script < other.script;
216 if (multi != other.multi) return multi < other.multi;
217 if (multi && def.fallBackFamilies.size() != other.def.fallBackFamilies.size())
218 return def.fallBackFamilies.size() < other.def.fallBackFamilies.size();
219 return def < other.def;
220 }
221 inline bool operator==(const Key &other) const
222 {
223 return script == other.script
224 && multi == other.multi
225 && (!multi || def.fallBackFamilies == other.def.fallBackFamilies)
226 && def == other.def;
227 }
228 };
229
230 // QFontEngineData cache
233
234 QFontEngineData *findEngineData(const QFontDef &def) const;
235 void insertEngineData(const QFontDef &def, QFontEngineData *engineData);
236
237 // QFontEngine cache
238 struct Engine {
239 Engine() : data(nullptr), timestamp(0), hits(0) { }
240 Engine(QFontEngine *d) : data(d), timestamp(0), hits(0) { }
241
245 };
246
250
251 QFontEngine *findEngine(const Key &key);
252
253 void updateHitCountAndTimeStamp(Engine &value);
254 void insertEngine(const Key &key, QFontEngine *engine, bool insertMulti = false);
255
256private:
257 void increaseCost(uint cost);
258 void decreaseCost(uint cost);
259 void timerEvent(QTimerEvent *event) override;
260 void decreaseCache();
261
262 static const uint min_cost;
263 uint total_cost, max_cost;
264 uint current_timestamp;
265 bool fast;
266 const bool autoClean;
267 int timer_id;
268 const int m_id;
269};
270
271Q_GUI_EXPORT int qt_defaultDpiX();
272Q_GUI_EXPORT int qt_defaultDpiY();
273Q_GUI_EXPORT int qt_defaultDpi();
274
275Q_GUI_EXPORT int qt_legacyToOpenTypeWeight(int weight);
276Q_GUI_EXPORT int qt_openTypeToLegacyWeight(int weight);
277
279
280#endif // QFONT_P_H
\inmodule QtCore
Definition qatomic.h:112
\inmodule QtCore
Definition qchar.h:48
@ ScriptCount
Definition qchar.h:341
T * data() const noexcept
Returns a pointer to the shared data object.
EngineDataCache engineDataCache
Definition qfont_p.h:232
QMultiMap< Key, Engine > EngineCache
Definition qfont_p.h:247
EngineCache engineCache
Definition qfont_p.h:248
QMap< QFontDef, QFontEngineData * > EngineDataCache
Definition qfont_p.h:231
int id() const
Definition qfont_p.h:200
QHash< QFontEngine *, int > engineCacheCount
Definition qfont_p.h:249
QAtomicInt ref
Definition qfont_p.h:132
QFontEngine * engines[QChar::ScriptCount]
Definition qfont_p.h:135
const int fontCacheId
Definition qfont_p.h:133
bool letterSpacingIsAbsolute
Definition qfont_p.h:163
uint overline
Definition qfont_p.h:159
uint strikeOut
Definition qfont_p.h:160
QAtomicInt ref
Definition qfont_p.h:153
QFontDef request
Definition qfont_p.h:154
static QFontPrivate * get(const QFont &font)
Definition qfont_p.h:173
QHash< quint32, quint32 > features
Definition qfont_p.h:167
uint underline
Definition qfont_p.h:158
QFixed wordSpacing
Definition qfont_p.h:166
uint kerning
Definition qfont_p.h:161
QFixed letterSpacing
Definition qfont_p.h:165
QFontEngineData * engineData
Definition qfont_p.h:155
uint capital
Definition qfont_p.h:162
QFont smallCapsFont() const
Definition qfont_p.h:170
QFontPrivate * scFont
Definition qfont_p.h:169
\reentrant
Definition qfont.h:20
\inmodule QtCore
Definition qhash.h:818
Definition qmap.h:186
\inmodule QtCore
Definition qobject.h:90
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
Definition qcoreevent.h:359
b clear()
Combined button and popup list for selecting options.
AudioChannelLayoutTag tag
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
qint64 qRound64(qfloat16 d) noexcept
Definition qfloat16.h:284
Q_GUI_EXPORT int qt_openTypeToLegacyWeight(int weight)
Definition qfont.cpp:198
size_t qHash(const QFontDef &fd, size_t seed=0) noexcept
Definition qfont_p.h:110
Q_GUI_EXPORT int qt_defaultDpiX()
Definition qfont.cpp:107
Q_GUI_EXPORT int qt_legacyToOpenTypeWeight(int weight)
Definition qfont.cpp:192
Q_GUI_EXPORT int qt_defaultDpi()
Definition qfont.cpp:137
Q_GUI_EXPORT int qt_defaultDpiY()
Definition qfont.cpp:122
constexpr QtPrivate::QHashMultiReturnType< T... > qHashMulti(size_t seed, const T &... args) noexcept(std::conjunction_v< QtPrivate::QNothrowHashable< T >... >)
const GLfloat * m
GLuint64 key
GLuint GLuint GLfloat weight
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint64 GLenum GLint fd
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
struct _cl_event * event
const GLubyte * c
static qsizetype cost(const QPixmap &pixmap)
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
unsigned int quint32
Definition qtypes.h:45
unsigned char uchar
Definition qtypes.h:27
unsigned int uint
Definition qtypes.h:29
double qreal
Definition qtypes.h:92
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]
QJSEngine engine
[0]
Engine(QFontEngine *d)
Definition qfont_p.h:240
QFontEngine * data
Definition qfont_p.h:242
QFontDef def
Definition qfont_p.h:209
bool operator==(const Key &other) const
Definition qfont_p.h:221
bool operator<(const Key &other) const
Definition qfont_p.h:213
Key(const QFontDef &d, uchar c, bool m=0)
Definition qfont_p.h:206
uint hintingPreference
Definition qfont_p.h:66
uint reserved
Definition qfont_p.h:73
QFontDef()
Definition qfont_p.h:38
uint stretch
Definition qfont_p.h:64
uint style
Definition qfont_p.h:65
uint styleStrategy
Definition qfont_p.h:63
QStringList fallBackFamilies
Definition qfont_p.h:57
uint fixedPitch
Definition qfont_p.h:70
bool operator<(const QFontDef &other) const
Definition qfont_p.h:90
qreal pixelSize
Definition qfont_p.h:60
uint ignorePitch
Definition qfont_p.h:71
bool operator==(const QFontDef &other) const
Definition qfont_p.h:76
uint weight
Definition qfont_p.h:69
QStringList families
Definition qfont_p.h:54
QString styleName
Definition qfont_p.h:55
uint fixedPitchComputed
Definition qfont_p.h:72
bool exactMatch(const QFontDef &other) const
Definition qfont.cpp:49
uint styleHint
Definition qfont_p.h:68
qreal pointSize
Definition qfont_p.h:59