Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 QMap<QFont::Tag, float> variableAxisValues;
59
62
63 // Note: Variable ordering matters to make sure no variable overlaps two 32-bit registers.
65 uint stretch : 12; // 0-4000
68
70 uint weight : 10; // 1-1000
73 uint fixedPitchComputed : 1; // for Mac OS X only
74 uint reserved : 11; // for future extensions
75
76 bool exactMatch(const QFontDef &other) const;
77 bool operator==(const QFontDef &other) const
78 {
79 return pixelSize == other.pixelSize
80 && weight == other.weight
81 && style == other.style
82 && stretch == other.stretch
83 && styleHint == other.styleHint
84 && styleStrategy == other.styleStrategy
85 && ignorePitch == other.ignorePitch && fixedPitch == other.fixedPitch
86 && families == other.families
87 && styleName == other.styleName
88 && hintingPreference == other.hintingPreference
89 && variableAxisValues == other.variableAxisValues
90 ;
91 }
92 inline bool operator<(const QFontDef &other) const
93 {
94 if (pixelSize != other.pixelSize) return pixelSize < other.pixelSize;
95 if (weight != other.weight) return weight < other.weight;
96 if (style != other.style) return style < other.style;
97 if (stretch != other.stretch) return stretch < other.stretch;
98 if (styleHint != other.styleHint) return styleHint < other.styleHint;
99 if (styleStrategy != other.styleStrategy) return styleStrategy < other.styleStrategy;
100 if (families != other.families) return families < other.families;
101 if (styleName != other.styleName)
102 return styleName < other.styleName;
103 if (hintingPreference != other.hintingPreference) return hintingPreference < other.hintingPreference;
104
105
106 if (ignorePitch != other.ignorePitch) return ignorePitch < other.ignorePitch;
107 if (fixedPitch != other.fixedPitch) return fixedPitch < other.fixedPitch;
108 if (variableAxisValues != other.variableAxisValues) {
109 if (variableAxisValues.size() != other.variableAxisValues.size())
110 return variableAxisValues.size() < other.variableAxisValues.size();
111
112 {
114 auto jt = other.variableAxisValues.constBegin();
115 for (; it != variableAxisValues.constEnd(); ++it, ++jt) {
116 if (it.key() != jt.key())
117 return jt.key() < it.key();
118 if (it.value() != jt.value())
119 return jt.value() < it.value();
120 }
121 }
122 }
123
124 return false;
125 }
126};
127
128inline size_t qHash(const QFontDef &fd, size_t seed = 0) noexcept
129{
130 return qHashMulti(seed,
131 qRound64(fd.pixelSize*10000), // use only 4 fractional digits
132 fd.weight,
133 fd.style,
134 fd.stretch,
135 fd.styleHint,
136 fd.styleStrategy,
137 fd.ignorePitch,
138 fd.fixedPitch,
139 fd.families,
140 fd.styleName,
141 fd.hintingPreference,
142 fd.variableAxisValues.keys(),
143 fd.variableAxisValues.values());
144}
145
147{
148public:
151
153 const int fontCacheId;
154
155 QFontEngine *engines[QChar::ScriptCount];
156
157private:
158 Q_DISABLE_COPY_MOVE(QFontEngineData)
159};
160
161
162class Q_GUI_EXPORT QFontPrivate
163{
164public:
165
166 QFontPrivate();
169
170 QFontEngine *engineForScript(int script) const;
171 void alterCharForCapitalization(QChar &c) const;
172
176 int dpi;
177
184
187 QHash<QFont::Tag, quint32> features;
188
190 QFont smallCapsFont() const { return QFont(smallCapsFontPrivate()); }
191 QFontPrivate *smallCapsFontPrivate() const;
192
193 static QFontPrivate *get(const QFont &font)
194 {
195 return font.d.data();
196 }
197
198 void resolve(uint mask, const QFontPrivate *other);
199
200 static void detachButKeepEngineData(QFont *font);
201
202 void setFeature(QFont::Tag tag, quint32 value);
203 void unsetFeature(QFont::Tag tag);
204
205 void setVariableAxis(QFont::Tag tag, float value);
206 void unsetVariableAxis(QFont::Tag tag);
207 bool hasVariableAxis(QFont::Tag tag, float value) const;
208
209private:
210 QFontPrivate &operator=(const QFontPrivate &) { return *this; }
211};
212
213
214class Q_GUI_EXPORT QFontCache : public QObject
215{
216public:
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 int id() const { return m_id; }
225
226 void clear();
227
228 struct Key {
229 Key() : script(0), multi(0) { }
230 Key(const QFontDef &d, uchar c, bool m = 0)
231 : def(d), script(c), multi(m) { }
232
236
237 inline bool operator<(const Key &other) const
238 {
239 if (script != other.script) return script < other.script;
240 if (multi != other.multi) return multi < other.multi;
241 if (multi && def.fallBackFamilies.size() != other.def.fallBackFamilies.size())
242 return def.fallBackFamilies.size() < other.def.fallBackFamilies.size();
243 return def < other.def;
244 }
245 inline bool operator==(const Key &other) const
246 {
247 return script == other.script
248 && multi == other.multi
249 && (!multi || def.fallBackFamilies == other.def.fallBackFamilies)
250 && def == other.def;
251 }
252 };
253
254 // QFontEngineData cache
255 typedef QMap<QFontDef, QFontEngineData*> EngineDataCache;
257
258 QFontEngineData *findEngineData(const QFontDef &def) const;
259 void insertEngineData(const QFontDef &def, QFontEngineData *engineData);
260
261 // QFontEngine cache
262 struct Engine {
263 Engine() : data(nullptr), timestamp(0), hits(0) { }
264 Engine(QFontEngine *d) : data(d), timestamp(0), hits(0) { }
265
269 };
270
271 typedef QMultiMap<Key,Engine> EngineCache;
273 QHash<QFontEngine *, int> engineCacheCount;
274
275 QFontEngine *findEngine(const Key &key);
276
277 void updateHitCountAndTimeStamp(Engine &value);
278 void insertEngine(const Key &key, QFontEngine *engine, bool insertMulti = false);
279
280private:
281 void increaseCost(uint cost);
282 void decreaseCost(uint cost);
283 void timerEvent(QTimerEvent *event) override;
284 void decreaseCache();
285
286 static const uint min_cost;
287 uint total_cost, max_cost;
288 uint current_timestamp;
289 bool fast;
290 const bool autoClean;
291 int timer_id;
292 const int m_id;
293};
294
295Q_GUI_EXPORT int qt_defaultDpiX();
296Q_GUI_EXPORT int qt_defaultDpiY();
297Q_GUI_EXPORT int qt_defaultDpi();
298
299Q_GUI_EXPORT int qt_legacyToOpenTypeWeight(int weight);
300Q_GUI_EXPORT int qt_openTypeToLegacyWeight(int weight);
301
303
304#endif // QFONT_P_H
\inmodule QtCore
Definition qatomic.h:112
\inmodule QtCore
T * data() const noexcept
Returns a pointer to the shared data object.
EngineDataCache engineDataCache
Definition qfont_p.h:256
QMultiMap< Key, Engine > EngineCache
Definition qfont_p.h:271
EngineCache engineCache
Definition qfont_p.h:272
QMap< QFontDef, QFontEngineData * > EngineDataCache
Definition qfont_p.h:255
int id() const
Definition qfont_p.h:224
QHash< QFontEngine *, int > engineCacheCount
Definition qfont_p.h:273
QAtomicInt ref
Definition qfont_p.h:152
QFontEngine * engines[QChar::ScriptCount]
Definition qfont_p.h:155
const int fontCacheId
Definition qfont_p.h:153
bool letterSpacingIsAbsolute
Definition qfont_p.h:183
uint overline
Definition qfont_p.h:179
uint strikeOut
Definition qfont_p.h:180
QAtomicInt ref
Definition qfont_p.h:173
QFontDef request
Definition qfont_p.h:174
static QFontPrivate * get(const QFont &font)
Definition qfont_p.h:193
uint underline
Definition qfont_p.h:178
QFixed wordSpacing
Definition qfont_p.h:186
uint kerning
Definition qfont_p.h:181
QFixed letterSpacing
Definition qfont_p.h:185
QFontEngineData * engineData
Definition qfont_p.h:175
uint capital
Definition qfont_p.h:182
QFont smallCapsFont() const
Definition qfont_p.h:190
QFontPrivate * scFont
Definition qfont_p.h:189
QHash< QFont::Tag, quint32 > features
Definition qfont_p.h:187
\reentrant
Definition qfont.h:22
const_iterator constBegin() const
Definition qmap.h:600
size_type size() const
Definition qmap.h:267
const_iterator constEnd() const
Definition qmap.h:604
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qcoreevent.h:366
b clear()
QSet< QString >::iterator it
Combined button and popup list for selecting options.
AudioChannelLayoutTag tag
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
qint64 qRound64(qfloat16 d) noexcept
Definition qfloat16.h:330
Q_GUI_EXPORT int qt_openTypeToLegacyWeight(int weight)
Definition qfont.cpp:201
size_t qHash(const QFontDef &fd, size_t seed=0) noexcept
Definition qfont_p.h:128
Q_GUI_EXPORT int qt_defaultDpiX()
Definition qfont.cpp:110
Q_GUI_EXPORT int qt_legacyToOpenTypeWeight(int weight)
Definition qfont.cpp:195
Q_GUI_EXPORT int qt_defaultDpi()
Definition qfont.cpp:140
Q_GUI_EXPORT int qt_defaultDpiY()
Definition qfont.cpp:125
constexpr QtPrivate::QHashMultiReturnType< T... > qHashMulti(size_t seed, const T &... args) noexcept(std::conjunction_v< QtPrivate::QNothrowHashable< T >... >)
const GLfloat * m
GLuint64 key
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLuint GLfloat weight
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 const QQmlJSScope * resolve(const QQmlJSScope *current, const QStringList &names)
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
unsigned int quint32
Definition qtypes.h:50
unsigned char uchar
Definition qtypes.h:32
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]
QJSEngine engine
[0]
Engine(QFontEngine *d)
Definition qfont_p.h:264
QFontEngine * data
Definition qfont_p.h:266
QFontDef def
Definition qfont_p.h:233
bool operator==(const Key &other) const
Definition qfont_p.h:245
bool operator<(const Key &other) const
Definition qfont_p.h:237
Key(const QFontDef &d, uchar c, bool m=0)
Definition qfont_p.h:230
uint hintingPreference
Definition qfont_p.h:67
uint reserved
Definition qfont_p.h:74
QFontDef()
Definition qfont_p.h:38
uint stretch
Definition qfont_p.h:65
uint style
Definition qfont_p.h:66
uint styleStrategy
Definition qfont_p.h:64
QStringList fallBackFamilies
Definition qfont_p.h:57
uint fixedPitch
Definition qfont_p.h:71
bool operator<(const QFontDef &other) const
Definition qfont_p.h:92
qreal pixelSize
Definition qfont_p.h:61
QMap< QFont::Tag, float > variableAxisValues
Definition qfont_p.h:58
uint ignorePitch
Definition qfont_p.h:72
bool operator==(const QFontDef &other) const
Definition qfont_p.h:77
uint weight
Definition qfont_p.h:70
QStringList families
Definition qfont_p.h:54
QString styleName
Definition qfont_p.h:55
uint fixedPitchComputed
Definition qfont_p.h:73
bool exactMatch(const QFontDef &other) const
Definition qfont.cpp:49
uint styleHint
Definition qfont_p.h:69
qreal pointSize
Definition qfont_p.h:60
The QFont::Tag type provides access to advanced font features.
Definition qfont.h:215