18#include <QtGui/private/qtguiglobal_p.h>
19#include "QtGui/qfont.h"
20#include "QtCore/qbasictimer.h"
21#include "QtCore/qmap.h"
22#include "QtCore/qhash.h"
23#include "QtCore/qobject.h"
24#include "QtCore/qstringlist.h"
25#include <QtGui/qfontdatabase.h>
26#include "private/qfixed_p.h"
27#include "private/qfontdatabase_p.h"
35#define QFONT_WEIGHT_MIN 1
36#define QFONT_WEIGHT_MAX 1000
81 return pixelSize == other.pixelSize
82 && weight == other.weight
83 && style == other.style
84 && stretch == other.stretch
85 && styleHint == other.styleHint
86 && styleStrategy == other.styleStrategy
87 && ignorePitch == other.ignorePitch && fixedPitch == other.fixedPitch
88 && families == other.families
89 && styleName == other.styleName
90 && hintingPreference == other.hintingPreference
91 && variableAxisValues == other.variableAxisValues
96 if (pixelSize != other.pixelSize)
return pixelSize < other.pixelSize;
102 if (families != other.families)
return families < other.families;
103 if (styleName != other.styleName)
104 return styleName < other.styleName;
110 if (variableAxisValues != other.variableAxisValues) {
111 if (variableAxisValues.size() != other.variableAxisValues.size())
112 return variableAxisValues.size() < other.variableAxisValues.size();
115 auto it = variableAxisValues.constBegin();
116 auto jt = other.variableAxisValues.constBegin();
117 for (; it != variableAxisValues.constEnd(); ++it, ++jt) {
118 if (it.key() != jt.key())
119 return jt.key() < it.key();
120 if (it.value() != jt.value())
121 return jt.value() < it.value();
132 return qHashMulti(seed,
133 qRound64(fd.pixelSize*10000),
144 fd.variableAxisValues.keys(),
145 fd.variableAxisValues.values());
166 enum class EngineQueryOption {
168 IgnoreSmallCapsEngine = 0x1,
170 Q_DECLARE_FLAGS(EngineQueryOptions, EngineQueryOption)
173 QFontPrivate(
const QFontPrivate &other);
174 QFontPrivate &operator=(
const QFontPrivate &) =
delete;
177 QFontEngine *engineForScript(
int script)
const;
178 QFontEngine *engineForCharacter(
char32_t c, EngineQueryOptions opt = {})
const;
179 void alterCharForCapitalization(QChar &c)
const;
183 mutable QFontEngineData *engineData;
191 bool letterSpacingIsAbsolute : 1;
193 QFixed letterSpacing;
195 QHash<QFont::Tag, quint32> features;
197 mutable QFontPrivate *scFont;
198 QFont smallCapsFont()
const {
return QFont(smallCapsFontPrivate()); }
199 QFontPrivate *smallCapsFontPrivate()
const;
201 static QFontPrivate *get(
const QFont &font)
203 return font.d.data();
206 void resolve(uint mask,
const QFontPrivate *other);
208 static void detachButKeepEngineData(QFont *font);
210 void setFeature(QFont::Tag tag, quint32 value);
211 void unsetFeature(QFont::Tag tag);
213 void setVariableAxis(QFont::Tag tag,
float value);
214 void unsetVariableAxis(QFont::Tag tag);
215 bool hasVariableAxis(QFont::Tag tag,
float value)
const;
217Q_DECLARE_OPERATORS_FOR_FLAGS(QFontPrivate::EngineQueryOptions)
220class Q_GUI_EXPORT QFontCache :
public QObject
224 static QFontCache *instance();
225 static void cleanup();
230 int id()
const {
return m_id; }
235 Key() : script(0), multi(0) { }
236 Key(
const QFontDef &d, uchar c,
bool m = 0)
237 : def(d), script(c), multi(m) { }
243 inline bool operator<(
const Key &other)
const
245 if (script != other.script)
return script < other.script;
246 if (multi != other.multi)
return multi < other.multi;
247 if (multi && def.fallBackFamilies.size() != other.def.fallBackFamilies.size())
248 return def.fallBackFamilies.size() < other.def.fallBackFamilies.size();
249 return def < other.def;
251 inline bool operator==(
const Key &other)
const
253 return script == other.script
254 && multi == other.multi
255 && (!multi || def.fallBackFamilies == other.def.fallBackFamilies)
261 typedef QMap<QFontDef, QFontEngineData*> EngineDataCache;
262 EngineDataCache engineDataCache;
264 QFontEngineData *findEngineData(
const QFontDef &def)
const;
265 void insertEngineData(
const QFontDef &def, QFontEngineData *engineData);
269 Engine() : data(
nullptr), timestamp(0), hits(0) { }
270 Engine(QFontEngine *d) : data(d), timestamp(0), hits(0) { }
277 typedef QMultiMap<Key,Engine> EngineCache;
278 EngineCache engineCache;
279 QHash<QFontEngine *,
int> engineCacheCount;
281 QFontEngine *findEngine(
const Key &key);
283 void updateHitCountAndTimeStamp(Engine &value);
284 void insertEngine(
const Key &key, QFontEngine *engine,
bool insertMulti =
false);
287 void increaseCost(uint cost);
288 void decreaseCost(uint cost);
289 void timerEvent(QTimerEvent *event) override;
290 void decreaseCache();
292 static const uint min_cost;
293 uint total_cost, max_cost;
294 uint current_timestamp;
296 const bool autoClean;
\threadsafe \inmodule QtGui
QFontEngine * engines[QFontDatabasePrivate::ScriptCount]
Combined button and popup list for selecting options.
QDataStream & operator>>(QDataStream &s, QKeyCombination &combination)
Q_GUI_EXPORT int qt_openTypeToLegacyWeight(int weight)
static void set_font_bits(int version, quint8 bits, QFontPrivate *f)
QRecursiveMutex * qt_fontdatabase_mutex()
static int convertWeights(int weight, bool inverted)
static QStringList splitIntoFamilies(const QString &family)
Q_GUI_EXPORT int qt_legacyToOpenTypeWeight(int weight)
static constexpr auto fast_timeout
QHash< QString, QStringList > QFontSubst
#define QFONT_DEBUG_SKIP_DEFAULT(prop)
#define QFONTCACHE_MIN_COST
#define QT_FONT_ENGINE_FROM_DATA(data, script)
Q_GUI_EXPORT int qt_defaultDpiY()
static constexpr auto slow_timeout
Q_GUI_EXPORT int qt_defaultDpiX()
static quint8 get_extended_font_bits(const QFontPrivate *f)
Q_GUI_EXPORT int qt_defaultDpi()
#define QFONTCACHE_DECREASE_TRIGGER_LIMIT
QStringList qt_fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QFontDatabasePrivate::ExtendedScript script)
static quint8 get_font_bits(int version, const QFontPrivate *f)
static void set_extended_font_bits(quint8 bits, QFontPrivate *f)
size_t qHash(const QFontDef &fd, size_t seed=0) noexcept
Q_CONSTINIT Q_GUI_EXPORT bool qt_is_tty_app
Q_GLOBAL_STATIC(QReadWriteLock, g_updateMutex)
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept
QStringList fallBackFamilies
bool operator<(const QFontDef &other) const
QMap< QFont::Tag, float > variableAxisValues
bool operator==(const QFontDef &other) const
bool exactMatch(const QFontDef &other) const