Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
| ** | |
| ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). | |
| ** Contact: http://www.qt-project.org/legal | |
| ** | |
| ** This file is part of the QtGui module of the Qt Toolkit. | |
| ** | |
| ** $QT_BEGIN_LICENSE:LGPL$ | |
| ** Commercial License Usage | |
| ** Licensees holding valid commercial Qt licenses may use this file in | |
| ** accordance with the commercial license agreement provided with the | |
| ** Software or, alternatively, in accordance with the terms contained in | |
| ** a written agreement between you and Digia. For licensing terms and | |
| ** conditions see http://qt.digia.com/licensing. For further information | |
| ** use the contact form at http://qt.digia.com/contact-us. | |
| ** | |
| ** GNU Lesser General Public License Usage | |
| ** Alternatively, this file may be used under the terms of the GNU Lesser | |
| ** General Public License version 2.1 as published by the Free Software | |
| ** Foundation and appearing in the file LICENSE.LGPL included in the | |
| ** packaging of this file. Please review the following information to | |
| ** ensure the GNU Lesser General Public License version 2.1 requirements | |
| ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
| ** | |
| ** In addition, as a special exception, Digia gives you certain additional | |
| ** rights. These rights are described in the Digia Qt LGPL Exception | |
| ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
| ** | |
| ** GNU General Public License Usage | |
| ** Alternatively, this file may be used under the terms of the GNU | |
| ** General Public License version 3.0 as published by the Free Software | |
| ** Foundation and appearing in the file LICENSE.GPL included in the | |
| ** packaging of this file. Please review the following information to | |
| ** ensure the GNU General Public License version 3.0 requirements will be | |
| ** met: http://www.gnu.org/copyleft/gpl.html. | |
| ** | |
| ** | |
| ** $QT_END_LICENSE$ | |
| ** | |
| ****************************************************************************/**************************************************************************** | |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
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 Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include "qfont.h" | - |
43 | #include "qdebug.h" | - |
44 | #include "qpaintdevice.h" | - |
45 | #include "qfontdatabase.h" | - |
46 | #include "qfontmetrics.h" | - |
47 | #include "qfontinfo.h" | - |
48 | #include "qpainter.h" | - |
49 | #include "qhash.h" | - |
50 | #include "qdatastream.h" | - |
51 | #include "qguiapplication.h" | - |
52 | #include "qstringlist.h" | - |
53 | #include "qscreen.h" | - |
54 | | - |
55 | #include "qthread.h" | - |
56 | #include "qthreadstorage.h" | - |
57 | | - |
58 | #include <private/qunicodetables_p.h> | - |
59 | #include "qfont_p.h" | - |
60 | #include <private/qfontengine_p.h> | - |
61 | #include <private/qpainter_p.h> | - |
62 | #include <private/qtextengine_p.h> | - |
63 | #include <limits.h> | - |
64 | | - |
65 | #include <qpa/qplatformscreen.h> | - |
66 | #include <QtGui/private/qguiapplication_p.h> | - |
67 | | - |
68 | #include <QtCore/QMutexLocker> | - |
69 | #include <QtCore/QMutex> | - |
70 | | - |
71 | // #define QFONTCACHE_DEBUG | - |
72 | #ifdef QFONTCACHE_DEBUG | - |
73 | # define FC_DEBUG qDebug | - |
74 | #else | - |
75 | # define FC_DEBUG if (false) qDebug | - |
76 | #endif | - |
77 | | - |
78 | QT_BEGIN_NAMESPACE | - |
79 | | - |
80 | | - |
81 | | - |
82 | bool QFontDef::exactMatch(const QFontDef &other) const | - |
83 | { | - |
84 | /* | - |
85 | QFontDef comparison is more complicated than just simple | - |
86 | per-member comparisons. | - |
87 | | - |
88 | When comparing point/pixel sizes, either point or pixelsize | - |
89 | could be -1. in This case we have to compare the non negative | - |
90 | size value. | - |
91 | | - |
92 | This test will fail if the point-sizes differ by 1/2 point or | - |
93 | more or they do not round to the same value. We have to do this | - |
94 | since our API still uses 'int' point-sizes in the API, but store | - |
95 | deci-point-sizes internally. | - |
96 | | - |
97 | To compare the family members, we need to parse the font names | - |
98 | and compare the family/foundry strings separately. This allows | - |
99 | us to compare e.g. "Helvetica" and "Helvetica [Adobe]" with | - |
100 | positive results. | - |
101 | */ | - |
102 | if (pixelSize != -1 && other.pixelSize != -1) { | - |
103 | if (pixelSize != other.pixelSize) | - |
104 | return false; | - |
105 | } else if (pointSize != -1 && other.pointSize != -1) { | - |
106 | if (pointSize != other.pointSize) | - |
107 | return false; | - |
108 | } else { | - |
109 | return false; | - |
110 | } | - |
111 | | - |
112 | if (!ignorePitch && !other.ignorePitch && fixedPitch != other.fixedPitch) | - |
113 | return false; | - |
114 | | - |
115 | if (stretch != 0 && other.stretch != 0 && stretch != other.stretch) | - |
116 | return false; | - |
117 | | - |
118 | QString this_family, this_foundry, other_family, other_foundry; | - |
119 | QFontDatabase::parseFontName(family, this_foundry, this_family); | - |
120 | QFontDatabase::parseFontName(other.family, other_foundry, other_family); | - |
121 | | - |
122 | this_family = QFontDatabase::resolveFontFamilyAlias(this_family); | - |
123 | other_family = QFontDatabase::resolveFontFamilyAlias(other_family); | - |
124 | | - |
125 | return (styleHint == other.styleHint | - |
126 | && styleStrategy == other.styleStrategy | - |
127 | && weight == other.weight | - |
128 | && style == other.style | - |
129 | && this_family == other_family | - |
130 | && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName) | - |
131 | && (this_foundry.isEmpty() | - |
132 | || other_foundry.isEmpty() | - |
133 | || this_foundry == other_foundry) | - |
134 | ); | - |
135 | } | - |
136 | | - |
137 | extern bool qt_is_gui_used; | - |
138 | | - |
139 | Q_GUI_EXPORT int qt_defaultDpiX() | - |
140 | { | - |
141 | if (qApp->testAttribute(Qt::AA_Use96Dpi)) | - |
142 | return 96; | - |
143 | | - |
144 | if (!qt_is_gui_used) | - |
145 | return 75; | - |
146 | | - |
147 | if (const QScreen *screen = QGuiApplication::primaryScreen()) | - |
148 | return qRound(screen->logicalDotsPerInchX()); | - |
149 | | - |
150 | //PI has not been initialised, or it is being initialised. Give a default dpi | - |
151 | return 100; | - |
152 | } | - |
153 | | - |
154 | Q_GUI_EXPORT int qt_defaultDpiY() | - |
155 | { | - |
156 | if (qApp->testAttribute(Qt::AA_Use96Dpi)) | - |
157 | return 96; | - |
158 | | - |
159 | if (!qt_is_gui_used) | - |
160 | return 75; | - |
161 | | - |
162 | if (const QScreen *screen = QGuiApplication::primaryScreen()) | - |
163 | return qRound(screen->logicalDotsPerInchY()); | - |
164 | | - |
165 | //PI has not been initialised, or it is being initialised. Give a default dpi | - |
166 | return 100; | - |
167 | } | - |
168 | | - |
169 | Q_GUI_EXPORT int qt_defaultDpi() | - |
170 | { | - |
171 | return qt_defaultDpiY(); | - |
172 | } | - |
173 | | - |
174 | QFontPrivate::QFontPrivate() | - |
175 | : engineData(0), dpi(qt_defaultDpi()), screen(0), | - |
176 | rawMode(false), underline(false), overline(false), strikeOut(false), kerning(true), | - |
177 | capital(0), letterSpacingIsAbsolute(false), scFont(0) | - |
178 | { | - |
179 | } | - |
180 | | - |
181 | QFontPrivate::QFontPrivate(const QFontPrivate &other) | - |
182 | : request(other.request), engineData(0), dpi(other.dpi), screen(other.screen), | - |
183 | rawMode(other.rawMode), underline(other.underline), overline(other.overline), | - |
184 | strikeOut(other.strikeOut), kerning(other.kerning), | - |
185 | capital(other.capital), letterSpacingIsAbsolute(other.letterSpacingIsAbsolute), | - |
186 | letterSpacing(other.letterSpacing), wordSpacing(other.wordSpacing), | - |
187 | scFont(other.scFont) | - |
188 | { | - |
189 | if (scFont && scFont != this) | - |
190 | scFont->ref.ref(); | - |
191 | } | - |
192 | | - |
193 | QFontPrivate::~QFontPrivate() | - |
194 | { | - |
195 | if (engineData) | - |
196 | engineData->ref.deref(); | - |
197 | engineData = 0; | - |
198 | if (scFont && scFont != this) | - |
199 | scFont->ref.deref(); | - |
200 | scFont = 0; | - |
201 | } | - |
202 | | - |
203 | extern QMutex *qt_fontdatabase_mutex(); | - |
204 | | - |
205 | #define QT_FONT_ENGINE_FROM_DATA(data, script) data->engines[script] | - |
206 | | - |
207 | QFontEngine *QFontPrivate::engineForScript(int script) const | - |
208 | { | - |
209 | QMutexLocker locker(qt_fontdatabase_mutex()); | - |
210 | if (script >= QUnicodeTables::Inherited) | - |
211 | script = QUnicodeTables::Common; | - |
212 | if (engineData && engineData->fontCache != QFontCache::instance()) { | - |
213 | // throw out engineData that came from a different thread | - |
214 | engineData->ref.deref(); | - |
215 | engineData = 0; | - |
216 | } | - |
217 | if (!engineData || !QT_FONT_ENGINE_FROM_DATA(engineData, script)) | - |
218 | QFontDatabase::load(this, script); | - |
219 | return QT_FONT_ENGINE_FROM_DATA(engineData, script); | - |
220 | } | - |
221 | | - |
222 | void QFontPrivate::alterCharForCapitalization(QChar &c) const { | - |
223 | switch (capital) { | - |
224 | case QFont::AllUppercase: | - |
225 | case QFont::SmallCaps: | - |
226 | c = c.toUpper(); | - |
227 | break; | - |
228 | case QFont::AllLowercase: | - |
229 | c = c.toLower(); | - |
230 | break; | - |
231 | case QFont::MixedCase: | - |
232 | break; | - |
233 | } | - |
234 | } | - |
235 | | - |
236 | QFontPrivate *QFontPrivate::smallCapsFontPrivate() const | - |
237 | { | - |
238 | if (scFont) | - |
239 | return scFont; | - |
240 | QFont font(const_cast<QFontPrivate *>(this)); | - |
241 | qreal pointSize = font.pointSizeF(); | - |
242 | if (pointSize > 0) | - |
243 | font.setPointSizeF(pointSize * .7); | - |
244 | else | - |
245 | font.setPixelSize((font.pixelSize() * 7 + 5) / 10); | - |
246 | scFont = font.d.data(); | - |
247 | if (scFont != this) | - |
248 | scFont->ref.ref(); | - |
249 | return scFont; | - |
250 | } | - |
251 | | - |
252 | | - |
253 | void QFontPrivate::resolve(uint mask, const QFontPrivate *other) | - |
254 | { | - |
255 | Q_ASSERT(other != 0); | - |
256 | | - |
257 | dpi = other->dpi; | - |
258 | | - |
259 | if ((mask & QFont::AllPropertiesResolved) == QFont::AllPropertiesResolved) return; | - |
260 | | - |
261 | // assign the unset-bits with the set-bits of the other font def | - |
262 | if (! (mask & QFont::FamilyResolved)) | - |
263 | request.family = other->request.family; | - |
264 | | - |
265 | if (! (mask & QFont::StyleNameResolved)) | - |
266 | request.styleName = other->request.styleName; | - |
267 | | - |
268 | if (! (mask & QFont::SizeResolved)) { | - |
269 | request.pointSize = other->request.pointSize; | - |
270 | request.pixelSize = other->request.pixelSize; | - |
271 | } | - |
272 | | - |
273 | if (! (mask & QFont::StyleHintResolved)) | - |
274 | request.styleHint = other->request.styleHint; | - |
275 | | - |
276 | if (! (mask & QFont::StyleStrategyResolved)) | - |
277 | request.styleStrategy = other->request.styleStrategy; | - |
278 | | - |
279 | if (! (mask & QFont::WeightResolved)) | - |
280 | request.weight = other->request.weight; | - |
281 | | - |
282 | if (! (mask & QFont::StyleResolved)) | - |
283 | request.style = other->request.style; | - |
284 | | - |
285 | if (! (mask & QFont::FixedPitchResolved)) | - |
286 | request.fixedPitch = other->request.fixedPitch; | - |
287 | | - |
288 | if (! (mask & QFont::StretchResolved)) | - |
289 | request.stretch = other->request.stretch; | - |
290 | | - |
291 | if (! (mask & QFont::HintingPreferenceResolved)) | - |
292 | request.hintingPreference = other->request.hintingPreference; | - |
293 | | - |
294 | if (! (mask & QFont::UnderlineResolved)) | - |
295 | underline = other->underline; | - |
296 | | - |
297 | if (! (mask & QFont::OverlineResolved)) | - |
298 | overline = other->overline; | - |
299 | | - |
300 | if (! (mask & QFont::StrikeOutResolved)) | - |
301 | strikeOut = other->strikeOut; | - |
302 | | - |
303 | if (! (mask & QFont::KerningResolved)) | - |
304 | kerning = other->kerning; | - |
305 | | - |
306 | if (! (mask & QFont::LetterSpacingResolved)) { | - |
307 | letterSpacing = other->letterSpacing; | - |
308 | letterSpacingIsAbsolute = other->letterSpacingIsAbsolute; | - |
309 | } | - |
310 | if (! (mask & QFont::WordSpacingResolved)) | - |
311 | wordSpacing = other->wordSpacing; | - |
312 | if (! (mask & QFont::CapitalizationResolved)) | - |
313 | capital = other->capital; | - |
314 | } | - |
315 | | - |
316 | | - |
317 | | - |
318 | | - |
319 | QFontEngineData::QFontEngineData() | - |
320 | : ref(1), fontCache(QFontCache::instance()) | - |
321 | { | - |
322 | memset(engines, 0, QUnicodeTables::ScriptCount * sizeof(QFontEngine *)); | - |
323 | } | - |
324 | | - |
325 | QFontEngineData::~QFontEngineData() | - |
326 | { | - |
327 | for (int i = 0; i < QUnicodeTables::ScriptCount; ++i) { | - |
328 | if (engines[i]) | - |
329 | engines[i]->ref.deref(); | - |
330 | engines[i] = 0; | - |
331 | } | - |
332 | } | - |
333 | | - |
334 | | - |
335 | | - |
336 | | - |
337 | /*! | - |
338 | \class QFont | - |
339 | \reentrant | - |
340 | | - |
341 | \brief The QFont class specifies a font used for drawing text. | - |
342 | | - |
343 | \ingroup painting | - |
344 | \ingroup appearance | - |
345 | \ingroup shared | - |
346 | \ingroup richtext-processing | - |
347 | \inmodule QtGui | - |
348 | | - |
349 | | - |
350 | When you create a QFont object you specify various attributes that | - |
351 | you want the font to have. Qt will use the font with the specified | - |
352 | attributes, or if no matching font exists, Qt will use the closest | - |
353 | matching installed font. The attributes of the font that is | - |
354 | actually used are retrievable from a QFontInfo object. If the | - |
355 | window system provides an exact match exactMatch() returns true. | - |
356 | Use QFontMetrics to get measurements, e.g. the pixel length of a | - |
357 | string using QFontMetrics::width(). | - |
358 | | - |
359 | Note that a QGuiApplication instance must exist before a QFont can be | - |
360 | used. You can set the application's default font with | - |
361 | QGuiApplication::setFont(). | - |
362 | | - |
363 | If a chosen font does not include all the characters that | - |
364 | need to be displayed, QFont will try to find the characters in the | - |
365 | nearest equivalent fonts. When a QPainter draws a character from a | - |
366 | font the QFont will report whether or not it has the character; if | - |
367 | it does not, QPainter will draw an unfilled square. | - |
368 | | - |
369 | Create QFonts like this: | - |
370 | | - |
371 | \snippet code/src_gui_text_qfont.cpp 0 | - |
372 | | - |
373 | The attributes set in the constructor can also be set later, e.g. | - |
374 | setFamily(), setPointSize(), setPointSizeF(), setWeight() and | - |
375 | setItalic(). The remaining attributes must be set after | - |
376 | contstruction, e.g. setBold(), setUnderline(), setOverline(), | - |
377 | setStrikeOut() and setFixedPitch(). QFontInfo objects should be | - |
378 | created \e after the font's attributes have been set. A QFontInfo | - |
379 | object will not change, even if you change the font's | - |
380 | attributes. The corresponding "get" functions, e.g. family(), | - |
381 | pointSize(), etc., return the values that were set, even though | - |
382 | the values used may differ. The actual values are available from a | - |
383 | QFontInfo object. | - |
384 | | - |
385 | If the requested font family is unavailable you can influence the | - |
386 | \l{#fontmatching}{font matching algorithm} by choosing a | - |
387 | particular \l{QFont::StyleHint} and \l{QFont::StyleStrategy} with | - |
388 | setStyleHint(). The default family (corresponding to the current | - |
389 | style hint) is returned by defaultFamily(). | - |
390 | | - |
391 | The font-matching algorithm has a lastResortFamily() and | - |
392 | lastResortFont() in cases where a suitable match cannot be found. | - |
393 | You can provide substitutions for font family names using | - |
394 | insertSubstitution() and insertSubstitutions(). Substitutions can | - |
395 | be removed with removeSubstitutions(). Use substitute() to retrieve | - |
396 | a family's first substitute, or the family name itself if it has | - |
397 | no substitutes. Use substitutes() to retrieve a list of a family's | - |
398 | substitutes (which may be empty). | - |
399 | | - |
400 | Every QFont has a key() which you can use, for example, as the key | - |
401 | in a cache or dictionary. If you want to store a user's font | - |
402 | preferences you could use QSettings, writing the font information | - |
403 | with toString() and reading it back with fromString(). The | - |
404 | operator<<() and operator>>() functions are also available, but | - |
405 | they work on a data stream. | - |
406 | | - |
407 | It is possible to set the height of characters shown on the screen | - |
408 | to a specified number of pixels with setPixelSize(); however using | - |
409 | setPointSize() has a similar effect and provides device | - |
410 | independence. | - |
411 | | - |
412 | In X11 you can set a font using its system | - |
413 | specific name with setRawName(). | - |
414 | | - |
415 | Loading fonts can be expensive, especially on X11. QFont contains | - |
416 | extensive optimizations to make the copying of QFont objects fast, | - |
417 | and to cache the results of the slow window system functions it | - |
418 | depends upon. | - |
419 | | - |
420 | \target fontmatching | - |
421 | The font matching algorithm works as follows: | - |
422 | \list 1 | - |
423 | \li The specified font family is searched for. | - |
424 | \li If not found, the styleHint() is used to select a replacement | - |
425 | family. | - |
426 | \li Each replacement font family is searched for. | - |
427 | \li If none of these are found or there was no styleHint(), "helvetica" | - |
428 | will be searched for. | - |
429 | \li If "helvetica" isn't found Qt will try the lastResortFamily(). | - |
430 | \li If the lastResortFamily() isn't found Qt will try the | - |
431 | lastResortFont() which will always return a name of some kind. | - |
432 | \endlist | - |
433 | | - |
434 | Note that the actual font matching algorithm varies from platform to platform. | - |
435 | | - |
436 | In Windows a request for the "Courier" font is automatically changed to | - |
437 | "Courier New", an improved version of Courier that allows for smooth scaling. | - |
438 | The older "Courier" bitmap font can be selected by setting the PreferBitmap | - |
439 | style strategy (see setStyleStrategy()). | - |
440 | | - |
441 | Once a font is found, the remaining attributes are matched in order of | - |
442 | priority: | - |
443 | \list 1 | - |
444 | \li fixedPitch() | - |
445 | \li pointSize() (see below) | - |
446 | \li weight() | - |
447 | \li style() | - |
448 | \endlist | - |
449 | | - |
450 | If you have a font which matches on family, even if none of the | - |
451 | other attributes match, this font will be chosen in preference to | - |
452 | a font which doesn't match on family but which does match on the | - |
453 | other attributes. This is because font family is the dominant | - |
454 | search criteria. | - |
455 | | - |
456 | The point size is defined to match if it is within 20% of the | - |
457 | requested point size. When several fonts match and are only | - |
458 | distinguished by point size, the font with the closest point size | - |
459 | to the one requested will be chosen. | - |
460 | | - |
461 | The actual family, font size, weight and other font attributes | - |
462 | used for drawing text will depend on what's available for the | - |
463 | chosen family under the window system. A QFontInfo object can be | - |
464 | used to determine the actual values used for drawing the text. | - |
465 | | - |
466 | Examples: | - |
467 | | - |
468 | \snippet code/src_gui_text_qfont.cpp 1 | - |
469 | If you had both an Adobe and a Cronyx Helvetica, you might get | - |
470 | either. | - |
471 | | - |
472 | \snippet code/src_gui_text_qfont.cpp 2 | - |
473 | | - |
474 | You can specify the foundry you want in the family name. The font f | - |
475 | in the above example will be set to "Helvetica | - |
476 | [Cronyx]". | - |
477 | | - |
478 | To determine the attributes of the font actually used in the window | - |
479 | system, use a QFontInfo object, e.g. | - |
480 | | - |
481 | \snippet code/src_gui_text_qfont.cpp 3 | - |
482 | | - |
483 | To find out font metrics use a QFontMetrics object, e.g. | - |
484 | | - |
485 | \snippet code/src_gui_text_qfont.cpp 4 | - |
486 | | - |
487 | For more general information on fonts, see the | - |
488 | \l{comp.fonts FAQ}{comp.fonts FAQ}. | - |
489 | Information on encodings can be found from | - |
490 | \l{Roman Czyborra's} page. | - |
491 | | - |
492 | \sa QFontMetrics, QFontInfo, QFontDatabase, {Character Map Example} | - |
493 | */ | - |
494 | | - |
495 | /*! | - |
496 | \internal | - |
497 | \enum QFont::ResolveProperties | - |
498 | | - |
499 | This enum describes the properties of a QFont that can be set on a font | - |
500 | individually and then considered resolved. | - |
501 | | - |
502 | \value FamilyResolved | - |
503 | \value SizeResolved | - |
504 | \value StyleHintResolved | - |
505 | \value StyleStrategyResolved | - |
506 | \value WeightResolved | - |
507 | \value StyleResolved | - |
508 | \value UnderlineResolved | - |
509 | \value OverlineResolved | - |
510 | \value StrikeOutResolved | - |
511 | \value FixedPitchResolved | - |
512 | \value StretchResolved | - |
513 | \value KerningResolved | - |
514 | \value CapitalizationResolved | - |
515 | \value LetterSpacingResolved | - |
516 | \value WordSpacingResolved | - |
517 | \value CompletelyResolved | - |
518 | */ | - |
519 | | - |
520 | /*! | - |
521 | \enum QFont::Style | - |
522 | | - |
523 | This enum describes the different styles of glyphs that are used to | - |
524 | display text. | - |
525 | | - |
526 | \value StyleNormal Normal glyphs used in unstyled text. | - |
527 | \value StyleItalic Italic glyphs that are specifically designed for | - |
528 | the purpose of representing italicized text. | - |
529 | \value StyleOblique Glyphs with an italic appearance that are typically | - |
530 | based on the unstyled glyphs, but are not fine-tuned | - |
531 | for the purpose of representing italicized text. | - |
532 | | - |
533 | \sa Weight | - |
534 | */ | - |
535 | | - |
536 | /*! | - |
537 | \fn QString QFont::rawName() const | - |
538 | | - |
539 | Returns the name of the font within the underlying window system. | - |
540 | | - |
541 | On X11, this function will return an empty string. | - |
542 | | - |
543 | Using the return value of this function is usually \e not \e | - |
544 | portable. | - |
545 | | - |
546 | \sa setRawName() | - |
547 | */ | - |
548 | | - |
549 | /*! | - |
550 | \fn void QFont::setRawName(const QString &name) | - |
551 | | - |
552 | Sets a font by its system specific name. | - |
553 | | - |
554 | A font set with setRawName() is still a full-featured QFont. It can | - |
555 | be queried (for example with italic()) or modified (for example with | - |
556 | setItalic()) and is therefore also suitable for rendering rich text. | - |
557 | | - |
558 | If Qt's internal font database cannot resolve the raw name, the | - |
559 | font becomes a raw font with \a name as its family. | - |
560 | | - |
561 | \sa rawName(), setRawMode(), setFamily() | - |
562 | */ | - |
563 | | - |
564 | /*! | - |
565 | \fn QString QFont::lastResortFamily() const | - |
566 | | - |
567 | Returns the "last resort" font family name. | - |
568 | | - |
569 | The current implementation tries a wide variety of common fonts, | - |
570 | returning the first one it finds. Is is possible that no family is | - |
571 | found in which case an empty string is returned. | - |
572 | | - |
573 | \sa lastResortFont() | - |
574 | */ | - |
575 | | - |
576 | /*! | - |
577 | \fn QString QFont::defaultFamily() const | - |
578 | | - |
579 | Returns the family name that corresponds to the current style | - |
580 | hint. | - |
581 | | - |
582 | \sa StyleHint, styleHint(), setStyleHint() | - |
583 | */ | - |
584 | | - |
585 | /*! | - |
586 | \fn QString QFont::lastResortFont() const | - |
587 | | - |
588 | Returns a "last resort" font name for the font matching algorithm. | - |
589 | This is used if the last resort family is not available. It will | - |
590 | always return a name, if necessary returning something like | - |
591 | "fixed" or "system". | - |
592 | | - |
593 | The current implementation tries a wide variety of common fonts, | - |
594 | returning the first one it finds. The implementation may change | - |
595 | at any time, but this function will always return a string | - |
596 | containing something. | - |
597 | | - |
598 | It is theoretically possible that there really isn't a | - |
599 | lastResortFont() in which case Qt will abort with an error | - |
600 | message. We have not been able to identify a case where this | - |
601 | happens. Please \l{bughowto.html}{report it as a bug} if | - |
602 | it does, preferably with a list of the fonts you have installed. | - |
603 | | - |
604 | \sa lastResortFamily(), rawName() | - |
605 | */ | - |
606 | | - |
607 | /*! | - |
608 | Constructs a font from \a font for use on the paint device \a pd. | - |
609 | */ | - |
610 | QFont::QFont(const QFont &font, QPaintDevice *pd) | - |
611 | : resolve_mask(font.resolve_mask) | - |
612 | { | - |
613 | Q_ASSERT(pd != 0); | - |
614 | int dpi = pd->logicalDpiY(); | - |
615 | const int screen = 0; | - |
616 | if (font.d->dpi != dpi || font.d->screen != screen ) { | - |
617 | d = new QFontPrivate(*font.d); | - |
618 | d->dpi = dpi; | - |
619 | d->screen = screen; | - |
620 | } else { | - |
621 | d = font.d.data(); | - |
622 | } | - |
623 | } | - |
624 | | - |
625 | /*! | - |
626 | \internal | - |
627 | */ | - |
628 | QFont::QFont(QFontPrivate *data) | - |
629 | : d(data), resolve_mask(QFont::AllPropertiesResolved) | - |
630 | { | - |
631 | } | - |
632 | | - |
633 | /*! \internal | - |
634 | Detaches the font object from common font data. | - |
635 | */ | - |
636 | void QFont::detach() | - |
637 | { | - |
638 | if (d->ref.load() == 1) { | - |
639 | if (d->engineData) | - |
640 | d->engineData->ref.deref(); | - |
641 | d->engineData = 0; | - |
642 | if (d->scFont && d->scFont != d.data()) | - |
643 | d->scFont->ref.deref(); | - |
644 | d->scFont = 0; | - |
645 | return; | - |
646 | } | - |
647 | | - |
648 | d.detach(); | - |
649 | } | - |
650 | | - |
651 | /*! | - |
652 | \internal | - |
653 | Detaches the font object from common font attributes data. | - |
654 | Call this instead of QFont::detach() if the only font attributes data | - |
655 | has been changed (underline, letterSpacing, kerning, etc.). | - |
656 | */ | - |
657 | void QFontPrivate::detachButKeepEngineData(QFont *font) | - |
658 | { | - |
659 | if (font->d->ref.load() == 1) | - |
660 | return; | - |
661 | | - |
662 | QFontEngineData *engineData = font->d->engineData; | - |
663 | if (engineData) | - |
664 | engineData->ref.ref(); | - |
665 | font->d.detach(); | - |
666 | font->d->engineData = engineData; | - |
667 | } | - |
668 | | - |
669 | /*! | - |
670 | Constructs a font object that uses the application's default font. | - |
671 | | - |
672 | \sa QGuiApplication::setFont(), QGuiApplication::font() | - |
673 | */ | - |
674 | QFont::QFont() | - |
675 | : d(QGuiApplicationPrivate::instance() ? QGuiApplication::font().d.data() : new QFontPrivate()), resolve_mask(0) | - |
676 | { | - |
677 | } executed: } Execution Count:1041278 | 1041278 |
678 | | - |
679 | /*! | - |
680 | Constructs a font object with the specified \a family, \a | - |
681 | pointSize, \a weight and \a italic settings. | - |
682 | | - |
683 | If \a pointSize is zero or negative, the point size of the font | - |
684 | is set to a system-dependent default value. Generally, this is | - |
685 | 12 points. | - |
686 | | - |
687 | The \a family name may optionally also include a foundry name, | - |
688 | e.g. "Helvetica [Cronyx]". If the \a family is | - |
689 | available from more than one foundry and the foundry isn't | - |
690 | specified, an arbitrary foundry is chosen. If the family isn't | - |
691 | available a family will be set using the \l{QFont}{font matching} | - |
692 | algorithm. | - |
693 | | - |
694 | \sa Weight, setFamily(), setPointSize(), setWeight(), setItalic(), | - |
695 | setStyleHint(), QGuiApplication::font() | - |
696 | */ | - |
697 | QFont::QFont(const QString &family, int pointSize, int weight, bool italic) | - |
698 | : d(new QFontPrivate()), resolve_mask(QFont::FamilyResolved) | - |
699 | { | - |
700 | if (pointSize <= 0) { | - |
701 | pointSize = 12; | - |
702 | } else { | - |
703 | resolve_mask |= QFont::SizeResolved; | - |
704 | } | - |
705 | | - |
706 | if (weight < 0) { | - |
707 | weight = Normal; | - |
708 | } else { | - |
709 | resolve_mask |= QFont::WeightResolved | QFont::StyleResolved; | - |
710 | } | - |
711 | | - |
712 | if (italic) | - |
713 | resolve_mask |= QFont::StyleResolved; | - |
714 | | - |
715 | d->request.family = family; | - |
716 | d->request.pointSize = qreal(pointSize); | - |
717 | d->request.pixelSize = -1; | - |
718 | d->request.weight = weight; | - |
719 | d->request.style = italic ? QFont::StyleItalic : QFont::StyleNormal; | - |
720 | } | - |
721 | | - |
722 | /*! | - |
723 | Constructs a font that is a copy of \a font. | - |
724 | */ | - |
725 | QFont::QFont(const QFont &font) | - |
726 | : d(font.d.data()), resolve_mask(font.resolve_mask) | - |
727 | { | - |
728 | } | - |
729 | | - |
730 | /*! | - |
731 | Destroys the font object and frees all allocated resources. | - |
732 | */ | - |
733 | QFont::~QFont() | - |
734 | { | - |
735 | } | - |
736 | | - |
737 | /*! | - |
738 | Assigns \a font to this font and returns a reference to it. | - |
739 | */ | - |
740 | QFont &QFont::operator=(const QFont &font) | - |
741 | { | - |
742 | d = font.d.data(); | - |
743 | resolve_mask = font.resolve_mask; | - |
744 | return *this; | - |
745 | } | - |
746 | | - |
747 | /*! | - |
748 | \fn void QFont::swap(QFont &other) | - |
749 | \since 5.0 | - |
750 | | - |
751 | Swaps this font instance with \a other. This function is very fast | - |
752 | and never fails. | - |
753 | */ | - |
754 | | - |
755 | /*! | - |
756 | Returns the requested font family name, i.e. the name set in the | - |
757 | constructor or the last setFont() call. | - |
758 | | - |
759 | \sa setFamily(), substitutes(), substitute() | - |
760 | */ | - |
761 | QString QFont::family() const | - |
762 | { | - |
763 | return d->request.family; | - |
764 | } | - |
765 | | - |
766 | /*! | - |
767 | Sets the family name of the font. The name is case insensitive and | - |
768 | may include a foundry name. | - |
769 | | - |
770 | The \a family name may optionally also include a foundry name, | - |
771 | e.g. "Helvetica [Cronyx]". If the \a family is | - |
772 | available from more than one foundry and the foundry isn't | - |
773 | specified, an arbitrary foundry is chosen. If the family isn't | - |
774 | available a family will be set using the \l{QFont}{font matching} | - |
775 | algorithm. | - |
776 | | - |
777 | \sa family(), setStyleHint(), QFontInfo | - |
778 | */ | - |
779 | void QFont::setFamily(const QString &family) | - |
780 | { | - |
781 | if ((resolve_mask & QFont::FamilyResolved) && d->request.family == family) | - |
782 | return; | - |
783 | | - |
784 | detach(); | - |
785 | | - |
786 | d->request.family = family; | - |
787 | | - |
788 | resolve_mask |= QFont::FamilyResolved; | - |
789 | } | - |
790 | | - |
791 | /*! | - |
792 | \since 4.8 | - |
793 | | - |
794 | Returns the requested font style name, it will be used to match the | - |
795 | font with irregular styles (that can't be normalized in other style | - |
796 | properties). It depends on system font support, thus only works for | - |
797 | Mac OS X and X11 so far. On Windows irregular styles will be added | - |
798 | as separate font families so there is no need for this. | - |
799 | | - |
800 | \sa setFamily(), setStyle() | - |
801 | */ | - |
802 | QString QFont::styleName() const | - |
803 | { | - |
804 | return d->request.styleName; | - |
805 | } | - |
806 | | - |
807 | /*! | - |
808 | \since 4.8 | - |
809 | | - |
810 | Sets the style name of the font to \a styleName. When set, other style properties | - |
811 | like \l style() and \l weight() will be ignored for font matching. | - |
812 | | - |
813 | \sa styleName() | - |
814 | */ | - |
815 | void QFont::setStyleName(const QString &styleName) | - |
816 | { | - |
817 | if ((resolve_mask & QFont::StyleNameResolved) && d->request.styleName == styleName) | - |
818 | return; | - |
819 | | - |
820 | detach(); | - |
821 | | - |
822 | d->request.styleName = styleName; | - |
823 | resolve_mask |= QFont::StyleNameResolved; | - |
824 | } | - |
825 | | - |
826 | /*! | - |
827 | Returns the point size of the font. Returns -1 if the font size | - |
828 | was specified in pixels. | - |
829 | | - |
830 | \sa setPointSize(), pointSizeF() | - |
831 | */ | - |
832 | int QFont::pointSize() const | - |
833 | { | - |
834 | return qRound(d->request.pointSize); | - |
835 | } | - |
836 | | - |
837 | /*! | - |
838 | \since 4.8 | - |
839 | | - |
840 | \enum QFont::HintingPreference | - |
841 | | - |
842 | This enum describes the different levels of hinting that can be applied | - |
843 | to glyphs to improve legibility on displays where it might be warranted | - |
844 | by the density of pixels. | - |
845 | | - |
846 | \value PreferDefaultHinting Use the default hinting level for the target platform. | - |
847 | \value PreferNoHinting If possible, render text without hinting the outlines | - |
848 | of the glyphs. The text layout will be typographically accurate and | - |
849 | scalable, using the same metrics as are used e.g. when printing. | - |
850 | \value PreferVerticalHinting If possible, render text with no horizontal hinting, | - |
851 | but align glyphs to the pixel grid in the vertical direction. The text will appear | - |
852 | crisper on displays where the density is too low to give an accurate rendering | - |
853 | of the glyphs. But since the horizontal metrics of the glyphs are unhinted, the text's | - |
854 | layout will be scalable to higher density devices (such as printers) without impacting | - |
855 | details such as line breaks. | - |
856 | \value PreferFullHinting If possible, render text with hinting in both horizontal and | - |
857 | vertical directions. The text will be altered to optimize legibility on the target | - |
858 | device, but since the metrics will depend on the target size of the text, the positions | - |
859 | of glyphs, line breaks, and other typographical detail will not scale, meaning that a | - |
860 | text layout may look different on devices with different pixel densities. | - |
861 | | - |
862 | Please note that this enum only describes a preference, as the full range of hinting levels | - |
863 | are not supported on all of Qt's supported platforms. The following table details the effect | - |
864 | of a given hinting preference on a selected set of target platforms. | - |
865 | | - |
866 | \table | - |
867 | \header | - |
868 | \li | - |
869 | \li PreferDefaultHinting | - |
870 | \li PreferNoHinting | - |
871 | \li PreferVerticalHinting | - |
872 | \li PreferFullHinting | - |
873 | \row | - |
874 | \li Windows Vista (w/o Platform Update) and earlier | - |
875 | \li Full hinting | - |
876 | \li Full hinting | - |
877 | \li Full hinting | - |
878 | \li Full hinting | - |
879 | \row | - |
880 | \li Windows 7 and Windows Vista (w/Platform Update) and DirectWrite enabled in Qt | - |
881 | \li Full hinting | - |
882 | \li Vertical hinting | - |
883 | \li Vertical hinting | - |
884 | \li Full hinting | - |
885 | \row | - |
886 | \li FreeType | - |
887 | \li Operating System setting | - |
888 | \li No hinting | - |
889 | \li Vertical hinting (light) | - |
890 | \li Full hinting | - |
891 | \row | - |
892 | \li Cocoa on Mac OS X | - |
893 | \li No hinting | - |
894 | \li No hinting | - |
895 | \li No hinting | - |
896 | \li No hinting | - |
897 | \endtable | - |
898 | | - |
899 | \note Please be aware that altering the hinting preference on Windows is available through | - |
900 | the DirectWrite font engine. This is available on Windows Vista after installing the platform | - |
901 | update, and on Windows 7. In order to use this extension, configure Qt using -directwrite. | - |
902 | The target application will then depend on the availability of DirectWrite on the target | - |
903 | system. | - |
904 | | - |
905 | */ | - |
906 | | - |
907 | /*! | - |
908 | \since 4.8 | - |
909 | | - |
910 | Set the preference for the hinting level of the glyphs to \a hintingPreference. This is a hint | - |
911 | to the underlying font rendering system to use a certain level of hinting, and has varying | - |
912 | support across platforms. See the table in the documentation for QFont::HintingPreference for | - |
913 | more details. | - |
914 | | - |
915 | The default hinting preference is QFont::PreferDefaultHinting. | - |
916 | */ | - |
917 | void QFont::setHintingPreference(HintingPreference hintingPreference) | - |
918 | { | - |
919 | if ((resolve_mask & QFont::HintingPreferenceResolved) && d->request.hintingPreference == hintingPreference) | - |
920 | return; | - |
921 | | - |
922 | detach(); | - |
923 | | - |
924 | d->request.hintingPreference = hintingPreference; | - |
925 | | - |
926 | resolve_mask |= QFont::HintingPreferenceResolved; | - |
927 | } | - |
928 | | - |
929 | /*! | - |
930 | \since 4.8 | - |
931 | | - |
932 | Returns the currently preferred hinting level for glyphs rendered with this font. | - |
933 | */ | - |
934 | QFont::HintingPreference QFont::hintingPreference() const | - |
935 | { | - |
936 | return QFont::HintingPreference(d->request.hintingPreference); | - |
937 | } | - |
938 | | - |
939 | /*! | - |
940 | Sets the point size to \a pointSize. The point size must be | - |
941 | greater than zero. | - |
942 | | - |
943 | \sa pointSize(), setPointSizeF() | - |
944 | */ | - |
945 | void QFont::setPointSize(int pointSize) | - |
946 | { | - |
947 | if (pointSize <= 0) { | - |
948 | qWarning("QFont::setPointSize: Point size <= 0 (%d), must be greater than 0", pointSize); | - |
949 | return; | - |
950 | } | - |
951 | | - |
952 | if ((resolve_mask & QFont::SizeResolved) && d->request.pointSize == qreal(pointSize)) | - |
953 | return; | - |
954 | | - |
955 | detach(); | - |
956 | | - |
957 | d->request.pointSize = qreal(pointSize); | - |
958 | d->request.pixelSize = -1; | - |
959 | | - |
960 | resolve_mask |= QFont::SizeResolved; | - |
961 | } | - |
962 | | - |
963 | /*! | - |
964 | Sets the point size to \a pointSize. The point size must be | - |
965 | greater than zero. The requested precision may not be achieved on | - |
966 | all platforms. | - |
967 | | - |
968 | \sa pointSizeF(), setPointSize(), setPixelSize() | - |
969 | */ | - |
970 | void QFont::setPointSizeF(qreal pointSize) | - |
971 | { | - |
972 | if (pointSize <= 0) { | - |
973 | qWarning("QFont::setPointSizeF: Point size <= 0 (%f), must be greater than 0", pointSize); | - |
974 | return; | - |
975 | } | - |
976 | | - |
977 | if ((resolve_mask & QFont::SizeResolved) && d->request.pointSize == pointSize) | - |
978 | return; | - |
979 | | - |
980 | detach(); | - |
981 | | - |
982 | d->request.pointSize = pointSize; | - |
983 | d->request.pixelSize = -1; | - |
984 | | - |
985 | resolve_mask |= QFont::SizeResolved; | - |
986 | } | - |
987 | | - |
988 | /*! | - |
989 | Returns the point size of the font. Returns -1 if the font size was | - |
990 | specified in pixels. | - |
991 | | - |
992 | \sa pointSize(), setPointSizeF(), pixelSize(), QFontInfo::pointSize(), QFontInfo::pixelSize() | - |
993 | */ | - |
994 | qreal QFont::pointSizeF() const | - |
995 | { | - |
996 | return d->request.pointSize; | - |
997 | } | - |
998 | | - |
999 | /*! | - |
1000 | Sets the font size to \a pixelSize pixels. | - |
1001 | | - |
1002 | Using this function makes the font device dependent. Use | - |
1003 | setPointSize() or setPointSizeF() to set the size of the font | - |
1004 | in a device independent manner. | - |
1005 | | - |
1006 | \sa pixelSize() | - |
1007 | */ | - |
1008 | void QFont::setPixelSize(int pixelSize) | - |
1009 | { | - |
1010 | if (pixelSize <= 0) { | - |
1011 | qWarning("QFont::setPixelSize: Pixel size <= 0 (%d)", pixelSize); | - |
1012 | return; | - |
1013 | } | - |
1014 | | - |
1015 | if ((resolve_mask & QFont::SizeResolved) && d->request.pixelSize == qreal(pixelSize)) | - |
1016 | return; | - |
1017 | | - |
1018 | detach(); | - |
1019 | | - |
1020 | d->request.pixelSize = pixelSize; | - |
1021 | d->request.pointSize = -1; | - |
1022 | | - |
1023 | resolve_mask |= QFont::SizeResolved; | - |
1024 | } | - |
1025 | | - |
1026 | /*! | - |
1027 | Returns the pixel size of the font if it was set with | - |
1028 | setPixelSize(). Returns -1 if the size was set with setPointSize() | - |
1029 | or setPointSizeF(). | - |
1030 | | - |
1031 | \sa setPixelSize(), pointSize(), QFontInfo::pointSize(), QFontInfo::pixelSize() | - |
1032 | */ | - |
1033 | int QFont::pixelSize() const | - |
1034 | { | - |
1035 | return d->request.pixelSize; | - |
1036 | } | - |
1037 | | - |
1038 | /*! | - |
1039 | \fn bool QFont::italic() const | - |
1040 | | - |
1041 | Returns true if the style() of the font is not QFont::StyleNormal | - |
1042 | | - |
1043 | \sa setItalic(), style() | - |
1044 | */ | - |
1045 | | - |
1046 | /*! | - |
1047 | \fn void QFont::setItalic(bool enable) | - |
1048 | | - |
1049 | Sets the style() of the font to QFont::StyleItalic if \a enable is true; | - |
1050 | otherwise the style is set to QFont::StyleNormal. | - |
1051 | | - |
1052 | \sa italic(), QFontInfo | - |
1053 | */ | - |
1054 | | - |
1055 | /*! | - |
1056 | Returns the style of the font. | - |
1057 | | - |
1058 | \sa setStyle() | - |
1059 | */ | - |
1060 | QFont::Style QFont::style() const | - |
1061 | { | - |
1062 | return (QFont::Style)d->request.style; | - |
1063 | } | - |
1064 | | - |
1065 | | - |
1066 | /*! | - |
1067 | Sets the style of the font to \a style. | - |
1068 | | - |
1069 | \sa italic(), QFontInfo | - |
1070 | */ | - |
1071 | void QFont::setStyle(Style style) | - |
1072 | { | - |
1073 | if ((resolve_mask & QFont::StyleResolved) && d->request.style == style) | - |
1074 | return; | - |
1075 | | - |
1076 | detach(); | - |
1077 | | - |
1078 | d->request.style = style; | - |
1079 | resolve_mask |= QFont::StyleResolved; | - |
1080 | } | - |
1081 | | - |
1082 | /*! | - |
1083 | Returns the weight of the font which is one of the enumerated | - |
1084 | values from \l{QFont::Weight}. | - |
1085 | | - |
1086 | \sa setWeight(), Weight, QFontInfo | - |
1087 | */ | - |
1088 | int QFont::weight() const | - |
1089 | { | - |
1090 | return d->request.weight; | - |
1091 | } | - |
1092 | | - |
1093 | /*! | - |
1094 | \enum QFont::Weight | - |
1095 | | - |
1096 | Qt uses a weighting scale from 0 to 99 similar to, but not the | - |
1097 | same as, the scales used in Windows or CSS. A weight of 0 is | - |
1098 | ultralight, whilst 99 will be an extremely black. | - |
1099 | | - |
1100 | This enum contains the predefined font weights: | - |
1101 | | - |
1102 | \value Light 25 | - |
1103 | \value Normal 50 | - |
1104 | \value DemiBold 63 | - |
1105 | \value Bold 75 | - |
1106 | \value Black 87 | - |
1107 | */ | - |
1108 | | - |
1109 | /*! | - |
1110 | Sets the weight the font to \a weight, which should be a value | - |
1111 | from the \l QFont::Weight enumeration. | - |
1112 | | - |
1113 | \sa weight(), QFontInfo | - |
1114 | */ | - |
1115 | void QFont::setWeight(int weight) | - |
1116 | { | - |
1117 | Q_ASSERT_X(weight >= 0 && weight <= 99, "QFont::setWeight", "Weight must be between 0 and 99"); | - |
1118 | | - |
1119 | if ((resolve_mask & QFont::WeightResolved) && d->request.weight == weight) | - |
1120 | return; | - |
1121 | | - |
1122 | detach(); | - |
1123 | | - |
1124 | d->request.weight = weight; | - |
1125 | resolve_mask |= QFont::WeightResolved; | - |
1126 | } | - |
1127 | | - |
1128 | /*! | - |
1129 | \fn bool QFont::bold() const | - |
1130 | | - |
1131 | Returns true if weight() is a value greater than | - |
1132 | \l{Weight}{QFont::Normal}; otherwise returns false. | - |
1133 | | - |
1134 | \sa weight(), setBold(), QFontInfo::bold() | - |
1135 | */ | - |
1136 | | - |
1137 | /*! | - |
1138 | \fn void QFont::setBold(bool enable) | - |
1139 | | - |
1140 | If \a enable is true sets the font's weight to | - |
1141 | \l{Weight}{QFont::Bold}; | - |
1142 | otherwise sets the weight to \l{Weight}{QFont::Normal}. | - |
1143 | | - |
1144 | For finer boldness control use setWeight(). | - |
1145 | | - |
1146 | \sa bold(), setWeight() | - |
1147 | */ | - |
1148 | | - |
1149 | /*! | - |
1150 | Returns true if underline has been set; otherwise returns false. | - |
1151 | | - |
1152 | \sa setUnderline() | - |
1153 | */ | - |
1154 | bool QFont::underline() const | - |
1155 | { | - |
1156 | return d->underline; | - |
1157 | } | - |
1158 | | - |
1159 | /*! | - |
1160 | If \a enable is true, sets underline on; otherwise sets underline | - |
1161 | off. | - |
1162 | | - |
1163 | \sa underline(), QFontInfo | - |
1164 | */ | - |
1165 | void QFont::setUnderline(bool enable) | - |
1166 | { | - |
1167 | if ((resolve_mask & QFont::UnderlineResolved) && d->underline == enable) | - |
1168 | return; | - |
1169 | | - |
1170 | QFontPrivate::detachButKeepEngineData(this); | - |
1171 | | - |
1172 | d->underline = enable; | - |
1173 | resolve_mask |= QFont::UnderlineResolved; | - |
1174 | } | - |
1175 | | - |
1176 | /*! | - |
1177 | Returns true if overline has been set; otherwise returns false. | - |
1178 | | - |
1179 | \sa setOverline() | - |
1180 | */ | - |
1181 | bool QFont::overline() const | - |
1182 | { | - |
1183 | return d->overline; | - |
1184 | } | - |
1185 | | - |
1186 | /*! | - |
1187 | If \a enable is true, sets overline on; otherwise sets overline off. | - |
1188 | | - |
1189 | \sa overline(), QFontInfo | - |
1190 | */ | - |
1191 | void QFont::setOverline(bool enable) | - |
1192 | { | - |
1193 | if ((resolve_mask & QFont::OverlineResolved) && d->overline == enable) | - |
1194 | return; | - |
1195 | | - |
1196 | QFontPrivate::detachButKeepEngineData(this); | - |
1197 | | - |
1198 | d->overline = enable; | - |
1199 | resolve_mask |= QFont::OverlineResolved; | - |
1200 | } | - |
1201 | | - |
1202 | /*! | - |
1203 | Returns true if strikeout has been set; otherwise returns false. | - |
1204 | | - |
1205 | \sa setStrikeOut() | - |
1206 | */ | - |
1207 | bool QFont::strikeOut() const | - |
1208 | { | - |
1209 | return d->strikeOut; | - |
1210 | } | - |
1211 | | - |
1212 | /*! | - |
1213 | If \a enable is true, sets strikeout on; otherwise sets strikeout | - |
1214 | off. | - |
1215 | | - |
1216 | \sa strikeOut(), QFontInfo | - |
1217 | */ | - |
1218 | void QFont::setStrikeOut(bool enable) | - |
1219 | { | - |
1220 | if ((resolve_mask & QFont::StrikeOutResolved) && d->strikeOut == enable) | - |
1221 | return; | - |
1222 | | - |
1223 | QFontPrivate::detachButKeepEngineData(this); | - |
1224 | | - |
1225 | d->strikeOut = enable; | - |
1226 | resolve_mask |= QFont::StrikeOutResolved; | - |
1227 | } | - |
1228 | | - |
1229 | /*! | - |
1230 | Returns true if fixed pitch has been set; otherwise returns false. | - |
1231 | | - |
1232 | \sa setFixedPitch(), QFontInfo::fixedPitch() | - |
1233 | */ | - |
1234 | bool QFont::fixedPitch() const | - |
1235 | { | - |
1236 | return d->request.fixedPitch; | - |
1237 | } | - |
1238 | | - |
1239 | /*! | - |
1240 | If \a enable is true, sets fixed pitch on; otherwise sets fixed | - |
1241 | pitch off. | - |
1242 | | - |
1243 | \sa fixedPitch(), QFontInfo | - |
1244 | */ | - |
1245 | void QFont::setFixedPitch(bool enable) | - |
1246 | { | - |
1247 | if ((resolve_mask & QFont::FixedPitchResolved) && d->request.fixedPitch == enable) | - |
1248 | return; | - |
1249 | | - |
1250 | detach(); | - |
1251 | | - |
1252 | d->request.fixedPitch = enable; | - |
1253 | d->request.ignorePitch = false; | - |
1254 | resolve_mask |= QFont::FixedPitchResolved; | - |
1255 | } | - |
1256 | | - |
1257 | /*! | - |
1258 | Returns true if kerning should be used when drawing text with this font. | - |
1259 | | - |
1260 | \sa setKerning() | - |
1261 | */ | - |
1262 | bool QFont::kerning() const | - |
1263 | { | - |
1264 | return d->kerning; | - |
1265 | } | - |
1266 | | - |
1267 | /*! | - |
1268 | Enables kerning for this font if \a enable is true; otherwise | - |
1269 | disables it. By default, kerning is enabled. | - |
1270 | | - |
1271 | When kerning is enabled, glyph metrics do not add up anymore, | - |
1272 | even for Latin text. In other words, the assumption that | - |
1273 | width('a') + width('b') is equal to width("ab") is not | - |
1274 | neccesairly true. | - |
1275 | | - |
1276 | \sa kerning(), QFontMetrics | - |
1277 | */ | - |
1278 | void QFont::setKerning(bool enable) | - |
1279 | { | - |
1280 | if ((resolve_mask & QFont::KerningResolved) && d->kerning == enable) | - |
1281 | return; | - |
1282 | | - |
1283 | QFontPrivate::detachButKeepEngineData(this); | - |
1284 | | - |
1285 | d->kerning = enable; | - |
1286 | resolve_mask |= QFont::KerningResolved; | - |
1287 | } | - |
1288 | | - |
1289 | /*! | - |
1290 | Returns the StyleStrategy. | - |
1291 | | - |
1292 | The style strategy affects the \l{QFont}{font matching} algorithm. | - |
1293 | See \l QFont::StyleStrategy for the list of available strategies. | - |
1294 | | - |
1295 | \sa setStyleHint(), QFont::StyleHint | - |
1296 | */ | - |
1297 | QFont::StyleStrategy QFont::styleStrategy() const | - |
1298 | { | - |
1299 | return (StyleStrategy) d->request.styleStrategy; | - |
1300 | } | - |
1301 | | - |
1302 | /*! | - |
1303 | Returns the StyleHint. | - |
1304 | | - |
1305 | The style hint affects the \l{QFont}{font matching} algorithm. | - |
1306 | See \l QFont::StyleHint for the list of available hints. | - |
1307 | | - |
1308 | \sa setStyleHint(), QFont::StyleStrategy, QFontInfo::styleHint() | - |
1309 | */ | - |
1310 | QFont::StyleHint QFont::styleHint() const | - |
1311 | { | - |
1312 | return (StyleHint) d->request.styleHint; | - |
1313 | } | - |
1314 | | - |
1315 | /*! | - |
1316 | \enum QFont::StyleHint | - |
1317 | | - |
1318 | Style hints are used by the \l{QFont}{font matching} algorithm to | - |
1319 | find an appropriate default family if a selected font family is | - |
1320 | not available. | - |
1321 | | - |
1322 | \value AnyStyle leaves the font matching algorithm to choose the | - |
1323 | family. This is the default. | - |
1324 | | - |
1325 | \value SansSerif the font matcher prefer sans serif fonts. | - |
1326 | \value Helvetica is a synonym for \c SansSerif. | - |
1327 | | - |
1328 | \value Serif the font matcher prefers serif fonts. | - |
1329 | \value Times is a synonym for \c Serif. | - |
1330 | | - |
1331 | \value TypeWriter the font matcher prefers fixed pitch fonts. | - |
1332 | \value Courier a synonym for \c TypeWriter. | - |
1333 | | - |
1334 | \value OldEnglish the font matcher prefers decorative fonts. | - |
1335 | \value Decorative is a synonym for \c OldEnglish. | - |
1336 | | - |
1337 | \value Monospace the font matcher prefers fonts that map to the | - |
1338 | CSS generic font-family 'monospace'. | - |
1339 | | - |
1340 | \value Fantasy the font matcher prefers fonts that map to the | - |
1341 | CSS generic font-family 'fantasy'. | - |
1342 | | - |
1343 | \value Cursive the font matcher prefers fonts that map to the | - |
1344 | CSS generic font-family 'cursive'. | - |
1345 | | - |
1346 | \value System the font matcher prefers system fonts. | - |
1347 | */ | - |
1348 | | - |
1349 | /*! | - |
1350 | \enum QFont::StyleStrategy | - |
1351 | | - |
1352 | The style strategy tells the \l{QFont}{font matching} algorithm | - |
1353 | what type of fonts should be used to find an appropriate default | - |
1354 | family. | - |
1355 | | - |
1356 | The following strategies are available: | - |
1357 | | - |
1358 | \value PreferDefault the default style strategy. It does not prefer | - |
1359 | any type of font. | - |
1360 | \value PreferBitmap prefers bitmap fonts (as opposed to outline | - |
1361 | fonts). | - |
1362 | \value PreferDevice prefers device fonts. | - |
1363 | \value PreferOutline prefers outline fonts (as opposed to bitmap fonts). | - |
1364 | \value ForceOutline forces the use of outline fonts. | - |
1365 | \value NoAntialias don't antialias the fonts. | - |
1366 | \value PreferAntialias antialias if possible. | - |
1367 | \value OpenGLCompatible forces the use of OpenGL compatible | - |
1368 | fonts. | - |
1369 | \value NoFontMerging If the font selected for a certain writing system | - |
1370 | does not contain a character requested to draw, then Qt automatically chooses a similar | - |
1371 | looking font that contains the character. The NoFontMerging flag disables this feature. | - |
1372 | Please note that enabling this flag will not prevent Qt from automatically picking a | - |
1373 | suitable font when the selected font does not support the writing system of the text. | - |
1374 | | - |
1375 | Any of these may be OR-ed with one of these flags: | - |
1376 | | - |
1377 | \value PreferMatch prefer an exact match. The font matcher will try to | - |
1378 | use the exact font size that has been specified. | - |
1379 | \value PreferQuality prefer the best quality font. The font matcher | - |
1380 | will use the nearest standard point size that the font | - |
1381 | supports. | - |
1382 | \value ForceIntegerMetrics forces the use of integer values in font engines that support fractional | - |
1383 | font metrics. | - |
1384 | */ | - |
1385 | | - |
1386 | /*! | - |
1387 | Sets the style hint and strategy to \a hint and \a strategy, | - |
1388 | respectively. | - |
1389 | | - |
1390 | If these aren't set explicitly the style hint will default to | - |
1391 | \c AnyStyle and the style strategy to \c PreferDefault. | - |
1392 | | - |
1393 | Qt does not support style hints on X11 since this information | - |
1394 | is not provided by the window system. | - |
1395 | | - |
1396 | \sa StyleHint, styleHint(), StyleStrategy, styleStrategy(), QFontInfo | - |
1397 | */ | - |
1398 | void QFont::setStyleHint(StyleHint hint, StyleStrategy strategy) | - |
1399 | { | - |
1400 | if ((resolve_mask & (QFont::StyleHintResolved | QFont::StyleStrategyResolved)) && | - |
1401 | (StyleHint) d->request.styleHint == hint && | - |
1402 | (StyleStrategy) d->request.styleStrategy == strategy) | - |
1403 | return; | - |
1404 | | - |
1405 | detach(); | - |
1406 | | - |
1407 | d->request.styleHint = hint; | - |
1408 | d->request.styleStrategy = strategy; | - |
1409 | resolve_mask |= QFont::StyleHintResolved; | - |
1410 | resolve_mask |= QFont::StyleStrategyResolved; | - |
1411 | | - |
1412 | } | - |
1413 | | - |
1414 | /*! | - |
1415 | Sets the style strategy for the font to \a s. | - |
1416 | | - |
1417 | \sa QFont::StyleStrategy | - |
1418 | */ | - |
1419 | void QFont::setStyleStrategy(StyleStrategy s) | - |
1420 | { | - |
1421 | if ((resolve_mask & QFont::StyleStrategyResolved) && | - |
1422 | s == (StyleStrategy)d->request.styleStrategy) | - |
1423 | return; | - |
1424 | | - |
1425 | detach(); | - |
1426 | | - |
1427 | d->request.styleStrategy = s; | - |
1428 | resolve_mask |= QFont::StyleStrategyResolved; | - |
1429 | } | - |
1430 | | - |
1431 | | - |
1432 | /*! | - |
1433 | \enum QFont::Stretch | - |
1434 | | - |
1435 | Predefined stretch values that follow the CSS naming convention. The higher | - |
1436 | the value, the more stretched the text is. | - |
1437 | | - |
1438 | \value UltraCondensed 50 | - |
1439 | \value ExtraCondensed 62 | - |
1440 | \value Condensed 75 | - |
1441 | \value SemiCondensed 87 | - |
1442 | \value Unstretched 100 | - |
1443 | \value SemiExpanded 112 | - |
1444 | \value Expanded 125 | - |
1445 | \value ExtraExpanded 150 | - |
1446 | \value UltraExpanded 200 | - |
1447 | | - |
1448 | \sa setStretch(), stretch() | - |
1449 | */ | - |
1450 | | - |
1451 | /*! | - |
1452 | Returns the stretch factor for the font. | - |
1453 | | - |
1454 | \sa setStretch() | - |
1455 | */ | - |
1456 | int QFont::stretch() const | - |
1457 | { | - |
1458 | return d->request.stretch; | - |
1459 | } | - |
1460 | | - |
1461 | /*! | - |
1462 | Sets the stretch factor for the font. | - |
1463 | | - |
1464 | The stretch factor changes the width of all characters in the font | - |
1465 | by \a factor percent. For example, setting \a factor to 150 | - |
1466 | results in all characters in the font being 1.5 times (ie. 150%) | - |
1467 | wider. The default stretch factor is 100. The minimum stretch | - |
1468 | factor is 1, and the maximum stretch factor is 4000. | - |
1469 | | - |
1470 | The stretch factor is only applied to outline fonts. The stretch | - |
1471 | factor is ignored for bitmap fonts. | - |
1472 | | - |
1473 | \sa stretch(), QFont::Stretch | - |
1474 | */ | - |
1475 | void QFont::setStretch(int factor) | - |
1476 | { | - |
1477 | if (factor < 1 || factor > 4000) { | - |
1478 | qWarning("QFont::setStretch: Parameter '%d' out of range", factor); | - |
1479 | return; | - |
1480 | } | - |
1481 | | - |
1482 | if ((resolve_mask & QFont::StretchResolved) && | - |
1483 | d->request.stretch == (uint)factor) | - |
1484 | return; | - |
1485 | | - |
1486 | detach(); | - |
1487 | | - |
1488 | d->request.stretch = (uint)factor; | - |
1489 | resolve_mask |= QFont::StretchResolved; | - |
1490 | } | - |
1491 | | - |
1492 | /*! | - |
1493 | \enum QFont::SpacingType | - |
1494 | \since 4.4 | - |
1495 | | - |
1496 | \value PercentageSpacing A value of 100 will keep the spacing unchanged; a value of 200 will enlarge the | - |
1497 | spacing after a character by the width of the character itself. | - |
1498 | \value AbsoluteSpacing A positive value increases the letter spacing by the corresponding pixels; a negative | - |
1499 | value decreases the spacing. | - |
1500 | */ | - |
1501 | | - |
1502 | /*! | - |
1503 | \since 4.4 | - |
1504 | Returns the letter spacing for the font. | - |
1505 | | - |
1506 | \sa setLetterSpacing(), letterSpacingType(), setWordSpacing() | - |
1507 | */ | - |
1508 | qreal QFont::letterSpacing() const | - |
1509 | { | - |
1510 | return d->letterSpacing.toReal(); | - |
1511 | } | - |
1512 | | - |
1513 | /*! | - |
1514 | \since 4.4 | - |
1515 | Sets the letter spacing for the font to \a spacing and the type | - |
1516 | of spacing to \a type. | - |
1517 | | - |
1518 | Letter spacing changes the default spacing between individual | - |
1519 | letters in the font. The spacing between the letters can be | - |
1520 | made smaller as well as larger. | - |
1521 | | - |
1522 | \sa letterSpacing(), letterSpacingType(), setWordSpacing() | - |
1523 | */ | - |
1524 | void QFont::setLetterSpacing(SpacingType type, qreal spacing) | - |
1525 | { | - |
1526 | const QFixed newSpacing = QFixed::fromReal(spacing); | - |
1527 | const bool absoluteSpacing = type == AbsoluteSpacing; | - |
1528 | if ((resolve_mask & QFont::LetterSpacingResolved) && | - |
1529 | d->letterSpacingIsAbsolute == absoluteSpacing && | - |
1530 | d->letterSpacing == newSpacing) | - |
1531 | return; | - |
1532 | | - |
1533 | QFontPrivate::detachButKeepEngineData(this); | - |
1534 | | - |
1535 | d->letterSpacing = newSpacing; | - |
1536 | d->letterSpacingIsAbsolute = absoluteSpacing; | - |
1537 | resolve_mask |= QFont::LetterSpacingResolved; | - |
1538 | } | - |
1539 | | - |
1540 | /*! | - |
1541 | \since 4.4 | - |
1542 | Returns the spacing type used for letter spacing. | - |
1543 | | - |
1544 | \sa letterSpacing(), setLetterSpacing(), setWordSpacing() | - |
1545 | */ | - |
1546 | QFont::SpacingType QFont::letterSpacingType() const | - |
1547 | { | - |
1548 | return d->letterSpacingIsAbsolute ? AbsoluteSpacing : PercentageSpacing; | - |
1549 | } | - |
1550 | | - |
1551 | /*! | - |
1552 | \since 4.4 | - |
1553 | Returns the word spacing for the font. | - |
1554 | | - |
1555 | \sa setWordSpacing(), setLetterSpacing() | - |
1556 | */ | - |
1557 | qreal QFont::wordSpacing() const | - |
1558 | { | - |
1559 | return d->wordSpacing.toReal(); | - |
1560 | } | - |
1561 | | - |
1562 | /*! | - |
1563 | \since 4.4 | - |
1564 | Sets the word spacing for the font to \a spacing. | - |
1565 | | - |
1566 | Word spacing changes the default spacing between individual | - |
1567 | words. A positive value increases the word spacing | - |
1568 | by a corresponding amount of pixels, while a negative value | - |
1569 | decreases the inter-word spacing accordingly. | - |
1570 | | - |
1571 | Word spacing will not apply to writing systems, where indiviaul | - |
1572 | words are not separated by white space. | - |
1573 | | - |
1574 | \sa wordSpacing(), setLetterSpacing() | - |
1575 | */ | - |
1576 | void QFont::setWordSpacing(qreal spacing) | - |
1577 | { | - |
1578 | const QFixed newSpacing = QFixed::fromReal(spacing); | - |
1579 | if ((resolve_mask & QFont::WordSpacingResolved) && | - |
1580 | d->wordSpacing == newSpacing) | - |
1581 | return; | - |
1582 | | - |
1583 | QFontPrivate::detachButKeepEngineData(this); | - |
1584 | | - |
1585 | d->wordSpacing = newSpacing; | - |
1586 | resolve_mask |= QFont::WordSpacingResolved; | - |
1587 | } | - |
1588 | | - |
1589 | /*! | - |
1590 | \enum QFont::Capitalization | - |
1591 | \since 4.4 | - |
1592 | | - |
1593 | Rendering option for text this font applies to. | - |
1594 | | - |
1595 | | - |
1596 | \value MixedCase This is the normal text rendering option where no capitalization change is applied. | - |
1597 | \value AllUppercase This alters the text to be rendered in all uppercase type. | - |
1598 | \value AllLowercase This alters the text to be rendered in all lowercase type. | - |
1599 | \value SmallCaps This alters the text to be rendered in small-caps type. | - |
1600 | \value Capitalize This alters the text to be rendered with the first character of each word as an uppercase character. | - |
1601 | */ | - |
1602 | | - |
1603 | /*! | - |
1604 | \since 4.4 | - |
1605 | Sets the capitalization of the text in this font to \a caps. | - |
1606 | | - |
1607 | A font's capitalization makes the text appear in the selected capitalization mode. | - |
1608 | | - |
1609 | \sa capitalization() | - |
1610 | */ | - |
1611 | void QFont::setCapitalization(Capitalization caps) | - |
1612 | { | - |
1613 | if ((resolve_mask & QFont::CapitalizationResolved) && | - |
1614 | capitalization() == caps) | - |
1615 | return; | - |
1616 | | - |
1617 | QFontPrivate::detachButKeepEngineData(this); | - |
1618 | | - |
1619 | d->capital = caps; | - |
1620 | resolve_mask |= QFont::CapitalizationResolved; | - |
1621 | } | - |
1622 | | - |
1623 | /*! | - |
1624 | \since 4.4 | - |
1625 | Returns the current capitalization type of the font. | - |
1626 | | - |
1627 | \sa setCapitalization() | - |
1628 | */ | - |
1629 | QFont::Capitalization QFont::capitalization() const | - |
1630 | { | - |
1631 | return static_cast<QFont::Capitalization> (d->capital); | - |
1632 | } | - |
1633 | | - |
1634 | | - |
1635 | /*! | - |
1636 | If \a enable is true, turns raw mode on; otherwise turns raw mode | - |
1637 | off. This function only has an effect under X11. | - |
1638 | | - |
1639 | If raw mode is enabled, Qt will search for an X font with a | - |
1640 | complete font name matching the family name, ignoring all other | - |
1641 | values set for the QFont. If the font name matches several fonts, | - |
1642 | Qt will use the first font returned by X. QFontInfo \e cannot be | - |
1643 | used to fetch information about a QFont using raw mode (it will | - |
1644 | return the values set in the QFont for all parameters, including | - |
1645 | the family name). | - |
1646 | | - |
1647 | \warning Do not use raw mode unless you really, really need it! In | - |
1648 | most (if not all) cases, setRawName() is a much better choice. | - |
1649 | | - |
1650 | \sa rawMode(), setRawName() | - |
1651 | */ | - |
1652 | void QFont::setRawMode(bool enable) | - |
1653 | { | - |
1654 | if ((bool) d->rawMode == enable) return; | - |
1655 | | - |
1656 | // might change behavior, thus destroy engine data | - |
1657 | detach(); | - |
1658 | | - |
1659 | d->rawMode = enable; | - |
1660 | } | - |
1661 | | - |
1662 | /*! | - |
1663 | Returns true if a window system font exactly matching the settings | - |
1664 | of this font is available. | - |
1665 | | - |
1666 | \sa QFontInfo | - |
1667 | */ | - |
1668 | bool QFont::exactMatch() const | - |
1669 | { | - |
1670 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
1671 | Q_ASSERT(engine != 0); | - |
1672 | return (d->rawMode | - |
1673 | ? engine->type() != QFontEngine::Box | - |
1674 | : d->request.exactMatch(engine->fontDef)); | - |
1675 | } | - |
1676 | | - |
1677 | /*! | - |
1678 | Returns true if this font is equal to \a f; otherwise returns | - |
1679 | false. | - |
1680 | | - |
1681 | Two QFonts are considered equal if their font attributes are | - |
1682 | equal. If rawMode() is enabled for both fonts, only the family | - |
1683 | fields are compared. | - |
1684 | | - |
1685 | \sa operator!=(), isCopyOf() | - |
1686 | */ | - |
1687 | bool QFont::operator==(const QFont &f) const | - |
1688 | { | - |
1689 | return (f.d == d | - |
1690 | || (f.d->request == d->request | - |
1691 | && f.d->request.pointSize == d->request.pointSize | - |
1692 | && f.d->underline == d->underline | - |
1693 | && f.d->overline == d->overline | - |
1694 | && f.d->strikeOut == d->strikeOut | - |
1695 | && f.d->kerning == d->kerning | - |
1696 | && f.d->capital == d->capital | - |
1697 | && f.d->letterSpacingIsAbsolute == d->letterSpacingIsAbsolute | - |
1698 | && f.d->letterSpacing == d->letterSpacing | - |
1699 | && f.d->wordSpacing == d->wordSpacing | - |
1700 | )); | - |
1701 | } | - |
1702 | | - |
1703 | | - |
1704 | /*! | - |
1705 | Provides an arbitrary comparison of this font and font \a f. | - |
1706 | All that is guaranteed is that the operator returns false if both | - |
1707 | fonts are equal and that (f1 \< f2) == !(f2 \< f1) if the fonts | - |
1708 | are not equal. | - |
1709 | | - |
1710 | This function is useful in some circumstances, for example if you | - |
1711 | want to use QFont objects as keys in a QMap. | - |
1712 | | - |
1713 | \sa operator==(), operator!=(), isCopyOf() | - |
1714 | */ | - |
1715 | bool QFont::operator<(const QFont &f) const | - |
1716 | { | - |
1717 | if (f.d == d) return false; | - |
1718 | // the < operator for fontdefs ignores point sizes. | - |
1719 | QFontDef &r1 = f.d->request; | - |
1720 | QFontDef &r2 = d->request; | - |
1721 | if (r1.pointSize != r2.pointSize) return r1.pointSize < r2.pointSize; | - |
1722 | if (r1.pixelSize != r2.pixelSize) return r1.pixelSize < r2.pixelSize; | - |
1723 | if (r1.weight != r2.weight) return r1.weight < r2.weight; | - |
1724 | if (r1.style != r2.style) return r1.style < r2.style; | - |
1725 | if (r1.stretch != r2.stretch) return r1.stretch < r2.stretch; | - |
1726 | if (r1.styleHint != r2.styleHint) return r1.styleHint < r2.styleHint; | - |
1727 | if (r1.styleStrategy != r2.styleStrategy) return r1.styleStrategy < r2.styleStrategy; | - |
1728 | if (r1.family != r2.family) return r1.family < r2.family; | - |
1729 | if (f.d->capital != d->capital) return f.d->capital < d->capital; | - |
1730 | | - |
1731 | if (f.d->letterSpacingIsAbsolute != d->letterSpacingIsAbsolute) return f.d->letterSpacingIsAbsolute < d->letterSpacingIsAbsolute; | - |
1732 | if (f.d->letterSpacing != d->letterSpacing) return f.d->letterSpacing < d->letterSpacing; | - |
1733 | if (f.d->wordSpacing != d->wordSpacing) return f.d->wordSpacing < d->wordSpacing; | - |
1734 | | - |
1735 | int f1attrs = (f.d->underline << 3) + (f.d->overline << 2) + (f.d->strikeOut<<1) + f.d->kerning; | - |
1736 | int f2attrs = (d->underline << 3) + (d->overline << 2) + (d->strikeOut<<1) + d->kerning; | - |
1737 | return f1attrs < f2attrs; | - |
1738 | } | - |
1739 | | - |
1740 | | - |
1741 | /*! | - |
1742 | Returns true if this font is different from \a f; otherwise | - |
1743 | returns false. | - |
1744 | | - |
1745 | Two QFonts are considered to be different if their font attributes | - |
1746 | are different. If rawMode() is enabled for both fonts, only the | - |
1747 | family fields are compared. | - |
1748 | | - |
1749 | \sa operator==() | - |
1750 | */ | - |
1751 | bool QFont::operator!=(const QFont &f) const | - |
1752 | { | - |
1753 | return !(operator==(f)); | - |
1754 | } | - |
1755 | | - |
1756 | /*! | - |
1757 | Returns the font as a QVariant | - |
1758 | */ | - |
1759 | QFont::operator QVariant() const | - |
1760 | { | - |
1761 | return QVariant(QVariant::Font, this); | - |
1762 | } | - |
1763 | | - |
1764 | /*! | - |
1765 | Returns true if this font and \a f are copies of each other, i.e. | - |
1766 | one of them was created as a copy of the other and neither has | - |
1767 | been modified since. This is much stricter than equality. | - |
1768 | | - |
1769 | \sa operator=(), operator==() | - |
1770 | */ | - |
1771 | bool QFont::isCopyOf(const QFont & f) const | - |
1772 | { | - |
1773 | return d == f.d; | - |
1774 | } | - |
1775 | | - |
1776 | /*! | - |
1777 | Returns true if raw mode is used for font name matching; otherwise | - |
1778 | returns false. | - |
1779 | | - |
1780 | \sa setRawMode(), rawName() | - |
1781 | */ | - |
1782 | bool QFont::rawMode() const | - |
1783 | { | - |
1784 | return d->rawMode; | - |
1785 | } | - |
1786 | | - |
1787 | /*! | - |
1788 | Returns a new QFont that has attributes copied from \a other that | - |
1789 | have not been previously set on this font. | - |
1790 | */ | - |
1791 | QFont QFont::resolve(const QFont &other) const | - |
1792 | { | - |
1793 | if (*this == other | - |
1794 | && (resolve_mask == other.resolve_mask || resolve_mask == 0) | - |
1795 | && d->dpi == other.d->dpi) { | - |
1796 | QFont o = other; | - |
1797 | o.resolve_mask = resolve_mask; | - |
1798 | return o; | - |
1799 | } | - |
1800 | | - |
1801 | QFont font(*this); | - |
1802 | font.detach(); | - |
1803 | font.d->resolve(resolve_mask, other.d.data()); | - |
1804 | | - |
1805 | return font; | - |
1806 | } | - |
1807 | | - |
1808 | /*! | - |
1809 | \fn uint QFont::resolve() const | - |
1810 | \internal | - |
1811 | */ | - |
1812 | | - |
1813 | /*! | - |
1814 | \fn void QFont::resolve(uint mask) | - |
1815 | \internal | - |
1816 | */ | - |
1817 | | - |
1818 | | - |
1819 | /***************************************************************************** | - |
1820 | QFont substitution management | - |
1821 | *****************************************************************************/ | - |
1822 | | - |
1823 | typedef QHash<QString, QStringList> QFontSubst; | - |
1824 | Q_GLOBAL_STATIC(QFontSubst, globalFontSubst) | - |
1825 | | - |
1826 | /*! | - |
1827 | Returns the first family name to be used whenever \a familyName is | - |
1828 | specified. The lookup is case insensitive. | - |
1829 | | - |
1830 | If there is no substitution for \a familyName, \a familyName is | - |
1831 | returned. | - |
1832 | | - |
1833 | To obtain a list of substitutions use substitutes(). | - |
1834 | | - |
1835 | \sa setFamily(), insertSubstitutions(), insertSubstitution(), removeSubstitutions() | - |
1836 | */ | - |
1837 | QString QFont::substitute(const QString &familyName) | - |
1838 | { | - |
1839 | QFontSubst *fontSubst = globalFontSubst(); | - |
1840 | Q_ASSERT(fontSubst != 0); | - |
1841 | QFontSubst::ConstIterator it = fontSubst->constFind(familyName.toLower()); | - |
1842 | if (it != fontSubst->constEnd() && !(*it).isEmpty()) | - |
1843 | return (*it).first(); | - |
1844 | | - |
1845 | return familyName; | - |
1846 | } | - |
1847 | | - |
1848 | | - |
1849 | /*! | - |
1850 | Returns a list of family names to be used whenever \a familyName | - |
1851 | is specified. The lookup is case insensitive. | - |
1852 | | - |
1853 | If there is no substitution for \a familyName, an empty list is | - |
1854 | returned. | - |
1855 | | - |
1856 | \sa substitute(), insertSubstitutions(), insertSubstitution(), removeSubstitutions() | - |
1857 | */ | - |
1858 | QStringList QFont::substitutes(const QString &familyName) | - |
1859 | { | - |
1860 | QFontSubst *fontSubst = globalFontSubst(); | - |
1861 | Q_ASSERT(fontSubst != 0); | - |
1862 | return fontSubst->value(familyName.toLower(), QStringList()); | - |
1863 | } | - |
1864 | | - |
1865 | | - |
1866 | /*! | - |
1867 | Inserts \a substituteName into the substitution | - |
1868 | table for the family \a familyName. | - |
1869 | | - |
1870 | \sa insertSubstitutions(), removeSubstitutions(), substitutions(), substitute(), substitutes() | - |
1871 | */ | - |
1872 | void QFont::insertSubstitution(const QString &familyName, | - |
1873 | const QString &substituteName) | - |
1874 | { | - |
1875 | QFontSubst *fontSubst = globalFontSubst(); | - |
1876 | Q_ASSERT(fontSubst != 0); | - |
1877 | QStringList &list = (*fontSubst)[familyName.toLower()]; | - |
1878 | QString s = substituteName.toLower(); | - |
1879 | if (!list.contains(s)) | - |
1880 | list.append(s); | - |
1881 | } | - |
1882 | | - |
1883 | | - |
1884 | /*! | - |
1885 | Inserts the list of families \a substituteNames into the | - |
1886 | substitution list for \a familyName. | - |
1887 | | - |
1888 | \sa insertSubstitution(), removeSubstitutions(), substitutions(), substitute() | - |
1889 | */ | - |
1890 | void QFont::insertSubstitutions(const QString &familyName, | - |
1891 | const QStringList &substituteNames) | - |
1892 | { | - |
1893 | QFontSubst *fontSubst = globalFontSubst(); | - |
1894 | Q_ASSERT(fontSubst != 0); | - |
1895 | QStringList &list = (*fontSubst)[familyName.toLower()]; | - |
1896 | foreach (const QString &substituteName, substituteNames) { | - |
1897 | const QString lowerSubstituteName = substituteName.toLower(); | - |
1898 | if (!list.contains(lowerSubstituteName)) | - |
1899 | list.append(lowerSubstituteName); | - |
1900 | } | - |
1901 | } | - |
1902 | | - |
1903 | /*! \fn void QFont::initialize() | - |
1904 | \internal | - |
1905 | | - |
1906 | Internal function that initializes the font system. The font cache | - |
1907 | and font dict do not alloc the keys. The key is a QString which is | - |
1908 | shared between QFontPrivate and QXFontName. | - |
1909 | */ | - |
1910 | | - |
1911 | /*! \fn void QFont::cleanup() | - |
1912 | \internal | - |
1913 | | - |
1914 | Internal function that cleans up the font system. | - |
1915 | */ | - |
1916 | | - |
1917 | /*! | - |
1918 | Removes all the substitutions for \a familyName. | - |
1919 | | - |
1920 | \sa insertSubstitutions(), insertSubstitution(), substitutions(), substitute() | - |
1921 | \since 5.0 | - |
1922 | */ | - |
1923 | void QFont::removeSubstitutions(const QString &familyName) | - |
1924 | { | - |
1925 | QFontSubst *fontSubst = globalFontSubst(); | - |
1926 | Q_ASSERT(fontSubst != 0); | - |
1927 | fontSubst->remove(familyName.toLower()); | - |
1928 | } | - |
1929 | | - |
1930 | /*! | - |
1931 | \fn void QFont::removeSubstitution(const QString &familyName) | - |
1932 | | - |
1933 | \obsolete | - |
1934 | | - |
1935 | This function is deprecated. Use removeSubstitutions() instead. | - |
1936 | */ | - |
1937 | | - |
1938 | /*! | - |
1939 | Returns a sorted list of substituted family names. | - |
1940 | | - |
1941 | \sa insertSubstitution(), removeSubstitution(), substitute() | - |
1942 | */ | - |
1943 | QStringList QFont::substitutions() | - |
1944 | { | - |
1945 | typedef QFontSubst::const_iterator QFontSubstConstIterator; | - |
1946 | | - |
1947 | QFontSubst *fontSubst = globalFontSubst(); | - |
1948 | Q_ASSERT(fontSubst != 0); | - |
1949 | QStringList ret; | - |
1950 | const QFontSubstConstIterator cend = fontSubst->constEnd(); | - |
1951 | for (QFontSubstConstIterator it = fontSubst->constBegin(); it != cend; ++it) | - |
1952 | ret.append(it.key()); | - |
1953 | | - |
1954 | ret.sort(); | - |
1955 | return ret; | - |
1956 | } | - |
1957 | | - |
1958 | | - |
1959 | /* \internal | - |
1960 | Internal function. Converts boolean font settings to an unsigned | - |
1961 | 8-bit number. Used for serialization etc. | - |
1962 | */ | - |
1963 | static quint8 get_font_bits(int version, const QFontPrivate *f) | - |
1964 | { | - |
1965 | Q_ASSERT(f != 0); | - |
1966 | quint8 bits = 0; | - |
1967 | if (f->request.style) | - |
1968 | bits |= 0x01; | - |
1969 | if (f->underline) | - |
1970 | bits |= 0x02; | - |
1971 | if (f->overline) | - |
1972 | bits |= 0x40; | - |
1973 | if (f->strikeOut) | - |
1974 | bits |= 0x04; | - |
1975 | if (f->request.fixedPitch) | - |
1976 | bits |= 0x08; | - |
1977 | // if (f.hintSetByUser) | - |
1978 | // bits |= 0x10; | - |
1979 | if (f->rawMode) | - |
1980 | bits |= 0x20; | - |
1981 | if (version >= QDataStream::Qt_4_0) { | - |
1982 | if (f->kerning) | - |
1983 | bits |= 0x10; | - |
1984 | } | - |
1985 | if (f->request.style == QFont::StyleOblique) | - |
1986 | bits |= 0x80; | - |
1987 | return bits; | - |
1988 | } | - |
1989 | | - |
1990 | static quint8 get_extended_font_bits(const QFontPrivate *f) | - |
1991 | { | - |
1992 | Q_ASSERT(f != 0); | - |
1993 | quint8 bits = 0; | - |
1994 | if (f->request.ignorePitch) | - |
1995 | bits |= 0x01; | - |
1996 | if (f->letterSpacingIsAbsolute) | - |
1997 | bits |= 0x02; | - |
1998 | return bits; | - |
1999 | } | - |
2000 | | - |
2001 | #ifndef QT_NO_DATASTREAM | - |
2002 | | - |
2003 | /* \internal | - |
2004 | Internal function. Sets boolean font settings from an unsigned | - |
2005 | 8-bit number. Used for serialization etc. | - |
2006 | */ | - |
2007 | static void set_font_bits(int version, quint8 bits, QFontPrivate *f) | - |
2008 | { | - |
2009 | Q_ASSERT(f != 0); | - |
2010 | f->request.style = (bits & 0x01) != 0 ? QFont::StyleItalic : QFont::StyleNormal; | - |
2011 | f->underline = (bits & 0x02) != 0; | - |
2012 | f->overline = (bits & 0x40) != 0; | - |
2013 | f->strikeOut = (bits & 0x04) != 0; | - |
2014 | f->request.fixedPitch = (bits & 0x08) != 0; | - |
2015 | // f->hintSetByUser = (bits & 0x10) != 0; | - |
2016 | f->rawMode = (bits & 0x20) != 0; | - |
2017 | if (version >= QDataStream::Qt_4_0) | - |
2018 | f->kerning = (bits & 0x10) != 0; | - |
2019 | if ((bits & 0x80) != 0) | - |
2020 | f->request.style = QFont::StyleOblique; | - |
2021 | } | - |
2022 | | - |
2023 | static void set_extended_font_bits(quint8 bits, QFontPrivate *f) | - |
2024 | { | - |
2025 | Q_ASSERT(f != 0); | - |
2026 | f->request.ignorePitch = (bits & 0x01) != 0; | - |
2027 | f->letterSpacingIsAbsolute = (bits & 0x02) != 0; | - |
2028 | } | - |
2029 | #endif | - |
2030 | | - |
2031 | | - |
2032 | /*! | - |
2033 | Returns the font's key, a textual representation of a font. It is | - |
2034 | typically used as the key for a cache or dictionary of fonts. | - |
2035 | | - |
2036 | \sa QMap | - |
2037 | */ | - |
2038 | QString QFont::key() const | - |
2039 | { | - |
2040 | return toString(); | - |
2041 | } | - |
2042 | | - |
2043 | /*! | - |
2044 | Returns a description of the font. The description is a | - |
2045 | comma-separated list of the attributes, perfectly suited for use | - |
2046 | in QSettings. | - |
2047 | | - |
2048 | \sa fromString() | - |
2049 | */ | - |
2050 | QString QFont::toString() const | - |
2051 | { | - |
2052 | const QChar comma(QLatin1Char(',')); | - |
2053 | return family() + comma + | - |
2054 | QString::number( pointSizeF()) + comma + | - |
2055 | QString::number( pixelSize()) + comma + | - |
2056 | QString::number((int) styleHint()) + comma + | - |
2057 | QString::number( weight()) + comma + | - |
2058 | QString::number((int) style()) + comma + | - |
2059 | QString::number((int) underline()) + comma + | - |
2060 | QString::number((int) strikeOut()) + comma + | - |
2061 | QString::number((int)fixedPitch()) + comma + | - |
2062 | QString::number((int) rawMode()); | - |
2063 | } | - |
2064 | | - |
2065 | | - |
2066 | /*! | - |
2067 | Sets this font to match the description \a descrip. The description | - |
2068 | is a comma-separated list of the font attributes, as returned by | - |
2069 | toString(). | - |
2070 | | - |
2071 | \sa toString() | - |
2072 | */ | - |
2073 | bool QFont::fromString(const QString &descrip) | - |
2074 | { | - |
2075 | QStringList l(descrip.split(QLatin1Char(','))); | - |
2076 | | - |
2077 | int count = l.count(); | - |
2078 | if (!count || (count > 2 && count < 9) || count > 11) { | - |
2079 | qWarning("QFont::fromString: Invalid description '%s'", | - |
2080 | descrip.isEmpty() ? "(empty)" : descrip.toLatin1().data()); | - |
2081 | return false; | - |
2082 | } | - |
2083 | | - |
2084 | setFamily(l[0]); | - |
2085 | if (count > 1 && l[1].toDouble() > 0.0) | - |
2086 | setPointSizeF(l[1].toDouble()); | - |
2087 | if (count == 9) { | - |
2088 | setStyleHint((StyleHint) l[2].toInt()); | - |
2089 | setWeight(qMax(qMin(99, l[3].toInt()), 0)); | - |
2090 | setItalic(l[4].toInt()); | - |
2091 | setUnderline(l[5].toInt()); | - |
2092 | setStrikeOut(l[6].toInt()); | - |
2093 | setFixedPitch(l[7].toInt()); | - |
2094 | setRawMode(l[8].toInt()); | - |
2095 | } else if (count == 10) { | - |
2096 | if (l[2].toInt() > 0) | - |
2097 | setPixelSize(l[2].toInt()); | - |
2098 | setStyleHint((StyleHint) l[3].toInt()); | - |
2099 | setWeight(qMax(qMin(99, l[4].toInt()), 0)); | - |
2100 | setStyle((QFont::Style)l[5].toInt()); | - |
2101 | setUnderline(l[6].toInt()); | - |
2102 | setStrikeOut(l[7].toInt()); | - |
2103 | setFixedPitch(l[8].toInt()); | - |
2104 | setRawMode(l[9].toInt()); | - |
2105 | } | - |
2106 | if (count >= 9 && !d->request.fixedPitch) // assume 'false' fixedPitch equals default | - |
2107 | d->request.ignorePitch = true; | - |
2108 | | - |
2109 | return true; | - |
2110 | } | - |
2111 | | - |
2112 | /*! \internal | - |
2113 | | - |
2114 | Internal function that dumps font cache statistics. | - |
2115 | */ | - |
2116 | void QFont::cacheStatistics() | - |
2117 | { | - |
2118 | | - |
2119 | | - |
2120 | } | - |
2121 | | - |
2122 | | - |
2123 | | - |
2124 | /***************************************************************************** | - |
2125 | QFont stream functions | - |
2126 | *****************************************************************************/ | - |
2127 | #ifndef QT_NO_DATASTREAM | - |
2128 | | - |
2129 | /*! | - |
2130 | \relates QFont | - |
2131 | | - |
2132 | Writes the font \a font to the data stream \a s. (toString() | - |
2133 | writes to a text stream.) | - |
2134 | | - |
2135 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - |
2136 | */ | - |
2137 | QDataStream &operator<<(QDataStream &s, const QFont &font) | - |
2138 | { | - |
2139 | if (s.version() == 1) { | - |
2140 | s << font.d->request.family.toLatin1(); | - |
2141 | } else { | - |
2142 | s << font.d->request.family; | - |
2143 | } | - |
2144 | | - |
2145 | if (s.version() >= QDataStream::Qt_4_0) { | - |
2146 | // 4.0 | - |
2147 | double pointSize = font.d->request.pointSize; | - |
2148 | qint32 pixelSize = font.d->request.pixelSize; | - |
2149 | s << pointSize; | - |
2150 | s << pixelSize; | - |
2151 | } else if (s.version() <= 3) { | - |
2152 | qint16 pointSize = (qint16) (font.d->request.pointSize * 10); | - |
2153 | if (pointSize < 0) { | - |
2154 | pointSize = (qint16)QFontInfo(font).pointSize() * 10; | - |
2155 | } | - |
2156 | s << pointSize; | - |
2157 | } else { | - |
2158 | s << (qint16) (font.d->request.pointSize * 10); | - |
2159 | s << (qint16) font.d->request.pixelSize; | - |
2160 | } | - |
2161 | | - |
2162 | s << (quint8) font.d->request.styleHint; | - |
2163 | if (s.version() >= QDataStream::Qt_3_1) | - |
2164 | s << (quint8) font.d->request.styleStrategy; | - |
2165 | s << (quint8) 0 | - |
2166 | << (quint8) font.d->request.weight | - |
2167 | << get_font_bits(s.version(), font.d.data()); | - |
2168 | if (s.version() >= QDataStream::Qt_4_3) | - |
2169 | s << (quint16)font.d->request.stretch; | - |
2170 | if (s.version() >= QDataStream::Qt_4_4) | - |
2171 | s << get_extended_font_bits(font.d.data()); | - |
2172 | if (s.version() >= QDataStream::Qt_4_5) { | - |
2173 | s << font.d->letterSpacing.value(); | - |
2174 | s << font.d->wordSpacing.value(); | - |
2175 | } | - |
2176 | return s; | - |
2177 | } | - |
2178 | | - |
2179 | | - |
2180 | /*! | - |
2181 | \relates QFont | - |
2182 | | - |
2183 | Reads the font \a font from the data stream \a s. (fromString() | - |
2184 | reads from a text stream.) | - |
2185 | | - |
2186 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - |
2187 | */ | - |
2188 | QDataStream &operator>>(QDataStream &s, QFont &font) | - |
2189 | { | - |
2190 | font.d = new QFontPrivate; | - |
2191 | font.resolve_mask = QFont::AllPropertiesResolved; | - |
2192 | | - |
2193 | quint8 styleHint, styleStrategy = QFont::PreferDefault, charSet, weight, bits; | - |
2194 | | - |
2195 | if (s.version() == 1) { | - |
2196 | QByteArray fam; | - |
2197 | s >> fam; | - |
2198 | font.d->request.family = QString::fromLatin1(fam); | - |
2199 | } else { | - |
2200 | s >> font.d->request.family; | - |
2201 | } | - |
2202 | | - |
2203 | if (s.version() >= QDataStream::Qt_4_0) { | - |
2204 | // 4.0 | - |
2205 | double pointSize; | - |
2206 | qint32 pixelSize; | - |
2207 | s >> pointSize; | - |
2208 | s >> pixelSize; | - |
2209 | font.d->request.pointSize = qreal(pointSize); | - |
2210 | font.d->request.pixelSize = pixelSize; | - |
2211 | } else { | - |
2212 | qint16 pointSize, pixelSize = -1; | - |
2213 | s >> pointSize; | - |
2214 | if (s.version() >= 4) | - |
2215 | s >> pixelSize; | - |
2216 | font.d->request.pointSize = qreal(pointSize / 10.); | - |
2217 | font.d->request.pixelSize = pixelSize; | - |
2218 | } | - |
2219 | s >> styleHint; | - |
2220 | if (s.version() >= QDataStream::Qt_3_1) | - |
2221 | s >> styleStrategy; | - |
2222 | | - |
2223 | s >> charSet; | - |
2224 | s >> weight; | - |
2225 | s >> bits; | - |
2226 | | - |
2227 | font.d->request.styleHint = styleHint; | - |
2228 | font.d->request.styleStrategy = styleStrategy; | - |
2229 | font.d->request.weight = weight; | - |
2230 | | - |
2231 | set_font_bits(s.version(), bits, font.d.data()); | - |
2232 | | - |
2233 | if (s.version() >= QDataStream::Qt_4_3) { | - |
2234 | quint16 stretch; | - |
2235 | s >> stretch; | - |
2236 | font.d->request.stretch = stretch; | - |
2237 | } | - |
2238 | | - |
2239 | if (s.version() >= QDataStream::Qt_4_4) { | - |
2240 | quint8 extendedBits; | - |
2241 | s >> extendedBits; | - |
2242 | set_extended_font_bits(extendedBits, font.d.data()); | - |
2243 | } | - |
2244 | if (s.version() >= QDataStream::Qt_4_5) { | - |
2245 | int value; | - |
2246 | s >> value; | - |
2247 | font.d->letterSpacing.setValue(value); | - |
2248 | s >> value; | - |
2249 | font.d->wordSpacing.setValue(value); | - |
2250 | } | - |
2251 | | - |
2252 | return s; | - |
2253 | } | - |
2254 | | - |
2255 | #endif // QT_NO_DATASTREAM | - |
2256 | | - |
2257 | | - |
2258 | /***************************************************************************** | - |
2259 | QFontInfo member functions | - |
2260 | *****************************************************************************/ | - |
2261 | | - |
2262 | /*! | - |
2263 | \class QFontInfo | - |
2264 | \reentrant | - |
2265 | | - |
2266 | \brief The QFontInfo class provides general information about fonts. | - |
2267 | \inmodule QtGui | - |
2268 | | - |
2269 | \ingroup appearance | - |
2270 | \ingroup shared | - |
2271 | | - |
2272 | The QFontInfo class provides the same access functions as QFont, | - |
2273 | e.g. family(), pointSize(), italic(), weight(), fixedPitch(), | - |
2274 | styleHint() etc. But whilst the QFont access functions return the | - |
2275 | values that were set, a QFontInfo object returns the values that | - |
2276 | apply to the font that will actually be used to draw the text. | - |
2277 | | - |
2278 | For example, when the program asks for a 25pt Courier font on a | - |
2279 | machine that has a non-scalable 24pt Courier font, QFont will | - |
2280 | (normally) use the 24pt Courier for rendering. In this case, | - |
2281 | QFont::pointSize() returns 25 and QFontInfo::pointSize() returns | - |
2282 | 24. | - |
2283 | | - |
2284 | There are three ways to create a QFontInfo object. | - |
2285 | \list 1 | - |
2286 | \li Calling the QFontInfo constructor with a QFont creates a font | - |
2287 | info object for a screen-compatible font, i.e. the font cannot be | - |
2288 | a printer font. If the font is changed later, the font | - |
2289 | info object is \e not updated. | - |
2290 | | - |
2291 | (Note: If you use a printer font the values returned may be | - |
2292 | inaccurate. Printer fonts are not always accessible so the nearest | - |
2293 | screen font is used if a printer font is supplied.) | - |
2294 | | - |
2295 | \li QWidget::fontInfo() returns the font info for a widget's font. | - |
2296 | This is equivalent to calling QFontInfo(widget->font()). If the | - |
2297 | widget's font is changed later, the font info object is \e not | - |
2298 | updated. | - |
2299 | | - |
2300 | \li QPainter::fontInfo() returns the font info for a painter's | - |
2301 | current font. If the painter's font is changed later, the font | - |
2302 | info object is \e not updated. | - |
2303 | \endlist | - |
2304 | | - |
2305 | \sa QFont, QFontMetrics, QFontDatabase | - |
2306 | */ | - |
2307 | | - |
2308 | /*! | - |
2309 | Constructs a font info object for \a font. | - |
2310 | | - |
2311 | The font must be screen-compatible, i.e. a font you use when | - |
2312 | drawing text in \l{QWidget}{widgets} or \l{QPixmap}{pixmaps}, not QPicture or QPrinter. | - |
2313 | | - |
2314 | The font info object holds the information for the font that is | - |
2315 | passed in the constructor at the time it is created, and is not | - |
2316 | updated if the font's attributes are changed later. | - |
2317 | | - |
2318 | Use QPainter::fontInfo() to get the font info when painting. | - |
2319 | This will give correct results also when painting on paint device | - |
2320 | that is not screen-compatible. | - |
2321 | */ | - |
2322 | QFontInfo::QFontInfo(const QFont &font) | - |
2323 | : d(font.d.data()) | - |
2324 | { | - |
2325 | } | - |
2326 | | - |
2327 | /*! | - |
2328 | Constructs a copy of \a fi. | - |
2329 | */ | - |
2330 | QFontInfo::QFontInfo(const QFontInfo &fi) | - |
2331 | : d(fi.d.data()) | - |
2332 | { | - |
2333 | } | - |
2334 | | - |
2335 | /*! | - |
2336 | Destroys the font info object. | - |
2337 | */ | - |
2338 | QFontInfo::~QFontInfo() | - |
2339 | { | - |
2340 | } | - |
2341 | | - |
2342 | /*! | - |
2343 | Assigns the font info in \a fi. | - |
2344 | */ | - |
2345 | QFontInfo &QFontInfo::operator=(const QFontInfo &fi) | - |
2346 | { | - |
2347 | d = fi.d.data(); | - |
2348 | return *this; | - |
2349 | } | - |
2350 | | - |
2351 | /*! | - |
2352 | \fn void QFontInfo::swap(QFontInfo &other) | - |
2353 | \since 5.0 | - |
2354 | | - |
2355 | Swaps this font info instance with \a other. This function is very | - |
2356 | fast and never fails. | - |
2357 | */ | - |
2358 | | - |
2359 | /*! | - |
2360 | Returns the family name of the matched window system font. | - |
2361 | | - |
2362 | \sa QFont::family() | - |
2363 | */ | - |
2364 | QString QFontInfo::family() const | - |
2365 | { | - |
2366 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
2367 | Q_ASSERT(engine != 0); | - |
2368 | return engine->fontDef.family; | - |
2369 | } | - |
2370 | | - |
2371 | /*! | - |
2372 | \since 4.8 | - |
2373 | | - |
2374 | Returns the style name of the matched window system font on | - |
2375 | system that supports it. | - |
2376 | | - |
2377 | \sa QFont::styleName() | - |
2378 | */ | - |
2379 | QString QFontInfo::styleName() const | - |
2380 | { | - |
2381 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
2382 | Q_ASSERT(engine != 0); | - |
2383 | return engine->fontDef.styleName; | - |
2384 | } | - |
2385 | | - |
2386 | /*! | - |
2387 | Returns the point size of the matched window system font. | - |
2388 | | - |
2389 | \sa pointSizeF(), QFont::pointSize() | - |
2390 | */ | - |
2391 | int QFontInfo::pointSize() const | - |
2392 | { | - |
2393 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
2394 | Q_ASSERT(engine != 0); | - |
2395 | return qRound(engine->fontDef.pointSize); | - |
2396 | } | - |
2397 | | - |
2398 | /*! | - |
2399 | Returns the point size of the matched window system font. | - |
2400 | | - |
2401 | \sa QFont::pointSizeF() | - |
2402 | */ | - |
2403 | qreal QFontInfo::pointSizeF() const | - |
2404 | { | - |
2405 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
2406 | Q_ASSERT(engine != 0); | - |
2407 | return engine->fontDef.pointSize; | - |
2408 | } | - |
2409 | | - |
2410 | /*! | - |
2411 | Returns the pixel size of the matched window system font. | - |
2412 | | - |
2413 | \sa QFont::pointSize() | - |
2414 | */ | - |
2415 | int QFontInfo::pixelSize() const | - |
2416 | { | - |
2417 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
2418 | Q_ASSERT(engine != 0); | - |
2419 | return engine->fontDef.pixelSize; | - |
2420 | } | - |
2421 | | - |
2422 | /*! | - |
2423 | Returns the italic value of the matched window system font. | - |
2424 | | - |
2425 | \sa QFont::italic() | - |
2426 | */ | - |
2427 | bool QFontInfo::italic() const | - |
2428 | { | - |
2429 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
2430 | Q_ASSERT(engine != 0); | - |
2431 | return engine->fontDef.style != QFont::StyleNormal; | - |
2432 | } | - |
2433 | | - |
2434 | /*! | - |
2435 | Returns the style value of the matched window system font. | - |
2436 | | - |
2437 | \sa QFont::style() | - |
2438 | */ | - |
2439 | QFont::Style QFontInfo::style() const | - |
2440 | { | - |
2441 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
2442 | Q_ASSERT(engine != 0); | - |
2443 | return (QFont::Style)engine->fontDef.style; | - |
2444 | } | - |
2445 | | - |
2446 | /*! | - |
2447 | Returns the weight of the matched window system font. | - |
2448 | | - |
2449 | \sa QFont::weight(), bold() | - |
2450 | */ | - |
2451 | int QFontInfo::weight() const | - |
2452 | { | - |
2453 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
2454 | Q_ASSERT(engine != 0); | - |
2455 | return engine->fontDef.weight; | - |
2456 | | - |
2457 | } | - |
2458 | | - |
2459 | /*! | - |
2460 | \fn bool QFontInfo::bold() const | - |
2461 | | - |
2462 | Returns true if weight() would return a value greater than | - |
2463 | QFont::Normal; otherwise returns false. | - |
2464 | | - |
2465 | \sa weight(), QFont::bold() | - |
2466 | */ | - |
2467 | | - |
2468 | /*! | - |
2469 | Returns the underline value of the matched window system font. | - |
2470 | | - |
2471 | \sa QFont::underline() | - |
2472 | | - |
2473 | \internal | - |
2474 | | - |
2475 | Here we read the underline flag directly from the QFont. | - |
2476 | This is OK for X11 and for Windows because we always get what we want. | - |
2477 | */ | - |
2478 | bool QFontInfo::underline() const | - |
2479 | { | - |
2480 | return d->underline; | - |
2481 | } | - |
2482 | | - |
2483 | /*! | - |
2484 | Returns the overline value of the matched window system font. | - |
2485 | | - |
2486 | \sa QFont::overline() | - |
2487 | | - |
2488 | \internal | - |
2489 | | - |
2490 | Here we read the overline flag directly from the QFont. | - |
2491 | This is OK for X11 and for Windows because we always get what we want. | - |
2492 | */ | - |
2493 | bool QFontInfo::overline() const | - |
2494 | { | - |
2495 | return d->overline; | - |
2496 | } | - |
2497 | | - |
2498 | /*! | - |
2499 | Returns the strikeout value of the matched window system font. | - |
2500 | | - |
2501 | \sa QFont::strikeOut() | - |
2502 | | - |
2503 | \internal Here we read the strikeOut flag directly from the QFont. | - |
2504 | This is OK for X11 and for Windows because we always get what we want. | - |
2505 | */ | - |
2506 | bool QFontInfo::strikeOut() const | - |
2507 | { | - |
2508 | return d->strikeOut; | - |
2509 | } | - |
2510 | | - |
2511 | /*! | - |
2512 | Returns the fixed pitch value of the matched window system font. | - |
2513 | | - |
2514 | \sa QFont::fixedPitch() | - |
2515 | */ | - |
2516 | bool QFontInfo::fixedPitch() const | - |
2517 | { | - |
2518 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
2519 | Q_ASSERT(engine != 0); | - |
2520 | #ifdef Q_OS_MAC | - |
2521 | if (!engine->fontDef.fixedPitchComputed) { | - |
2522 | QChar ch[2] = { QLatin1Char('i'), QLatin1Char('m') }; | - |
2523 | QGlyphLayoutArray<2> g; | - |
2524 | int l = 2; | - |
2525 | engine->stringToCMap(ch, 2, &g, &l, 0); | - |
2526 | engine->fontDef.fixedPitch = g.advances_x[0] == g.advances_x[1]; | - |
2527 | engine->fontDef.fixedPitchComputed = true; | - |
2528 | } | - |
2529 | #endif | - |
2530 | return engine->fontDef.fixedPitch; | - |
2531 | } | - |
2532 | | - |
2533 | /*! | - |
2534 | Returns the style of the matched window system font. | - |
2535 | | - |
2536 | Currently only returns the style hint set in QFont. | - |
2537 | | - |
2538 | \sa QFont::styleHint(), QFont::StyleHint | - |
2539 | */ | - |
2540 | QFont::StyleHint QFontInfo::styleHint() const | - |
2541 | { | - |
2542 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
2543 | Q_ASSERT(engine != 0); | - |
2544 | return (QFont::StyleHint) engine->fontDef.styleHint; | - |
2545 | } | - |
2546 | | - |
2547 | /*! | - |
2548 | Returns true if the font is a raw mode font; otherwise returns | - |
2549 | false. | - |
2550 | | - |
2551 | If it is a raw mode font, all other functions in QFontInfo will | - |
2552 | return the same values set in the QFont, regardless of the font | - |
2553 | actually used. | - |
2554 | | - |
2555 | \sa QFont::rawMode() | - |
2556 | */ | - |
2557 | bool QFontInfo::rawMode() const | - |
2558 | { | - |
2559 | return d->rawMode; | - |
2560 | } | - |
2561 | | - |
2562 | /*! | - |
2563 | Returns true if the matched window system font is exactly the same | - |
2564 | as the one specified by the font; otherwise returns false. | - |
2565 | | - |
2566 | \sa QFont::exactMatch() | - |
2567 | */ | - |
2568 | bool QFontInfo::exactMatch() const | - |
2569 | { | - |
2570 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
2571 | Q_ASSERT(engine != 0); | - |
2572 | return (d->rawMode | - |
2573 | ? engine->type() != QFontEngine::Box | - |
2574 | : d->request.exactMatch(engine->fontDef)); | - |
2575 | } | - |
2576 | | - |
2577 | | - |
2578 | | - |
2579 | | - |
2580 | // ********************************************************************** | - |
2581 | // QFontCache | - |
2582 | // ********************************************************************** | - |
2583 | | - |
2584 | #ifdef QFONTCACHE_DEBUG | - |
2585 | // fast timeouts for debugging | - |
2586 | static const int fast_timeout = 1000; // 1s | - |
2587 | static const int slow_timeout = 5000; // 5s | - |
2588 | #else | - |
2589 | static const int fast_timeout = 10000; // 10s | - |
2590 | static const int slow_timeout = 300000; // 5m | - |
2591 | #endif // QFONTCACHE_DEBUG | - |
2592 | | - |
2593 | const uint QFontCache::min_cost = 4*1024; // 4mb | - |
2594 | | - |
2595 | #ifdef QT_NO_THREAD | - |
2596 | Q_GLOBAL_STATIC(QFontCache, theFontCache) | - |
2597 | | - |
2598 | QFontCache *QFontCache::instance() | - |
2599 | { | - |
2600 | return theFontCache(); | - |
2601 | } | - |
2602 | | - |
2603 | void QFontCache::cleanup() | - |
2604 | { | - |
2605 | } | - |
2606 | #else | - |
2607 | Q_GLOBAL_STATIC(QThreadStorage<QFontCache *>, theFontCache) | - |
2608 | | - |
2609 | QFontCache *QFontCache::instance() | - |
2610 | { | - |
2611 | QFontCache *&fontCache = theFontCache()->localData(); | - |
2612 | if (!fontCache) | - |
2613 | fontCache = new QFontCache; | - |
2614 | return fontCache; | - |
2615 | } | - |
2616 | | - |
2617 | void QFontCache::cleanup() | - |
2618 | { | - |
2619 | QThreadStorage<QFontCache *> *cache = 0; | - |
2620 | QT_TRY { | - |
2621 | cache = theFontCache(); | - |
2622 | } QT_CATCH (const std::bad_alloc &) { | - |
2623 | // no cache - just ignore | - |
2624 | } | - |
2625 | if (cache && cache->hasLocalData()) | - |
2626 | cache->setLocalData(0); | - |
2627 | } | - |
2628 | #endif // QT_NO_THREAD | - |
2629 | | - |
2630 | QFontCache::QFontCache() | - |
2631 | : QObject(), total_cost(0), max_cost(min_cost), | - |
2632 | current_timestamp(0), fast(false), timer_id(-1) | - |
2633 | { | - |
2634 | } | - |
2635 | | - |
2636 | QFontCache::~QFontCache() | - |
2637 | { | - |
2638 | clear(); | - |
2639 | { | - |
2640 | EngineDataCache::ConstIterator it = engineDataCache.constBegin(), | - |
2641 | end = engineDataCache.constEnd(); | - |
2642 | while (it != end) { | - |
2643 | if (it.value()->ref.load() == 0) | - |
2644 | delete it.value(); | - |
2645 | else | - |
2646 | FC_DEBUG("QFontCache::~QFontCache: engineData %p still has refcount %d", | - |
2647 | it.value(), it.value()->ref.load()); | - |
2648 | ++it; | - |
2649 | } | - |
2650 | } | - |
2651 | EngineCache::ConstIterator it = engineCache.constBegin(), | - |
2652 | end = engineCache.constEnd(); | - |
2653 | while (it != end) { | - |
2654 | if (--it.value().data->cache_count == 0) { | - |
2655 | if (it.value().data->ref.load() == 0) { | - |
2656 | FC_DEBUG("QFontCache::~QFontCache: deleting engine %p key=(%d / %g %g %d %d %d)", | - |
2657 | it.value().data, it.key().script, it.key().def.pointSize, | - |
2658 | it.key().def.pixelSize, it.key().def.weight, it.key().def.style, | - |
2659 | it.key().def.fixedPitch); | - |
2660 | | - |
2661 | delete it.value().data; | - |
2662 | } else { | - |
2663 | FC_DEBUG("QFontCache::~QFontCache: engine = %p still has refcount %d", | - |
2664 | it.value().data, it.value().data->ref.load()); | - |
2665 | } | - |
2666 | } | - |
2667 | ++it; | - |
2668 | } | - |
2669 | } | - |
2670 | | - |
2671 | void QFontCache::clear() | - |
2672 | { | - |
2673 | { | - |
2674 | EngineDataCache::Iterator it = engineDataCache.begin(), | - |
2675 | end = engineDataCache.end(); | - |
2676 | while (it != end) { | - |
2677 | QFontEngineData *data = it.value(); | - |
2678 | for (int i = 0; i < QUnicodeTables::ScriptCount; ++i) { | - |
2679 | if (data->engines[i]) { | - |
2680 | data->engines[i]->ref.deref(); | - |
2681 | data->engines[i] = 0; | - |
2682 | } | - |
2683 | } | - |
2684 | ++it; | - |
2685 | } | - |
2686 | } | - |
2687 | | - |
2688 | for (EngineCache::Iterator it = engineCache.begin(), end = engineCache.end(); | - |
2689 | it != end; ++it) { | - |
2690 | if (it->data->ref.load() == 0) { | - |
2691 | delete it->data; | - |
2692 | it->data = 0; | - |
2693 | } | - |
2694 | } | - |
2695 | | - |
2696 | for (EngineCache::Iterator it = engineCache.begin(), end = engineCache.end(); | - |
2697 | it != end; ++it) { | - |
2698 | if (it->data && it->data->ref.load() == 0) { | - |
2699 | delete it->data; | - |
2700 | it->data = 0; | - |
2701 | } | - |
2702 | } | - |
2703 | | - |
2704 | engineCache.clear(); | - |
2705 | } | - |
2706 | | - |
2707 | | - |
2708 | QFontEngineData *QFontCache::findEngineData(const QFontDef &def) const | - |
2709 | { | - |
2710 | EngineDataCache::ConstIterator it = engineDataCache.constFind(def); | - |
2711 | if (it == engineDataCache.constEnd()) | - |
2712 | return 0; | - |
2713 | | - |
2714 | // found | - |
2715 | return it.value(); | - |
2716 | } | - |
2717 | | - |
2718 | void QFontCache::insertEngineData(const QFontDef &def, QFontEngineData *engineData) | - |
2719 | { | - |
2720 | FC_DEBUG("QFontCache: inserting new engine data %p", engineData); | - |
2721 | | - |
2722 | engineDataCache.insert(def, engineData); | - |
2723 | increaseCost(sizeof(QFontEngineData)); | - |
2724 | } | - |
2725 | | - |
2726 | QFontEngine *QFontCache::findEngine(const Key &key) | - |
2727 | { | - |
2728 | EngineCache::Iterator it = engineCache.find(key), | - |
2729 | end = engineCache.end(); | - |
2730 | if (it == end) return 0; | - |
2731 | // found... update the hitcount and timestamp | - |
2732 | updateHitCountAndTimeStamp(it.value()); | - |
2733 | | - |
2734 | return it.value().data; | - |
2735 | } | - |
2736 | | - |
2737 | void QFontCache::updateHitCountAndTimeStamp(Engine &value) | - |
2738 | { | - |
2739 | value.hits++; | - |
2740 | value.timestamp = ++current_timestamp; | - |
2741 | | - |
2742 | FC_DEBUG("QFontCache: found font engine\n" | - |
2743 | " %p: timestamp %4u hits %3u ref %2d/%2d, type '%s'", | - |
2744 | value.data, value.timestamp, value.hits, | - |
2745 | value.data->ref.load(), value.data->cache_count, | - |
2746 | value.data->name()); | - |
2747 | } | - |
2748 | | - |
2749 | void QFontCache::insertEngine(const Key &key, QFontEngine *engine, bool insertMulti) | - |
2750 | { | - |
2751 | FC_DEBUG("QFontCache: inserting new engine %p", engine); | - |
2752 | | - |
2753 | Engine data(engine); | - |
2754 | data.timestamp = ++current_timestamp; | - |
2755 | | - |
2756 | if (insertMulti) | - |
2757 | engineCache.insertMulti(key, data); | - |
2758 | else | - |
2759 | engineCache.insert(key, data); | - |
2760 | | - |
2761 | // only increase the cost if this is the first time we insert the engine | - |
2762 | if (engine->cache_count == 0) | - |
2763 | increaseCost(engine->cache_cost); | - |
2764 | | - |
2765 | ++engine->cache_count; | - |
2766 | } | - |
2767 | | - |
2768 | void QFontCache::increaseCost(uint cost) | - |
2769 | { | - |
2770 | cost = (cost + 512) / 1024; // store cost in kb | - |
2771 | cost = cost > 0 ? cost : 1; | - |
2772 | total_cost += cost; | - |
2773 | | - |
2774 | FC_DEBUG(" COST: increased %u kb, total_cost %u kb, max_cost %u kb", | - |
2775 | cost, total_cost, max_cost); | - |
2776 | | - |
2777 | if (total_cost > max_cost) { | - |
2778 | max_cost = total_cost; | - |
2779 | | - |
2780 | if (timer_id == -1 || ! fast) { | - |
2781 | FC_DEBUG(" TIMER: starting fast timer (%d ms)", fast_timeout); | - |
2782 | | - |
2783 | if (timer_id != -1) killTimer(timer_id); | - |
2784 | timer_id = startTimer(fast_timeout); | - |
2785 | fast = true; | - |
2786 | } | - |
2787 | } | - |
2788 | } | - |
2789 | | - |
2790 | void QFontCache::decreaseCost(uint cost) | - |
2791 | { | - |
2792 | cost = (cost + 512) / 1024; // cost is stored in kb | - |
2793 | cost = cost > 0 ? cost : 1; | - |
2794 | Q_ASSERT(cost <= total_cost); | - |
2795 | total_cost -= cost; | - |
2796 | | - |
2797 | FC_DEBUG(" COST: decreased %u kb, total_cost %u kb, max_cost %u kb", | - |
2798 | cost, total_cost, max_cost); | - |
2799 | } | - |
2800 | | - |
2801 | void QFontCache::timerEvent(QTimerEvent *) | - |
2802 | { | - |
2803 | FC_DEBUG("QFontCache::timerEvent: performing cache maintenance (timestamp %u)", | - |
2804 | current_timestamp); | - |
2805 | | - |
2806 | if (total_cost <= max_cost && max_cost <= min_cost) { | - |
2807 | FC_DEBUG(" cache redused sufficiently, stopping timer"); | - |
2808 | | - |
2809 | killTimer(timer_id); | - |
2810 | timer_id = -1; | - |
2811 | fast = false; | - |
2812 | | - |
2813 | return; | - |
2814 | } | - |
2815 | | - |
2816 | // go through the cache and count up everything in use | - |
2817 | uint in_use_cost = 0; | - |
2818 | | - |
2819 | { | - |
2820 | FC_DEBUG(" SWEEP engine data:"); | - |
2821 | | - |
2822 | // make sure the cost of each engine data is at least 1kb | - |
2823 | const uint engine_data_cost = | - |
2824 | sizeof(QFontEngineData) > 1024 ? sizeof(QFontEngineData) : 1024; | - |
2825 | | - |
2826 | EngineDataCache::ConstIterator it = engineDataCache.constBegin(), | - |
2827 | end = engineDataCache.constEnd(); | - |
2828 | for (; it != end; ++it) { | - |
2829 | #ifdef QFONTCACHE_DEBUG | - |
2830 | FC_DEBUG(" %p: ref %2d", it.value(), int(it.value()->ref.load())); | - |
2831 | | - |
2832 | #endif // QFONTCACHE_DEBUG | - |
2833 | | - |
2834 | if (it.value()->ref.load() != 0) | - |
2835 | in_use_cost += engine_data_cost; | - |
2836 | } | - |
2837 | } | - |
2838 | | - |
2839 | { | - |
2840 | FC_DEBUG(" SWEEP engine:"); | - |
2841 | | - |
2842 | EngineCache::ConstIterator it = engineCache.constBegin(), | - |
2843 | end = engineCache.constEnd(); | - |
2844 | for (; it != end; ++it) { | - |
2845 | FC_DEBUG(" %p: timestamp %4u hits %2u ref %2d/%2d, cost %u bytes", | - |
2846 | it.value().data, it.value().timestamp, it.value().hits, | - |
2847 | it.value().data->ref.load(), it.value().data->cache_count, | - |
2848 | it.value().data->cache_cost); | - |
2849 | | - |
2850 | if (it.value().data->ref.load() != 0) | - |
2851 | in_use_cost += it.value().data->cache_cost / it.value().data->cache_count; | - |
2852 | } | - |
2853 | | - |
2854 | // attempt to make up for rounding errors | - |
2855 | in_use_cost += engineCache.size(); | - |
2856 | } | - |
2857 | | - |
2858 | in_use_cost = (in_use_cost + 512) / 1024; // cost is stored in kb | - |
2859 | | - |
2860 | /* | - |
2861 | calculate the new maximum cost for the cache | - |
2862 | | - |
2863 | NOTE: in_use_cost is *not* correct due to rounding errors in the | - |
2864 | above algorithm. instead of worrying about getting the | - |
2865 | calculation correct, we are more interested in speed, and use | - |
2866 | in_use_cost as a floor for new_max_cost | - |
2867 | */ | - |
2868 | uint new_max_cost = qMax(qMax(max_cost / 2, in_use_cost), min_cost); | - |
2869 | | - |
2870 | FC_DEBUG(" after sweep, in use %u kb, total %u kb, max %u kb, new max %u kb", | - |
2871 | in_use_cost, total_cost, max_cost, new_max_cost); | - |
2872 | | - |
2873 | if (new_max_cost == max_cost) { | - |
2874 | if (fast) { | - |
2875 | FC_DEBUG(" cannot shrink cache, slowing timer"); | - |
2876 | | - |
2877 | killTimer(timer_id); | - |
2878 | timer_id = startTimer(slow_timeout); | - |
2879 | fast = false; | - |
2880 | } | - |
2881 | | - |
2882 | return; | - |
2883 | } else if (! fast) { | - |
2884 | FC_DEBUG(" dropping into passing gear"); | - |
2885 | | - |
2886 | killTimer(timer_id); | - |
2887 | timer_id = startTimer(fast_timeout); | - |
2888 | fast = true; | - |
2889 | } | - |
2890 | | - |
2891 | max_cost = new_max_cost; | - |
2892 | | - |
2893 | { | - |
2894 | FC_DEBUG(" CLEAN engine data:"); | - |
2895 | | - |
2896 | // clean out all unused engine data | - |
2897 | EngineDataCache::Iterator it = engineDataCache.begin(), | - |
2898 | end = engineDataCache.end(); | - |
2899 | while (it != end) { | - |
2900 | if (it.value()->ref.load() != 0) { | - |
2901 | ++it; | - |
2902 | continue; | - |
2903 | } | - |
2904 | | - |
2905 | EngineDataCache::Iterator rem = it++; | - |
2906 | | - |
2907 | decreaseCost(sizeof(QFontEngineData)); | - |
2908 | | - |
2909 | FC_DEBUG(" %p", rem.value()); | - |
2910 | | - |
2911 | delete rem.value(); | - |
2912 | engineDataCache.erase(rem); | - |
2913 | } | - |
2914 | } | - |
2915 | | - |
2916 | // clean out the engine cache just enough to get below our new max cost | - |
2917 | uint current_cost; | - |
2918 | do { | - |
2919 | current_cost = total_cost; | - |
2920 | | - |
2921 | EngineCache::Iterator it = engineCache.begin(), | - |
2922 | end = engineCache.end(); | - |
2923 | // determine the oldest and least popular of the unused engines | - |
2924 | uint oldest = ~0u; | - |
2925 | uint least_popular = ~0u; | - |
2926 | | - |
2927 | for (; it != end; ++it) { | - |
2928 | if (it.value().data->ref.load() != 0) | - |
2929 | continue; | - |
2930 | | - |
2931 | if (it.value().timestamp < oldest && | - |
2932 | it.value().hits <= least_popular) { | - |
2933 | oldest = it.value().timestamp; | - |
2934 | least_popular = it.value().hits; | - |
2935 | } | - |
2936 | } | - |
2937 | | - |
2938 | FC_DEBUG(" oldest %u least popular %u", oldest, least_popular); | - |
2939 | | - |
2940 | for (it = engineCache.begin(); it != end; ++it) { | - |
2941 | if (it.value().data->ref.load() == 0 && | - |
2942 | it.value().timestamp == oldest && | - |
2943 | it.value().hits == least_popular) | - |
2944 | break; | - |
2945 | } | - |
2946 | | - |
2947 | if (it != end) { | - |
2948 | FC_DEBUG(" %p: timestamp %4u hits %2u ref %2d/%2d, type '%s'", | - |
2949 | it.value().data, it.value().timestamp, it.value().hits, | - |
2950 | it.value().data->ref.load(), it.value().data->cache_count, | - |
2951 | it.value().data->name()); | - |
2952 | | - |
2953 | if (--it.value().data->cache_count == 0) { | - |
2954 | FC_DEBUG(" DELETE: last occurrence in cache"); | - |
2955 | | - |
2956 | decreaseCost(it.value().data->cache_cost); | - |
2957 | delete it.value().data; | - |
2958 | } else { | - |
2959 | /* | - |
2960 | this particular font engine is in the cache multiple | - |
2961 | times... set current_cost to zero, so that we can | - |
2962 | keep looping to get rid of all occurrences | - |
2963 | */ | - |
2964 | current_cost = 0; | - |
2965 | } | - |
2966 | | - |
2967 | engineCache.erase(it); | - |
2968 | } | - |
2969 | } while (current_cost != total_cost && total_cost > max_cost); | - |
2970 | } | - |
2971 | | - |
2972 | | - |
2973 | #ifndef QT_NO_DEBUG_STREAM | - |
2974 | QDebug operator<<(QDebug stream, const QFont &font) | - |
2975 | { | - |
2976 | return stream << "QFont(" << font.toString() << ')'; | - |
2977 | } | - |
2978 | #endif | - |
2979 | | - |
2980 | QT_END_NAMESPACE | - |
2981 | | - |
| | |