QtBase  v6.3.1
qfont_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QFONT_P_H
41 #define QFONT_P_H
42 
43 //
44 // W A R N I N G
45 // -------------
46 //
47 // This file is not part of the Qt API. It exists for the convenience
48 // of internal files. This header file may change from version to version
49 // without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include <QtGui/private/qtguiglobal_p.h>
55 #include "QtGui/qfont.h"
56 #include "QtCore/qmap.h"
57 #include "QtCore/qhash.h"
58 #include "QtCore/qobject.h"
59 #include "QtCore/qstringlist.h"
60 #include <QtGui/qfontdatabase.h>
61 #include "private/qfixed_p.h"
62 
64 
65 // forwards
66 class QFontCache;
67 class QFontEngine;
68 
69 #define QFONT_WEIGHT_MIN 1
70 #define QFONT_WEIGHT_MAX 1000
71 
72 struct QFontDef
73 {
74  inline QFontDef()
75  : pointSize(-1.0),
76  pixelSize(-1),
77  styleStrategy(QFont::PreferDefault),
78  stretch(QFont::AnyStretch),
79  style(QFont::StyleNormal),
80  hintingPreference(QFont::PreferDefaultHinting),
81  styleHint(QFont::AnyStyle),
82  weight(QFont::Normal),
86  reserved(0)
87  {
88  }
89 
92 
94 
97 
98  // Note: Variable ordering matters to make sure no variable overlaps two 32-bit registers.
100  uint stretch : 12; // 0-4000
101  uint style : 2;
103 
105  uint weight : 10; // 1-1000
108  uint fixedPitchComputed : 1; // for Mac OS X only
109  uint reserved : 11; // for future extensions
110 
111  bool exactMatch(const QFontDef &other) const;
112  bool operator==(const QFontDef &other) const
113  {
114  return pixelSize == other.pixelSize
115  && weight == other.weight
116  && style == other.style
117  && stretch == other.stretch
118  && styleHint == other.styleHint
119  && styleStrategy == other.styleStrategy
120  && ignorePitch == other.ignorePitch && fixedPitch == other.fixedPitch
121  && families == other.families
122  && styleName == other.styleName
123  && hintingPreference == other.hintingPreference
124  ;
125  }
126  inline bool operator<(const QFontDef &other) const
127  {
128  if (pixelSize != other.pixelSize) return pixelSize < other.pixelSize;
129  if (weight != other.weight) return weight < other.weight;
130  if (style != other.style) return style < other.style;
131  if (stretch != other.stretch) return stretch < other.stretch;
132  if (styleHint != other.styleHint) return styleHint < other.styleHint;
133  if (styleStrategy != other.styleStrategy) return styleStrategy < other.styleStrategy;
134  if (families != other.families) return families < other.families;
135  if (styleName != other.styleName)
136  return styleName < other.styleName;
137  if (hintingPreference != other.hintingPreference) return hintingPreference < other.hintingPreference;
138 
139 
140  if (ignorePitch != other.ignorePitch) return ignorePitch < other.ignorePitch;
141  if (fixedPitch != other.fixedPitch) return fixedPitch < other.fixedPitch;
142  return false;
143  }
144 };
145 
146 inline size_t qHash(const QFontDef &fd, size_t seed = 0) noexcept
147 {
148  return qHashMulti(seed,
149  qRound64(fd.pixelSize*10000), // use only 4 fractional digits
150  fd.weight,
151  fd.style,
152  fd.stretch,
153  fd.styleHint,
154  fd.styleStrategy,
155  fd.ignorePitch,
156  fd.fixedPitch,
157  fd.families,
158  fd.styleName,
159  fd.hintingPreference);
160 }
161 
163 {
164 public:
165  QFontEngineData();
167 
169  const int fontCacheId;
170 
172 
173 private:
175 };
176 
177 
178 class Q_GUI_EXPORT QFontPrivate
179 {
180 public:
181 
182  QFontPrivate();
184  ~QFontPrivate();
185 
186  QFontEngine *engineForScript(int script) const;
187  void alterCharForCapitalization(QChar &c) const;
188 
192  int dpi;
193 
200 
203 
205  QFont smallCapsFont() const { return QFont(smallCapsFontPrivate()); }
206  QFontPrivate *smallCapsFontPrivate() const;
207 
208  static QFontPrivate *get(const QFont &font)
209  {
210  return font.d.data();
211  }
212 
213  void resolve(uint mask, const QFontPrivate *other);
214 
215  static void detachButKeepEngineData(QFont *font);
216 
217 private:
218  QFontPrivate &operator=(const QFontPrivate &) { return *this; }
219 };
220 
221 
222 class Q_GUI_EXPORT QFontCache : public QObject
223 {
224 public:
225  // note: these static functions work on a per-thread basis
226  static QFontCache *instance();
227  static void cleanup();
228 
229  QFontCache();
230  ~QFontCache();
231 
232  int id() const { return m_id; }
233 
234  void clear();
235 
236  struct Key {
237  Key() : script(0), multi(0) { }
238  Key(const QFontDef &d, uchar c, bool m = 0)
239  : def(d), script(c), multi(m) { }
240 
244 
245  inline bool operator<(const Key &other) const
246  {
247  if (script != other.script) return script < other.script;
248  if (multi != other.multi) return multi < other.multi;
249  if (multi && def.fallBackFamilies.size() != other.def.fallBackFamilies.size())
250  return def.fallBackFamilies.size() < other.def.fallBackFamilies.size();
251  return def < other.def;
252  }
253  inline bool operator==(const Key &other) const
254  {
255  return script == other.script
256  && multi == other.multi
257  && (!multi || def.fallBackFamilies == other.def.fallBackFamilies)
258  && def == other.def;
259  }
260  };
261 
262  // QFontEngineData cache
265 
266  QFontEngineData *findEngineData(const QFontDef &def) const;
267  void insertEngineData(const QFontDef &def, QFontEngineData *engineData);
268 
269  // QFontEngine cache
270  struct Engine {
271  Engine() : data(nullptr), timestamp(0), hits(0) { }
272  Engine(QFontEngine *d) : data(d), timestamp(0), hits(0) { }
273 
277  };
278 
282 
283  QFontEngine *findEngine(const Key &key);
284 
285  void updateHitCountAndTimeStamp(Engine &value);
286  void insertEngine(const Key &key, QFontEngine *engine, bool insertMulti = false);
287 
288 private:
289  void increaseCost(uint cost);
290  void decreaseCost(uint cost);
291  void timerEvent(QTimerEvent *event) override;
292  void decreaseCache();
293 
294  static const uint min_cost;
295  uint total_cost, max_cost;
296  uint current_timestamp;
297  bool fast;
298  const bool autoClean;
299  int timer_id;
300  const int m_id;
301 };
302 
303 Q_GUI_EXPORT int qt_defaultDpiX();
304 Q_GUI_EXPORT int qt_defaultDpiY();
305 Q_GUI_EXPORT int qt_defaultDpi();
306 
307 Q_GUI_EXPORT int qt_legacyToOpenTypeWeight(int weight);
308 Q_GUI_EXPORT int qt_openTypeToLegacyWeight(int weight);
309 
311 
312 #endif // QFONT_P_H
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
Definition: afscript.h:271
The QAtomicInt class provides platform-independent atomic operations on int.
Definition: qatomic.h:158
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:84
@ ScriptCount
Definition: qchar.h:373
T * data() const noexcept
Definition: qshareddata.h:171
template< typename Enum > size_t qHash(QFlags< Enum > flags, size_t seed=0) noexcept
EngineDataCache engineDataCache
Definition: qfont_p.h:264
QMultiMap< Key, Engine > EngineCache
Definition: qfont_p.h:279
EngineCache engineCache
Definition: qfont_p.h:280
QMap< QFontDef, QFontEngineData * > EngineDataCache
Definition: qfont_p.h:263
int id() const
Definition: qfont_p.h:232
QHash< QFontEngine *, int > engineCacheCount
Definition: qfont_p.h:281
QAtomicInt ref
Definition: qfont_p.h:168
QFontEngine * engines[QChar::ScriptCount]
Definition: qfont_p.h:171
const int fontCacheId
Definition: qfont_p.h:169
The QFont class specifies a query for a font used for drawing text.
Definition: qfont.h:56
bool letterSpacingIsAbsolute
Definition: qfont_p.h:199
uint overline
Definition: qfont_p.h:195
uint strikeOut
Definition: qfont_p.h:196
QAtomicInt ref
Definition: qfont_p.h:189
QFontDef request
Definition: qfont_p.h:190
uint underline
Definition: qfont_p.h:194
static QFontPrivate * get(const QFont &font)
Definition: qfont_p.h:208
QFixed wordSpacing
Definition: qfont_p.h:202
uint kerning
Definition: qfont_p.h:197
QFixed letterSpacing
Definition: qfont_p.h:201
QFontEngineData * engineData
Definition: qfont_p.h:191
uint capital
Definition: qfont_p.h:198
QFont smallCapsFont() const
Definition: qfont_p.h:205
QFontPrivate * scFont
Definition: qfont_p.h:204
template< typename... T > size_t qHashMulti(size_t seed, const T &...args)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QStringList class provides a list of strings.
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:367
b clear()
#define true
Definition: ftrandom.c:51
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 &reg2 endm macro vzip8 reg2 vzip d d &reg2 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 cleanup[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld SRC pixld MASK if DST_R else pixld DST_R endif if src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head if pixblock_size cache_preload_simple endif process_pixblock_tail pixinterleave dst_w_basereg irp if pixblock_size chunk_size tst beq if DST_W else pixst DST_W else mov ORIG_W endif add lsl if lsl endif if lsl endif lsl endif lsl endif lsl endif subs mov DST_W if regs_shortage str endif bge start_of_loop_label endm macro generate_composite_function
EGLOutputLayerEXT EGLint EGLAttrib value
qint64 qRound64(qfloat16 d) noexcept
Definition: qfloat16.h:230
Q_GUI_EXPORT int qt_openTypeToLegacyWeight(int weight)
Definition: qfont.cpp:232
Q_GUI_EXPORT int qt_defaultDpiX()
Definition: qfont.cpp:141
Q_GUI_EXPORT int qt_legacyToOpenTypeWeight(int weight)
Definition: qfont.cpp:226
Q_GUI_EXPORT int qt_defaultDpi()
Definition: qfont.cpp:171
Q_GUI_EXPORT int qt_defaultDpiY()
Definition: qfont.cpp:156
#define Q_DISABLE_COPY_MOVE(Class)
Definition: qglobal.h:519
QT_BEGIN_INCLUDE_NAMESPACE typedef unsigned char uchar
Definition: qglobal.h:332
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
unsigned int uint
Definition: qglobal.h:334
const GLfloat * m
GLuint64 key
GLuint GLuint GLfloat weight
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint64 GLenum GLint fd
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
struct _cl_event * event
Definition: qopenglext.h:2998
const GLubyte * c
Definition: qopenglext.h:12701
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]
Engine(QFontEngine *d)
Definition: qfont_p.h:272
QFontEngine * data
Definition: qfont_p.h:274
QFontDef def
Definition: qfont_p.h:241
bool operator==(const Key &other) const
Definition: qfont_p.h:253
bool operator<(const Key &other) const
Definition: qfont_p.h:245
Key(const QFontDef &d, uchar c, bool m=0)
Definition: qfont_p.h:238
uchar script
Definition: qfont_p.h:242
uint hintingPreference
Definition: qfont_p.h:102
uint reserved
Definition: qfont_p.h:109
QFontDef()
Definition: qfont_p.h:74
uint stretch
Definition: qfont_p.h:100
uint style
Definition: qfont_p.h:101
uint styleStrategy
Definition: qfont_p.h:99
QStringList fallBackFamilies
Definition: qfont_p.h:93
uint fixedPitch
Definition: qfont_p.h:106
bool operator<(const QFontDef &other) const
Definition: qfont_p.h:126
qreal pixelSize
Definition: qfont_p.h:96
uint ignorePitch
Definition: qfont_p.h:107
bool operator==(const QFontDef &other) const
Definition: qfont_p.h:112
uint weight
Definition: qfont_p.h:105
QStringList families
Definition: qfont_p.h:90
QString styleName
Definition: qfont_p.h:91
uint fixedPitchComputed
Definition: qfont_p.h:108
bool exactMatch(const QFontDef &other) const
Definition: qfont.cpp:83
uint styleHint
Definition: qfont_p.h:104
qreal pointSize
Definition: qfont_p.h:95