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
qfontdatabase_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 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 QFONTDATABASE_P_H
5#define QFONTDATABASE_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 <QtCore/qcache.h>
19
20#include <QtGui/qfontdatabase.h>
21#include <QtCore/private/qglobal_p.h>
22
24
25struct QtFontDesc;
26
34
35inline bool operator==(const QtFontFallbacksCacheKey &lhs, const QtFontFallbacksCacheKey &rhs) noexcept
36{
37 return lhs.script == rhs.script &&
38 lhs.styleHint == rhs.styleHint &&
39 lhs.style == rhs.style &&
40 lhs.family == rhs.family;
41}
42
43inline bool operator!=(const QtFontFallbacksCacheKey &lhs, const QtFontFallbacksCacheKey &rhs) noexcept
44{
45 return !operator==(lhs, rhs);
46}
47
48inline size_t qHash(const QtFontFallbacksCacheKey &key, size_t seed = 0) noexcept
49{
51 seed = hash(seed, key.family);
52 seed = hash(seed, int(key.style));
53 seed = hash(seed, int(key.styleHint));
54 seed = hash(seed, int(key.script));
55 return seed;
56}
57
58struct Q_GUI_EXPORT QtFontSize
59{
60 void *handle;
61 unsigned short pixelSize : 16;
62};
63
64struct Q_GUI_EXPORT QtFontStyle
65{
66 struct Key
67 {
68 Key(const QString &styleString);
69
71 : style(QFont::StyleNormal)
73 , stretch(0)
74 {}
75
76 Key(const Key &o)
77 : style(o.style)
78 , weight(o.weight)
79 , stretch(o.stretch)
80 {}
81
84 signed int stretch : 12;
85
86 bool operator==(const Key &other) const noexcept
87 {
88 return (style == other.style && weight == other.weight &&
89 (stretch == 0 || other.stretch == 0 || stretch == other.stretch));
90 }
91
92 bool operator!=(const Key &other) const noexcept
93 {
94 return !operator==(other);
95 }
96 };
97
98 QtFontStyle(const Key &k)
99 : key(k)
100 , bitmapScalable(false)
101 , smoothScalable(false)
102 , count(0)
103 , pixelSizes(nullptr)
104 {
105 }
106
107 ~QtFontStyle();
108
109 QtFontSize *pixelSize(unsigned short size, bool = false);
110
114 signed int count : 30;
118};
119
120struct Q_GUI_EXPORT QtFontFoundry
121{
123 : name(n)
124 , count(0)
125 , styles(nullptr)
126 {}
127
129 {
130 while (count--)
131 delete styles[count];
132 free(styles);
133 }
134
136 int count;
138 QtFontStyle *style(const QtFontStyle::Key &, const QString & = QString(), bool = false);
139};
140
141struct Q_GUI_EXPORT QtFontFamily
142{
145 Supported = 1,
146 UnsupportedFT = 2,
147 Unsupported = UnsupportedFT
148 };
149
151 :
152 populated(false),
153 fixedPitch(false),
154 name(n), count(0), foundries(nullptr)
155 {
156 memset(writingSystems, 0, sizeof(writingSystems));
157 }
159 while (count--)
160 delete foundries[count];
161 free(foundries);
162 }
163
164 bool populated : 1;
165 bool fixedPitch : 1;
166
169 int count;
171
172 unsigned char writingSystems[QFontDatabase::WritingSystemsCount];
173
174 bool matchesFamilyName(const QString &familyName) const;
175 QtFontFoundry *foundry(const QString &f, bool = false);
176
177 bool ensurePopulated();
178};
179
180class Q_GUI_EXPORT QFontDatabasePrivate
181{
182public:
184 : count(0)
185 , families(nullptr)
186 , fallbacksCache(64)
187 { }
188
190 clearFamilies();
191 }
192
193 void clearFamilies();
194
196 RequestFamily = 0,
198 EnsurePopulated
199 };
200
201 QtFontFamily *family(const QString &f, FamilyRequestFlags flags = EnsurePopulated);
202
203 int count;
205 bool populated = false;
206
207 QHash<QChar::Script, QStringList> applicationFallbackFontFamilies;
208
209 QCache<QtFontFallbacksCacheKey, QStringList> fallbacksCache;
212
213 // Note: The data may be implicitly shared throughout the
214 // font database and platform font database, so be careful
215 // to never detach when accessing this member!
217
218 bool isNull() const { return fileName.isEmpty(); }
219 bool isPopulated() const { return !properties.isEmpty(); }
220
228
229 QList<Properties> properties;
230 };
231 QList<ApplicationFont> applicationFonts;
232 int addAppFont(const QByteArray &fontData, const QString &fileName);
233 bool isApplicationFont(const QString &fileName);
234
235 static QFontDatabasePrivate *instance();
236
237 static void parseFontName(const QString &name, QString &foundry, QString &family);
238 static QString resolveFontFamilyAlias(const QString &family);
239 static QFontEngine *findFont(const QFontDef &request,
240 int script /* QChar::Script */,
241 bool preferScriptOverFamily = false);
242 static void load(const QFontPrivate *d, int script /* QChar::Script */);
243 static QFontDatabasePrivate *ensureFontDatabase();
244
245 void invalidate();
246
247private:
248 static int match(int script, const QFontDef &request, const QString &family_name,
249 const QString &foundry_name, QtFontDesc *desc, const QList<int> &blacklistedFamilies,
250 unsigned int *resultingScore = nullptr);
251
252 static unsigned int bestFoundry(int script, unsigned int score, int styleStrategy,
253 const QtFontFamily *family, const QString &foundry_name,
254 QtFontStyle::Key styleKey, int pixelSize, char pitch,
255 QtFontDesc *desc, const QString &styleName = QString());
256
257 static QFontEngine *loadSingleEngine(int script, const QFontDef &request,
258 QtFontFamily *family, QtFontFoundry *foundry,
259 QtFontStyle *style, QtFontSize *size);
260
261 static QFontEngine *loadEngine(int script, const QFontDef &request,
262 QtFontFamily *family, QtFontFoundry *foundry,
263 QtFontStyle *style, QtFontSize *size);
264
265};
267
269
270#endif // QFONTDATABASE_P_H
\inmodule QtCore
Definition qbytearray.h:57
QtFontFamily ** families
QList< ApplicationFont > applicationFonts
QCache< QtFontFallbacksCacheKey, QStringList > fallbacksCache
QHash< QChar::Script, QStringList > applicationFallbackFontFamilies
\reentrant
Definition qfont.h:22
StyleHint
Style hints are used by the \l{QFont}{font matching} algorithm to find an appropriate default family ...
Definition qfont.h:25
@ Unstretched
Definition qfont.h:89
Style
This enum describes the different styles of glyphs that are used to display text.
Definition qfont.h:76
@ StyleNormal
Definition qfont.h:77
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QHash< int, QWidget * > hash
[35multi]
p1 load("image.bmp")
Combined button and popup list for selecting options.
static const QCssKnownValue properties[NumProperties - 1]
static void parseFontName(const QString &name, QString &foundry, QString &family)
bool operator==(const QtFontFallbacksCacheKey &lhs, const QtFontFallbacksCacheKey &rhs) noexcept
size_t qHash(const QtFontFallbacksCacheKey &key, size_t seed=0) noexcept
bool operator!=(const QtFontFallbacksCacheKey &lhs, const QtFontFallbacksCacheKey &rhs) noexcept
GLuint64 key
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei count
GLfloat GLfloat f
GLuint GLuint GLfloat weight
GLbitfield flags
GLuint name
GLfloat n
GLenum GLsizeiptr const void * fontData
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Definition qrandom.cpp:1220
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:158
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
unsigned int uint
Definition qtypes.h:34
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]
QNetworkRequest request(url)
QFont::StyleHint styleHint
QtFontFoundry ** foundries
QStringList aliases
QtFontFamily(const QString &n)
QtFontStyle ** styles
QtFontFoundry(const QString &n)
unsigned short pixelSize
Key(const Key &o)
bool operator!=(const Key &other) const noexcept
bool operator==(const Key &other) const noexcept
QtFontSize * pixelSizes
QtFontStyle(const Key &k)
signed int count