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
60 return families.value(0);
88 return pixelSize == other.pixelSize
89 && weight == other.weight
90 && style == other.style
91 && stretch == other.stretch
92 && styleHint == other.styleHint
93 && styleStrategy == other.styleStrategy
94 && ignorePitch == other.ignorePitch && fixedPitch == other.fixedPitch
95 && families == other.families
96 && styleName == other.styleName
97 && hintingPreference == other.hintingPreference
98 && variableAxisValues == other.variableAxisValues
103 if (pixelSize != other.pixelSize)
return pixelSize < other.pixelSize;
109 if (families != other.families)
return families < other.families;
110 if (styleName != other.styleName)
111 return styleName < other.styleName;
117 if (variableAxisValues != other.variableAxisValues) {
118 if (variableAxisValues.size() != other.variableAxisValues.size())
119 return variableAxisValues.size() < other.variableAxisValues.size();
122 auto it = variableAxisValues.constBegin();
123 auto jt = other.variableAxisValues.constBegin();
124 for (; it != variableAxisValues.constEnd(); ++it, ++jt) {
125 if (it.key() != jt.key())
126 return jt.key() < it.key();
127 if (it.value() != jt.value())
128 return jt.value() < it.value();
139 return qHashMulti(seed,
140 qRound64(fd.pixelSize*10000),
151 fd.variableAxisValues.keys(),
152 fd.variableAxisValues.values());
173 enum class EngineQueryOption {
175 IgnoreSmallCapsEngine = 0x1,
177 Q_DECLARE_FLAGS(EngineQueryOptions, EngineQueryOption)
180 QFontPrivate(
const QFontPrivate &other);
181 QFontPrivate &operator=(
const QFontPrivate &) =
delete;
184 QFontEngine *engineForScript(
int script)
const;
185 QFontEngine *engineForCharacter(
char32_t c, EngineQueryOptions opt = {})
const;
186 void alterCharForCapitalization(QChar &c)
const;
190 mutable QFontEngineData *engineData;
198 bool letterSpacingIsAbsolute : 1;
200 QFixed letterSpacing;
202 QMap<QFont::Tag, quint32> features;
204 mutable QFontPrivate *scFont;
205 QFont smallCapsFont()
const {
return QFont(smallCapsFontPrivate()); }
206 QFontPrivate *smallCapsFontPrivate()
const;
208 static QFontPrivate *get(
const QFont &font)
210 return font.d.data();
213 void resolve(uint mask,
const QFontPrivate *other);
215 static void detachButKeepEngineData(QFont *font);
217 void setFeature(QFont::Tag tag, quint32 value);
218 void unsetFeature(QFont::Tag tag);
220 void setVariableAxis(QFont::Tag tag,
float value);
221 void unsetVariableAxis(QFont::Tag tag);
222 bool hasVariableAxis(QFont::Tag tag,
float value)
const;
224Q_DECLARE_OPERATORS_FOR_FLAGS(QFontPrivate::EngineQueryOptions)
227class Q_GUI_EXPORT QFontCache :
public QObject
231 static QFontCache *instance();
232 static void cleanup();
237 int id()
const {
return m_id; }
242 Key() : script(0), multi(0) { }
243 Key(
const QFontDef &d, uchar c,
bool m = 0)
244 : def(d), script(c), multi(m) { }
250 inline bool operator<(
const Key &other)
const
252 if (script != other.script)
return script < other.script;
253 if (multi != other.multi)
return multi < other.multi;
254 if (multi && def.fallBackFamilies.size() != other.def.fallBackFamilies.size())
255 return def.fallBackFamilies.size() < other.def.fallBackFamilies.size();
256 return def < other.def;
258 inline bool operator==(
const Key &other)
const
260 return script == other.script
261 && multi == other.multi
262 && (!multi || def.fallBackFamilies == other.def.fallBackFamilies)
268 typedef QMap<QFontDef, QFontEngineData*> EngineDataCache;
269 EngineDataCache engineDataCache;
271 QFontEngineData *findEngineData(
const QFontDef &def)
const;
272 void insertEngineData(
const QFontDef &def, QFontEngineData *engineData);
276 Engine() : data(
nullptr), timestamp(0), hits(0) { }
277 Engine(QFontEngine *d) : data(d), timestamp(0), hits(0) { }
284 typedef QMultiMap<Key,Engine> EngineCache;
285 EngineCache engineCache;
286 QHash<QFontEngine *,
int> engineCacheCount;
288 QFontEngine *findEngine(
const Key &key);
290 void updateHitCountAndTimeStamp(Engine &value);
291 void insertEngine(
const Key &key, QFontEngine *engine,
bool insertMulti =
false);
294 void increaseCost(uint cost);
295 void decreaseCost(uint cost);
296 void timerEvent(QTimerEvent *event) override;
297 void decreaseCache();
299 static const uint min_cost;
300 uint total_cost, max_cost;
301 uint current_timestamp;
303 const bool autoClean;
308Q_GUI_EXPORT QPoint qt_defaultDpis();
\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
static std::optional< std::pair< QFont::Tag, quint32 > > fontFeatureFromString(QStringView view)
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 std::optional< std::pair< QFont::Tag, float > > variableAxisFromString(QStringView view)
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