57 #include <private/qfontengine_p.h>
58 #include <private/qpainter_p.h>
59 #include <private/qtextengine_p.h>
62 #include <qpa/qplatformscreen.h>
63 #include <qpa/qplatformintegration.h>
64 #include <qpa/qplatformfontdatabase.h>
65 #include <QtGui/private/qguiapplication_p.h>
67 #include <QtCore/QMutexLocker>
68 #include <QtCore/QMutex>
71 #ifdef QFONTCACHE_DEBUG
72 # define FC_DEBUG qDebug
74 # define FC_DEBUG if (false) qDebug
79 #ifndef QFONTCACHE_DECREASE_TRIGGER_LIMIT
80 # define QFONTCACHE_DECREASE_TRIGGER_LIMIT 256
119 QString this_family, this_foundry, other_family, other_foundry;
123 if (this_family != other_family || this_foundry != other_foundry)
131 && this_family == other_family
135 || this_foundry == other_foundry)
177 static int convertWeights(
int weight,
bool inverted)
185 int closestDist = INT_MAX;
189 for (
auto mapping : legacyToOpenTypeMap) {
193 if (
dist < closestDist) {
212 const int numFamilies =
list.size();
213 familyList.reserve(numFamilies);
214 for (
int i = 0;
i < numFamilies; ++
i) {
220 familyList <<
str.toString();
228 return convertWeights(
weight,
false);
234 return convertWeights(
weight,
true);
240 capital(0), letterSpacingIsAbsolute(
false), scFont(
nullptr)
246 underline(
other.underline), overline(
other.overline),
248 capital(
other.capital), letterSpacingIsAbsolute(
other.letterSpacingIsAbsolute),
249 letterSpacing(
other.letterSpacing), wordSpacing(
other.wordSpacing),
270 #define QT_FONT_ENGINE_FROM_DATA(data, script) data->engines[script]
626 : resolve_mask(
font.resolve_mask)
642 :
d(
data), resolve_mask(
QFont::AllPropertiesResolved)
803 resolve_mask =
font.resolve_mask;
848 qWarning(
"From Qt 6.2, QFont::setFamily() will no long split the family string on the comma"
849 " and will keep it as a single family");
1009 qWarning(
"QFont::setPointSize: Point size <= 0 (%d), must be greater than 0",
pointSize);
1034 qWarning(
"QFont::setPointSizeF: Point size <= 0 (%f), must be greater than 0",
pointSize);
1177 #if QT_DEPRECATED_SINCE(6, 0)
1193 void QFont::setLegacyWeight(
int legacyWeight)
1211 int QFont::legacyWeight()
const
1228 if (weightValue !=
static_cast<int>(
weight)) {
1229 qWarning() <<
"QFont::setWeight: Weight must be between 1 and 1000, attempted to set "
1230 <<
static_cast<int>(
weight);
1602 if (factor < 0 || factor > 4000) {
1603 qWarning(
"QFont::setStretch: Parameter '%d' out of range",
factor);
1812 if (
f.d == d)
return false;
1816 if (
r1.pointSize !=
r2.pointSize)
return r1.pointSize <
r2.pointSize;
1817 if (
r1.pixelSize !=
r2.pixelSize)
return r1.pixelSize <
r2.pixelSize;
1818 if (
r1.weight !=
r2.weight)
return r1.weight <
r2.weight;
1819 if (
r1.style !=
r2.style)
return r1.style <
r2.style;
1820 if (
r1.stretch !=
r2.stretch)
return r1.stretch <
r2.stretch;
1821 if (
r1.styleHint !=
r2.styleHint)
return r1.styleHint <
r2.styleHint;
1822 if (
r1.styleStrategy !=
r2.styleStrategy)
return r1.styleStrategy <
r2.styleStrategy;
1823 if (
r1.families !=
r2.families)
return r1.families <
r2.families;
1830 int f1attrs = (
f.d->underline << 3) + (
f.d->overline << 2) + (
f.d->strikeOut<<1) +
f.d->kerning;
1832 return f1attrs < f2attrs;
1876 if (resolve_mask == 0 || (resolve_mask ==
other.resolve_mask && *
this ==
other)) {
1878 o.resolve_mask = resolve_mask;
1923 if (
it != fontSubst->
constEnd() && !(*it).isEmpty())
1924 return (*it).first();
1957 const QString &substituteName)
1963 if (!
list.contains(
s))
1984 for (
const QString &substituteName : substituteNames) {
1986 if (!
list.contains(lowerSubstituteName))
1987 list.append(lowerSubstituteName);
2019 #ifndef QT_NO_DATASTREAM
2028 if (
f->request.style)
2036 if (
f->request.fixedPitch)
2053 if (
f->request.ignorePitch)
2055 if (
f->letterSpacingIsAbsolute)
2068 f->underline = (
bits & 0x02) != 0;
2069 f->overline = (
bits & 0x40) != 0;
2070 f->strikeOut = (
bits & 0x04) != 0;
2071 f->request.fixedPitch = (
bits & 0x08) != 0;
2074 f->kerning = (
bits & 0x10) != 0;
2075 if ((
bits & 0x80) != 0)
2082 f->request.ignorePitch = (
bits & 0x01) != 0;
2083 f->letterSpacingIsAbsolute = (
bits & 0x02) != 0;
2148 return fontDescription;
2175 const int count =
l.count();
2177 l.first().isEmpty()) {
2178 qWarning(
"QFont::fromString: Invalid description '%s'",
2193 }
else if (
count >= 10) {
2194 if (
l[2].toInt() > 0)
2269 if (!fallbacks.isEmpty())
2270 return fallbacks.first();
2319 #ifndef QT_NO_DATASTREAM
2331 if (
s.version() == 1) {
2345 }
else if (
s.version() <= 3) {
2347 if (pointSize < 0) {
2371 s << get_font_bits(
s.version(),
font.d.
data());
2375 s << get_extended_font_bits(
font.d.
data());
2410 if (
s.version() == 1) {
2431 qint16 pointSize, pixelSize = -1;
2433 if (
s.version() >= 4)
2443 quint8 tempStyleStrategy;
2444 s >> tempStyleStrategy;
2445 styleStrategy = tempStyleStrategy;
2477 set_extended_font_bits(extendedBits,
font.d.
data());
2699 #if QT_DEPRECATED_SINCE(6, 0)
2713 int QFontInfo::legacyWeight()
const
2843 #ifdef QFONTCACHE_DEBUG
2845 static const int fast_timeout = 1000;
2846 static const int slow_timeout = 5000;
2848 static const int fast_timeout = 10000;
2849 static const int slow_timeout = 300000;
2852 #ifndef QFONTCACHE_MIN_COST
2853 # define QFONTCACHE_MIN_COST 4*1024
2860 QFontCache *&fontCache = theFontCache()->localData();
2870 cache = theFontCache();
2871 } QT_CATCH (
const std::bad_alloc &) {
2875 cache->setLocalData(
nullptr);
2881 :
QObject(), total_cost(0), max_cost(min_cost),
2882 current_timestamp(0), fast(
false),
2886 m_id(font_cache_id.fetchAndAddRelaxed(1) + 1)
2903 if (
data->engines[
i]) {
2904 if (!
data->engines[
i]->ref.deref()) {
2906 delete data->engines[
i];
2908 data->engines[
i] =
nullptr;
2911 if (!
data->ref.deref()) {
2914 FC_DEBUG(
"QFontCache::clear: engineData %p still has refcount %d",
2924 bool mightHaveEnginesLeftForCleanup;
2926 mightHaveEnginesLeftForCleanup =
false;
2937 }
else if (cacheCount == 0) {
2938 FC_DEBUG(
"QFontCache::clear: engine %p still has refcount %d",
2941 it.value().data =
nullptr;
2944 }
while (mightHaveEnginesLeftForCleanup);
2951 max_cost = min_cost;
2967 #ifdef QFONTCACHE_DEBUG
2968 FC_DEBUG(
"QFontCache: inserting new engine data %p", engineData);
2970 FC_DEBUG(
" QFontCache already contains engine data %p for key=(%g %g %d %d %d)",
2990 if (
it ==
end)
return nullptr;
2998 return it.value().data;
3004 value.timestamp = ++current_timestamp;
3006 FC_DEBUG(
"QFontCache: found font engine\n"
3007 " %p: timestamp %4u hits %3u ref %2d/%2d, type %d",
3010 value.data->type());
3018 #ifdef QFONTCACHE_DEBUG
3021 FC_DEBUG(
" QFontCache already contains engine %p for key=(%g %g %d %d %d)",
3023 key.def.pixelSize,
key.def.weight,
key.def.style,
key.def.fixedPitch);
3032 data.timestamp = ++current_timestamp;
3043 void QFontCache::increaseCost(
uint cost)
3045 cost = (cost + 512) / 1024;
3046 cost = cost > 0 ? cost : 1;
3049 FC_DEBUG(
" COST: increased %u kb, total_cost %u kb, max_cost %u kb",
3050 cost, total_cost, max_cost);
3052 if (total_cost > max_cost) {
3053 max_cost = total_cost;
3058 if (timer_id == -1 || ! fast) {
3059 FC_DEBUG(
" TIMER: starting fast timer (%d ms)", fast_timeout);
3069 void QFontCache::decreaseCost(
uint cost)
3071 cost = (cost + 512) / 1024;
3072 cost = cost > 0 ? cost : 1;
3076 FC_DEBUG(
" COST: decreased %u kb, total_cost %u kb, max_cost %u kb",
3077 cost, total_cost, max_cost);
3082 FC_DEBUG(
"QFontCache::timerEvent: performing cache maintenance (timestamp %u)",
3085 if (total_cost <= max_cost && max_cost <= min_cost) {
3086 FC_DEBUG(
" cache redused sufficiently, stopping timer");
3097 void QFontCache::decreaseCache()
3100 uint in_use_cost = 0;
3106 const uint engine_data_cost =
3112 FC_DEBUG(
" %p: ref %2d",
it.value(),
int(
it.value()->ref.loadRelaxed()));
3114 if (
it.value()->ref.loadRelaxed() != 1)
3115 in_use_cost += engine_data_cost;
3125 FC_DEBUG(
" %p: timestamp %4u hits %2u ref %2d/%2d, cost %u bytes",
3126 it.value().data,
it.value().timestamp,
it.value().hits,
3128 it.value().data->cache_cost);
3138 in_use_cost = (in_use_cost + 512) / 1024;
3148 uint new_max_cost = qMax(qMax(max_cost / 2, in_use_cost), min_cost);
3150 FC_DEBUG(
" after sweep, in use %u kb, total %u kb, max %u kb, new max %u kb",
3151 in_use_cost, total_cost, max_cost, new_max_cost);
3154 if (new_max_cost == max_cost) {
3156 FC_DEBUG(
" cannot shrink cache, slowing timer");
3158 if (timer_id != -1) {
3165 }
else if (! fast) {
3166 FC_DEBUG(
" dropping into passing gear");
3175 max_cost = new_max_cost;
3183 if (
it.value()->ref.loadRelaxed() == 1) {
3186 it.value()->ref.deref();
3198 bool cost_decreased;
3200 cost_decreased =
false;
3206 uint least_popular = ~0
u;
3214 if (
it.value().timestamp < oldest &&
it.value().hits <= least_popular) {
3215 oldest =
it.value().timestamp;
3216 least_popular =
it.value().hits;
3223 FC_DEBUG(
" %p: timestamp %4u hits %2u ref %2d/%2d, type %d",
3224 it.value().data,
it.value().timestamp,
it.value().hits,
3226 it.value().data->type());
3232 if (
it.value().data == fontEngine) {
3245 cost_decreased =
true;
3247 }
while (cost_decreased && total_cost > max_cost);
3251 #ifndef QT_NO_DEBUG_STREAM
3255 stream.nospace().noquote();
3270 const bool resolved = (
font.resolve_mask &
property) != 0;
3274 #define QFONT_DEBUG_SKIP_DEFAULT(prop) \
3275 if ((font.prop() == defaultFont.prop()) && stream.verbosity() == 1) \
3336 #undef QFONT_DEBUG_SKIP_DEFAULT
3344 fontDescription.
chop(2);
3346 stream << fontDescription <<
')';
3354 #include "moc_qfont.cpp"
small capitals from c petite p scientific f u
small capitals from c petite p scientific i
[1]
xD9 x84 xD8 xAD xD9 x80 xF0 x90 xAC x9A xE0 xA7 xA6 xE0 xA7 xAA xF0 x91 x84 xA4 xF0 x91 x84 x89 xF0 x91 x84 x9B xF0 x90 x8A xAB xF0 x90 x8B x89 xE2 xB2 x9E xE2 xB2 x9F xD0 xBE xD0 x9E xF0 x90 x90 x84 xF0 x90 x90 xAC xE1 x83 x98 xE1 x83 x94 xE1 x83 x90 xE1 xB2 xBF xE2 xB0 x95 xE2 xB1 x85 xCE xBF xCE x9F xE0 xA8 xA0 xE0 xA8 xB0 xE0 xA9 xA6 Kayah xEA xA4 x8D xEA xA4 x80 Khmer xE1 xA7 xA1 xE1 xA7 xAA xE0 xBB x90 Latin Subscript xE2 x82 x92 xE2 x82 x80 xEA x93 xB3 xF0 x96 xB9 xA1 xF0 x96 xB9 x9B xF0 x96 xB9 xAF xE1 x80 x9D xE1 x80 x84 xE1 x80 x82 no script
T loadRelaxed() const noexcept
The QByteArray class provides an array of bytes.
The QChar class provides a 16-bit Unicode character.
static QCoreApplication * instance()
The QDataStream class provides serialization of binary data to a QIODevice.
operator>>(QDataStream &ds, qfloat16 &f)
operator<<(QDataStream &ds, qfloat16 f)
The QDebug class provides an output stream for debugging information.
Convenience class for custom QDebug operators.
T * data() const noexcept
The QFlags class provides a type-safe way of storing OR-combinations of enum values.
template< typename Enum > size_t qHash(QFlags< Enum > flags, size_t seed=0) noexcept
void insertEngineData(const QFontDef &def, QFontEngineData *engineData)
EngineDataCache engineDataCache
QFontEngine * findEngine(const Key &key)
QFontEngineData * findEngineData(const QFontDef &def) const
static QFontCache * instance()
void updateHitCountAndTimeStamp(Engine &value)
void insertEngine(const Key &key, QFontEngine *engine, bool insertMulti=false)
QHash< QFontEngine *, int > engineCacheCount
static void parseFontName(const QString &name, QString &foundry, QString &family)
static void load(const QFontPrivate *d, int script)
QFontEngine * engines[QChar::ScriptCount]
virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, ShaperFlags flags) const =0
The QFont class specifies a query for a font used for drawing text.
static QStringList substitutes(const QString &)
void setStyle(Style style)
StyleStrategy styleStrategy() const
static void cacheStatistics()
QString styleName() const
bool isCopyOf(const QFont &) const
friend class QFontPrivate
StyleHint styleHint() const
bool fromString(const QString &)
size_t qHash(const QFont &font, size_t seed) noexcept
void setFamilies(const QStringList &)
bool operator!=(const QFont &) const
void setCapitalization(Capitalization)
qreal letterSpacing() const
void setWordSpacing(qreal spacing)
void setFamily(const QString &)
void setStyleStrategy(StyleStrategy s)
QFont resolve(const QFont &) const
static void insertSubstitution(const QString &, const QString &)
HintingPreference hintingPreference() const
bool operator<(const QFont &) const
Capitalization capitalization() const
static void removeSubstitutions(const QString &)
QStringList families() const
@ HintingPreferenceResolved
void setLetterSpacing(SpacingType type, qreal spacing)
qreal wordSpacing() const
static QStringList substitutions()
QString defaultFamily() const
bool operator==(const QFont &) const
void setHintingPreference(HintingPreference hintingPreference)
void setStyleHint(StyleHint, StyleStrategy=PreferDefault)
QFont & operator=(const QFont &)
void setStyleName(const QString &)
SpacingType letterSpacingType() const
void setPointSizeF(qreal)
void setWeight(Weight weight)
static void insertSubstitutions(const QString &, const QStringList &)
The QFontInfo class provides general information about fonts. \inmodule QtGui.
QFontInfo & operator=(const QFontInfo &)
QString styleName() const
QFont::StyleHint styleHint() const
QFont::Style style() const
bool letterSpacingIsAbsolute
QFontPrivate * smallCapsFontPrivate() const
static QFontPrivate * get(const QFont &font)
QFontEngine * engineForScript(int script) const
void resolve(uint mask, const QFontPrivate *other)
QFontEngineData * engineData
void alterCharForCapitalization(QChar &c) const
static void detachButKeepEngineData(QFont *font)
The QGuiApplication class manages the GUI application's control flow and main settings.
QScreen * primaryScreen
the primary (or default) screen of the application.
bool remove(const Key &key)
const_iterator constFind(const Key &key) const noexcept
const_iterator constEnd() const noexcept
QList< Key > keys() const
T value(const Key &key) const noexcept
const_iterator ConstIterator
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
iterator insert(const Key &key, const T &value)
T value(const Key &key, const T &defaultValue=T()) const
iterator erase(const_iterator it)
bool contains(const Key &key) const
const_iterator constFind(const Key &key) const
const_iterator ConstIterator
const_iterator constBegin() const
const_iterator constEnd() const
iterator replace(const Key &key, const T &value)
const_iterator constEnd() const
bool contains(const Key &key) const
const_iterator ConstIterator
iterator find(const Key &key)
iterator insert(const Key &key, const T &value)
iterator erase(const_iterator it)
const_iterator constBegin() const
T value(const Key &key, const T &defaultValue=T()) const
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes.
The QObject class is the base class of all Qt objects.
int startTimer(int interval, Qt::TimerType timerType=Qt::CoarseTimer)
The QRecursiveMutex class provides access serialization between threads.
The QScreen class is used to query screen properties. \inmodule QtGui.
qreal logicalDotsPerInchY
the number of logical dots or pixels per inch in the vertical direction
qreal logicalDotsPerInchX
the number of logical dots or pixels per inch in the horizontal direction
The QString class provides a Unicode character string.
QByteArray toLatin1() const &
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static QString fromLatin1(QByteArrayView ba)
QStringList split(const QString &sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QString mid(qsizetype position, qsizetype n=-1) const
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QString toLower() const &
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static QString number(int, int base=10)
The QStringList class provides a list of strings.
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QStrin...
QStringView trimmed() const noexcept
The QThreadStorage class provides per-thread data storage.
The QTimerEvent class contains parameters that describe a timer event.
The QVariant class acts like a union for the most common Qt data types.
static auto fromValue(const T &value) -> std::enable_if_t< std::is_copy_constructible_v< T >, QVariant >
QCache< int, Employee > cache
[0]
auto it unsigned count const
Q_WIDGETS_EXPORT qreal dpi(const QStyleOption *option)
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION ParsedNumber< double > toDouble(QByteArrayView a) noexcept
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
[3]
#define Q_BASIC_ATOMIC_INITIALIZER(a)
QList< QString > QStringList
EGLOutputLayerEXT EGLint EGLAttrib value
int qRound(qfloat16 d) noexcept
Q_GUI_EXPORT int qt_openTypeToLegacyWeight(int weight)
QRecursiveMutex * qt_fontdatabase_mutex()
Q_GUI_EXPORT int qt_defaultDpiX()
Q_GUI_EXPORT int qt_legacyToOpenTypeWeight(int weight)
Q_GUI_EXPORT int qt_defaultDpi()
QStringList qt_fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script)
#define QFONT_DEBUG_SKIP_DEFAULT(prop)
#define QFONTCACHE_MIN_COST
#define QT_FONT_ENGINE_FROM_DATA(data, script)
Q_GUI_EXPORT int qt_defaultDpiY()
#define QFONTCACHE_DECREASE_TRIGGER_LIMIT
QHash< QString, QStringList > QFontSubst
QT_END_INCLUDE_NAMESPACE typedef double qreal
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
GLenum GLenum GLsizei count
GLuint GLuint GLfloat weight
GLenum const void GLbitfield fontStyle
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
GLenum GLenum GLenum GLenum mapping
std::uniform_real_distribution dist(1, 2.5)
[2]
QFileInfo fi("c:/temp/foo")
[newstuff]
QNetworkRequest request(url)
constexpr int value() const
constexpr static QFixed fromReal(qreal r)
constexpr qreal toReal() const
bool exactMatch(const QFontDef &other) const
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
FT_UInt FT_UInt FT_Vector * kerning