Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | bool QFontDef::exactMatch(const QFontDef &other) const | - |
10 | { | - |
11 | if (pixelSize != -1 && other.pixelSize != -1) { | - |
12 | if (pixelSize != other.pixelSize) | - |
13 | return false; | - |
14 | } else if (pointSize != -1 && other.pointSize != -1) { | - |
15 | if (pointSize != other.pointSize) | - |
16 | return false; | - |
17 | } else { | - |
18 | return false; | - |
19 | } | - |
20 | | - |
21 | if (!ignorePitch && !other.ignorePitch && fixedPitch != other.fixedPitch) | - |
22 | return false; | - |
23 | | - |
24 | if (stretch != 0 && other.stretch != 0 && stretch != other.stretch) | - |
25 | return false; | - |
26 | | - |
27 | QString this_family, this_foundry, other_family, other_foundry; | - |
28 | QFontDatabase::parseFontName(family, this_foundry, this_family); | - |
29 | QFontDatabase::parseFontName(other.family, other_foundry, other_family); | - |
30 | | - |
31 | this_family = QFontDatabase::resolveFontFamilyAlias(this_family); | - |
32 | other_family = QFontDatabase::resolveFontFamilyAlias(other_family); | - |
33 | | - |
34 | return (styleHint == other.styleHint | - |
35 | && styleStrategy == other.styleStrategy | - |
36 | && weight == other.weight | - |
37 | && style == other.style | - |
38 | && this_family == other_family | - |
39 | && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName) | - |
40 | && (this_foundry.isEmpty() | - |
41 | || other_foundry.isEmpty() | - |
42 | || this_foundry == other_foundry) | - |
43 | ); | - |
44 | } | - |
45 | | - |
46 | extern bool qt_is_gui_used; | - |
47 | | - |
48 | __attribute__((visibility("default"))) int qt_defaultDpiX() | - |
49 | { | - |
50 | if ((static_cast<QGuiApplication *>(QCoreApplication::instance()))->testAttribute(Qt::AA_Use96Dpi)) | - |
51 | return 96; | - |
52 | | - |
53 | if (!qt_is_gui_used) | - |
54 | return 75; | - |
55 | | - |
56 | if (const QScreen *screen = QGuiApplication::primaryScreen()) | - |
57 | return qRound(screen->logicalDotsPerInchX()); | - |
58 | | - |
59 | | - |
60 | return 100; | - |
61 | } | - |
62 | | - |
63 | __attribute__((visibility("default"))) int qt_defaultDpiY() | - |
64 | { | - |
65 | if ((static_cast<QGuiApplication *>(QCoreApplication::instance()))->testAttribute(Qt::AA_Use96Dpi)) | - |
66 | return 96; | - |
67 | | - |
68 | if (!qt_is_gui_used) | - |
69 | return 75; | - |
70 | | - |
71 | if (const QScreen *screen = QGuiApplication::primaryScreen()) | - |
72 | return qRound(screen->logicalDotsPerInchY()); | - |
73 | | - |
74 | | - |
75 | return 100; | - |
76 | } | - |
77 | | - |
78 | __attribute__((visibility("default"))) int qt_defaultDpi() | - |
79 | { | - |
80 | return qt_defaultDpiY(); | - |
81 | } | - |
82 | | - |
83 | QFontPrivate::QFontPrivate() | - |
84 | : engineData(0), dpi(qt_defaultDpi()), screen(0), | - |
85 | rawMode(false), underline(false), overline(false), strikeOut(false), kerning(true), | - |
86 | capital(0), letterSpacingIsAbsolute(false), scFont(0) | - |
87 | { | - |
88 | } | - |
89 | | - |
90 | QFontPrivate::QFontPrivate(const QFontPrivate &other) | - |
91 | : request(other.request), engineData(0), dpi(other.dpi), screen(other.screen), | - |
92 | rawMode(other.rawMode), underline(other.underline), overline(other.overline), | - |
93 | strikeOut(other.strikeOut), kerning(other.kerning), | - |
94 | capital(other.capital), letterSpacingIsAbsolute(other.letterSpacingIsAbsolute), | - |
95 | letterSpacing(other.letterSpacing), wordSpacing(other.wordSpacing), | - |
96 | scFont(other.scFont) | - |
97 | { | - |
98 | if (scFont && scFont != this) | - |
99 | scFont->ref.ref(); | - |
100 | } | - |
101 | | - |
102 | QFontPrivate::~QFontPrivate() | - |
103 | { | - |
104 | if (engineData) | - |
105 | engineData->ref.deref(); | - |
106 | engineData = 0; | - |
107 | if (scFont && scFont != this) | - |
108 | scFont->ref.deref(); | - |
109 | scFont = 0; | - |
110 | } | - |
111 | | - |
112 | extern QMutex *qt_fontdatabase_mutex(); | - |
113 | | - |
114 | | - |
115 | | - |
116 | QFontEngine *QFontPrivate::engineForScript(int script) const | - |
117 | { | - |
118 | QMutexLocker locker(qt_fontdatabase_mutex()); | - |
119 | if (script >= QUnicodeTables::Inherited) | - |
120 | script = QUnicodeTables::Common; | - |
121 | if (engineData && engineData->fontCache != QFontCache::instance()) { | - |
122 | | - |
123 | engineData->ref.deref(); | - |
124 | engineData = 0; | - |
125 | } | - |
126 | if (!engineData || !engineData->engines[script]) | - |
127 | QFontDatabase::load(this, script); | - |
128 | return engineData->engines[script]; | - |
129 | } | - |
130 | | - |
131 | void QFontPrivate::alterCharForCapitalization(QChar &c) const { | - |
132 | switch (capital) { | - |
133 | case QFont::AllUppercase: | - |
134 | case QFont::SmallCaps: | - |
135 | c = c.toUpper(); | - |
136 | break; | - |
137 | case QFont::AllLowercase: | - |
138 | c = c.toLower(); | - |
139 | break; | - |
140 | case QFont::MixedCase: | - |
141 | break; | - |
142 | } | - |
143 | } | - |
144 | | - |
145 | QFontPrivate *QFontPrivate::smallCapsFontPrivate() const | - |
146 | { | - |
147 | if (scFont) | - |
148 | return scFont; | - |
149 | QFont font(const_cast<QFontPrivate *>(this)); | - |
150 | qreal pointSize = font.pointSizeF(); | - |
151 | if (pointSize > 0) | - |
152 | font.setPointSizeF(pointSize * .7); | - |
153 | else | - |
154 | font.setPixelSize((font.pixelSize() * 7 + 5) / 10); | - |
155 | scFont = font.d.data(); | - |
156 | if (scFont != this) | - |
157 | scFont->ref.ref(); | - |
158 | return scFont; | - |
159 | } | - |
160 | | - |
161 | | - |
162 | void QFontPrivate::resolve(uint mask, const QFontPrivate *other) | - |
163 | { | - |
164 | qt_noop(); | - |
165 | | - |
166 | dpi = other->dpi; | - |
167 | | - |
168 | if ((mask & QFont::AllPropertiesResolved) == QFont::AllPropertiesResolved) return; | - |
169 | | - |
170 | | - |
171 | if (! (mask & QFont::FamilyResolved)) | - |
172 | request.family = other->request.family; | - |
173 | | - |
174 | if (! (mask & QFont::StyleNameResolved)) | - |
175 | request.styleName = other->request.styleName; | - |
176 | | - |
177 | if (! (mask & QFont::SizeResolved)) { | - |
178 | request.pointSize = other->request.pointSize; | - |
179 | request.pixelSize = other->request.pixelSize; | - |
180 | } | - |
181 | | - |
182 | if (! (mask & QFont::StyleHintResolved)) | - |
183 | request.styleHint = other->request.styleHint; | - |
184 | | - |
185 | if (! (mask & QFont::StyleStrategyResolved)) | - |
186 | request.styleStrategy = other->request.styleStrategy; | - |
187 | | - |
188 | if (! (mask & QFont::WeightResolved)) | - |
189 | request.weight = other->request.weight; | - |
190 | | - |
191 | if (! (mask & QFont::StyleResolved)) | - |
192 | request.style = other->request.style; | - |
193 | | - |
194 | if (! (mask & QFont::FixedPitchResolved)) | - |
195 | request.fixedPitch = other->request.fixedPitch; | - |
196 | | - |
197 | if (! (mask & QFont::StretchResolved)) | - |
198 | request.stretch = other->request.stretch; | - |
199 | | - |
200 | if (! (mask & QFont::HintingPreferenceResolved)) | - |
201 | request.hintingPreference = other->request.hintingPreference; | - |
202 | | - |
203 | if (! (mask & QFont::UnderlineResolved)) | - |
204 | underline = other->underline; | - |
205 | | - |
206 | if (! (mask & QFont::OverlineResolved)) | - |
207 | overline = other->overline; | - |
208 | | - |
209 | if (! (mask & QFont::StrikeOutResolved)) | - |
210 | strikeOut = other->strikeOut; | - |
211 | | - |
212 | if (! (mask & QFont::KerningResolved)) | - |
213 | kerning = other->kerning; | - |
214 | | - |
215 | if (! (mask & QFont::LetterSpacingResolved)) { | - |
216 | letterSpacing = other->letterSpacing; | - |
217 | letterSpacingIsAbsolute = other->letterSpacingIsAbsolute; | - |
218 | } | - |
219 | if (! (mask & QFont::WordSpacingResolved)) | - |
220 | wordSpacing = other->wordSpacing; | - |
221 | if (! (mask & QFont::CapitalizationResolved)) | - |
222 | capital = other->capital; | - |
223 | } | - |
224 | | - |
225 | | - |
226 | | - |
227 | | - |
228 | QFontEngineData::QFontEngineData() | - |
229 | : ref(1), fontCache(QFontCache::instance()) | - |
230 | { | - |
231 | memset(engines, 0, QUnicodeTables::ScriptCount * sizeof(QFontEngine *)); | - |
232 | } | - |
233 | | - |
234 | QFontEngineData::~QFontEngineData() | - |
235 | { | - |
236 | for (int i = 0; i < QUnicodeTables::ScriptCount; ++i) { | - |
237 | if (engines[i]) | - |
238 | engines[i]->ref.deref(); | - |
239 | engines[i] = 0; | - |
240 | } | - |
241 | } | - |
242 | QFont::QFont(const QFont &font, QPaintDevice *pd) | - |
243 | : resolve_mask(font.resolve_mask) | - |
244 | { | - |
245 | qt_noop(); | - |
246 | int dpi = pd->logicalDpiY(); | - |
247 | const int screen = 0; | - |
248 | if (font.d->dpi != dpi || font.d->screen != screen ) { | - |
249 | d = new QFontPrivate(*font.d); | - |
250 | d->dpi = dpi; | - |
251 | d->screen = screen; | - |
252 | } else { | - |
253 | d = font.d.data(); | - |
254 | } | - |
255 | } | - |
256 | | - |
257 | | - |
258 | | - |
259 | | - |
260 | QFont::QFont(QFontPrivate *data) | - |
261 | : d(data), resolve_mask(QFont::AllPropertiesResolved) | - |
262 | { | - |
263 | } | - |
264 | | - |
265 | | - |
266 | | - |
267 | | - |
268 | void QFont::detach() | - |
269 | { | - |
270 | if (d->ref.load() == 1) { | - |
271 | if (d->engineData) | - |
272 | d->engineData->ref.deref(); | - |
273 | d->engineData = 0; | - |
274 | if (d->scFont && d->scFont != d.data()) | - |
275 | d->scFont->ref.deref(); | - |
276 | d->scFont = 0; | - |
277 | return; | - |
278 | } | - |
279 | | - |
280 | d.detach(); | - |
281 | } | - |
282 | | - |
283 | | - |
284 | | - |
285 | | - |
286 | | - |
287 | | - |
288 | | - |
289 | void QFontPrivate::detachButKeepEngineData(QFont *font) | - |
290 | { | - |
291 | if (font->d->ref.load() == 1) | - |
292 | return; | - |
293 | | - |
294 | QFontEngineData *engineData = font->d->engineData; | - |
295 | if (engineData) | - |
296 | engineData->ref.ref(); | - |
297 | font->d.detach(); | - |
298 | font->d->engineData = engineData; | - |
299 | } | - |
300 | | - |
301 | | - |
302 | | - |
303 | | - |
304 | | - |
305 | | - |
306 | QFont::QFont() | - |
307 | : d(QGuiApplicationPrivate::instance() ? QGuiApplication::font().d.data() : new QFontPrivate()), resolve_mask(0) | - |
308 | { | - |
309 | } executed: } Execution Count:1041278 | 1041278 |
310 | QFont::QFont(const QString &family, int pointSize, int weight, bool italic) | - |
311 | : d(new QFontPrivate()), resolve_mask(QFont::FamilyResolved) | - |
312 | { | - |
313 | if (pointSize <= 0) { | - |
314 | pointSize = 12; | - |
315 | } else { | - |
316 | resolve_mask |= QFont::SizeResolved; | - |
317 | } | - |
318 | | - |
319 | if (weight < 0) { | - |
320 | weight = Normal; | - |
321 | } else { | - |
322 | resolve_mask |= QFont::WeightResolved | QFont::StyleResolved; | - |
323 | } | - |
324 | | - |
325 | if (italic) | - |
326 | resolve_mask |= QFont::StyleResolved; | - |
327 | | - |
328 | d->request.family = family; | - |
329 | d->request.pointSize = qreal(pointSize); | - |
330 | d->request.pixelSize = -1; | - |
331 | d->request.weight = weight; | - |
332 | d->request.style = italic ? QFont::StyleItalic : QFont::StyleNormal; | - |
333 | } | - |
334 | | - |
335 | | - |
336 | | - |
337 | | - |
338 | QFont::QFont(const QFont &font) | - |
339 | : d(font.d.data()), resolve_mask(font.resolve_mask) | - |
340 | { | - |
341 | } | - |
342 | | - |
343 | | - |
344 | | - |
345 | | - |
346 | QFont::~QFont() | - |
347 | { | - |
348 | } | - |
349 | | - |
350 | | - |
351 | | - |
352 | | - |
353 | QFont &QFont::operator=(const QFont &font) | - |
354 | { | - |
355 | d = font.d.data(); | - |
356 | resolve_mask = font.resolve_mask; | - |
357 | return *this; | - |
358 | } | - |
359 | QString QFont::family() const | - |
360 | { | - |
361 | return d->request.family; | - |
362 | } | - |
363 | void QFont::setFamily(const QString &family) | - |
364 | { | - |
365 | if ((resolve_mask & QFont::FamilyResolved) && d->request.family == family) | - |
366 | return; | - |
367 | | - |
368 | detach(); | - |
369 | | - |
370 | d->request.family = family; | - |
371 | | - |
372 | resolve_mask |= QFont::FamilyResolved; | - |
373 | } | - |
374 | QString QFont::styleName() const | - |
375 | { | - |
376 | return d->request.styleName; | - |
377 | } | - |
378 | void QFont::setStyleName(const QString &styleName) | - |
379 | { | - |
380 | if ((resolve_mask & QFont::StyleNameResolved) && d->request.styleName == styleName) | - |
381 | return; | - |
382 | | - |
383 | detach(); | - |
384 | | - |
385 | d->request.styleName = styleName; | - |
386 | resolve_mask |= QFont::StyleNameResolved; | - |
387 | } | - |
388 | | - |
389 | | - |
390 | | - |
391 | | - |
392 | | - |
393 | | - |
394 | | - |
395 | int QFont::pointSize() const | - |
396 | { | - |
397 | return qRound(d->request.pointSize); | - |
398 | } | - |
399 | void QFont::setHintingPreference(HintingPreference hintingPreference) | - |
400 | { | - |
401 | if ((resolve_mask & QFont::HintingPreferenceResolved) && d->request.hintingPreference == hintingPreference) | - |
402 | return; | - |
403 | | - |
404 | detach(); | - |
405 | | - |
406 | d->request.hintingPreference = hintingPreference; | - |
407 | | - |
408 | resolve_mask |= QFont::HintingPreferenceResolved; | - |
409 | } | - |
410 | | - |
411 | | - |
412 | | - |
413 | | - |
414 | | - |
415 | | - |
416 | QFont::HintingPreference QFont::hintingPreference() const | - |
417 | { | - |
418 | return QFont::HintingPreference(d->request.hintingPreference); | - |
419 | } | - |
420 | | - |
421 | | - |
422 | | - |
423 | | - |
424 | | - |
425 | | - |
426 | | - |
427 | void QFont::setPointSize(int pointSize) | - |
428 | { | - |
429 | if (pointSize <= 0) { | - |
430 | QMessageLogger("text/qfont.cpp", 948, __PRETTY_FUNCTION__).warning("QFont::setPointSize: Point size <= 0 (%d), must be greater than 0", pointSize); | - |
431 | return; | - |
432 | } | - |
433 | | - |
434 | if ((resolve_mask & QFont::SizeResolved) && d->request.pointSize == qreal(pointSize)) | - |
435 | return; | - |
436 | | - |
437 | detach(); | - |
438 | | - |
439 | d->request.pointSize = qreal(pointSize); | - |
440 | d->request.pixelSize = -1; | - |
441 | | - |
442 | resolve_mask |= QFont::SizeResolved; | - |
443 | } | - |
444 | void QFont::setPointSizeF(qreal pointSize) | - |
445 | { | - |
446 | if (pointSize <= 0) { | - |
447 | QMessageLogger("text/qfont.cpp", 973, __PRETTY_FUNCTION__).warning("QFont::setPointSizeF: Point size <= 0 (%f), must be greater than 0", pointSize); | - |
448 | return; | - |
449 | } | - |
450 | | - |
451 | if ((resolve_mask & QFont::SizeResolved) && d->request.pointSize == pointSize) | - |
452 | return; | - |
453 | | - |
454 | detach(); | - |
455 | | - |
456 | d->request.pointSize = pointSize; | - |
457 | d->request.pixelSize = -1; | - |
458 | | - |
459 | resolve_mask |= QFont::SizeResolved; | - |
460 | } | - |
461 | | - |
462 | | - |
463 | | - |
464 | | - |
465 | | - |
466 | | - |
467 | | - |
468 | qreal QFont::pointSizeF() const | - |
469 | { | - |
470 | return d->request.pointSize; | - |
471 | } | - |
472 | void QFont::setPixelSize(int pixelSize) | - |
473 | { | - |
474 | if (pixelSize <= 0) { | - |
475 | QMessageLogger("text/qfont.cpp", 1011, __PRETTY_FUNCTION__).warning("QFont::setPixelSize: Pixel size <= 0 (%d)", pixelSize); | - |
476 | return; | - |
477 | } | - |
478 | | - |
479 | if ((resolve_mask & QFont::SizeResolved) && d->request.pixelSize == qreal(pixelSize)) | - |
480 | return; | - |
481 | | - |
482 | detach(); | - |
483 | | - |
484 | d->request.pixelSize = pixelSize; | - |
485 | d->request.pointSize = -1; | - |
486 | | - |
487 | resolve_mask |= QFont::SizeResolved; | - |
488 | } | - |
489 | int QFont::pixelSize() const | - |
490 | { | - |
491 | return d->request.pixelSize; | - |
492 | } | - |
493 | QFont::Style QFont::style() const | - |
494 | { | - |
495 | return (QFont::Style)d->request.style; | - |
496 | } | - |
497 | | - |
498 | | - |
499 | | - |
500 | | - |
501 | | - |
502 | | - |
503 | | - |
504 | void QFont::setStyle(Style style) | - |
505 | { | - |
506 | if ((resolve_mask & QFont::StyleResolved) && d->request.style == style) | - |
507 | return; | - |
508 | | - |
509 | detach(); | - |
510 | | - |
511 | d->request.style = style; | - |
512 | resolve_mask |= QFont::StyleResolved; | - |
513 | } | - |
514 | | - |
515 | | - |
516 | | - |
517 | | - |
518 | | - |
519 | | - |
520 | | - |
521 | int QFont::weight() const | - |
522 | { | - |
523 | return d->request.weight; | - |
524 | } | - |
525 | void QFont::setWeight(int weight) | - |
526 | { | - |
527 | qt_noop(); | - |
528 | | - |
529 | if ((resolve_mask & QFont::WeightResolved) && d->request.weight == weight) | - |
530 | return; | - |
531 | | - |
532 | detach(); | - |
533 | | - |
534 | d->request.weight = weight; | - |
535 | resolve_mask |= QFont::WeightResolved; | - |
536 | } | - |
537 | bool QFont::underline() const | - |
538 | { | - |
539 | return d->underline; | - |
540 | } | - |
541 | | - |
542 | | - |
543 | | - |
544 | | - |
545 | | - |
546 | | - |
547 | | - |
548 | void QFont::setUnderline(bool enable) | - |
549 | { | - |
550 | if ((resolve_mask & QFont::UnderlineResolved) && d->underline == enable) | - |
551 | return; | - |
552 | | - |
553 | QFontPrivate::detachButKeepEngineData(this); | - |
554 | | - |
555 | d->underline = enable; | - |
556 | resolve_mask |= QFont::UnderlineResolved; | - |
557 | } | - |
558 | | - |
559 | | - |
560 | | - |
561 | | - |
562 | | - |
563 | | - |
564 | bool QFont::overline() const | - |
565 | { | - |
566 | return d->overline; | - |
567 | } | - |
568 | | - |
569 | | - |
570 | | - |
571 | | - |
572 | | - |
573 | | - |
574 | void QFont::setOverline(bool enable) | - |
575 | { | - |
576 | if ((resolve_mask & QFont::OverlineResolved) && d->overline == enable) | - |
577 | return; | - |
578 | | - |
579 | QFontPrivate::detachButKeepEngineData(this); | - |
580 | | - |
581 | d->overline = enable; | - |
582 | resolve_mask |= QFont::OverlineResolved; | - |
583 | } | - |
584 | | - |
585 | | - |
586 | | - |
587 | | - |
588 | | - |
589 | | - |
590 | bool QFont::strikeOut() const | - |
591 | { | - |
592 | return d->strikeOut; | - |
593 | } | - |
594 | | - |
595 | | - |
596 | | - |
597 | | - |
598 | | - |
599 | | - |
600 | | - |
601 | void QFont::setStrikeOut(bool enable) | - |
602 | { | - |
603 | if ((resolve_mask & QFont::StrikeOutResolved) && d->strikeOut == enable) | - |
604 | return; | - |
605 | | - |
606 | QFontPrivate::detachButKeepEngineData(this); | - |
607 | | - |
608 | d->strikeOut = enable; | - |
609 | resolve_mask |= QFont::StrikeOutResolved; | - |
610 | } | - |
611 | | - |
612 | | - |
613 | | - |
614 | | - |
615 | | - |
616 | | - |
617 | bool QFont::fixedPitch() const | - |
618 | { | - |
619 | return d->request.fixedPitch; | - |
620 | } | - |
621 | | - |
622 | | - |
623 | | - |
624 | | - |
625 | | - |
626 | | - |
627 | | - |
628 | void QFont::setFixedPitch(bool enable) | - |
629 | { | - |
630 | if ((resolve_mask & QFont::FixedPitchResolved) && d->request.fixedPitch == enable) | - |
631 | return; | - |
632 | | - |
633 | detach(); | - |
634 | | - |
635 | d->request.fixedPitch = enable; | - |
636 | d->request.ignorePitch = false; | - |
637 | resolve_mask |= QFont::FixedPitchResolved; | - |
638 | } | - |
639 | | - |
640 | | - |
641 | | - |
642 | | - |
643 | | - |
644 | | - |
645 | bool QFont::kerning() const | - |
646 | { | - |
647 | return d->kerning; | - |
648 | } | - |
649 | void QFont::setKerning(bool enable) | - |
650 | { | - |
651 | if ((resolve_mask & QFont::KerningResolved) && d->kerning == enable) | - |
652 | return; | - |
653 | | - |
654 | QFontPrivate::detachButKeepEngineData(this); | - |
655 | | - |
656 | d->kerning = enable; | - |
657 | resolve_mask |= QFont::KerningResolved; | - |
658 | } | - |
659 | QFont::StyleStrategy QFont::styleStrategy() const | - |
660 | { | - |
661 | return (StyleStrategy) d->request.styleStrategy; | - |
662 | } | - |
663 | QFont::StyleHint QFont::styleHint() const | - |
664 | { | - |
665 | return (StyleHint) d->request.styleHint; | - |
666 | } | - |
667 | void QFont::setStyleHint(StyleHint hint, StyleStrategy strategy) | - |
668 | { | - |
669 | if ((resolve_mask & (QFont::StyleHintResolved | QFont::StyleStrategyResolved)) && | - |
670 | (StyleHint) d->request.styleHint == hint && | - |
671 | (StyleStrategy) d->request.styleStrategy == strategy) | - |
672 | return; | - |
673 | | - |
674 | detach(); | - |
675 | | - |
676 | d->request.styleHint = hint; | - |
677 | d->request.styleStrategy = strategy; | - |
678 | resolve_mask |= QFont::StyleHintResolved; | - |
679 | resolve_mask |= QFont::StyleStrategyResolved; | - |
680 | | - |
681 | } | - |
682 | | - |
683 | | - |
684 | | - |
685 | | - |
686 | | - |
687 | | - |
688 | void QFont::setStyleStrategy(StyleStrategy s) | - |
689 | { | - |
690 | if ((resolve_mask & QFont::StyleStrategyResolved) && | - |
691 | s == (StyleStrategy)d->request.styleStrategy) | - |
692 | return; | - |
693 | | - |
694 | detach(); | - |
695 | | - |
696 | d->request.styleStrategy = s; | - |
697 | resolve_mask |= QFont::StyleStrategyResolved; | - |
698 | } | - |
699 | int QFont::stretch() const | - |
700 | { | - |
701 | return d->request.stretch; | - |
702 | } | - |
703 | void QFont::setStretch(int factor) | - |
704 | { | - |
705 | if (factor < 1 || factor > 4000) { | - |
706 | QMessageLogger("text/qfont.cpp", 1478, __PRETTY_FUNCTION__).warning("QFont::setStretch: Parameter '%d' out of range", factor); | - |
707 | return; | - |
708 | } | - |
709 | | - |
710 | if ((resolve_mask & QFont::StretchResolved) && | - |
711 | d->request.stretch == (uint)factor) | - |
712 | return; | - |
713 | | - |
714 | detach(); | - |
715 | | - |
716 | d->request.stretch = (uint)factor; | - |
717 | resolve_mask |= QFont::StretchResolved; | - |
718 | } | - |
719 | qreal QFont::letterSpacing() const | - |
720 | { | - |
721 | return d->letterSpacing.toReal(); | - |
722 | } | - |
723 | void QFont::setLetterSpacing(SpacingType type, qreal spacing) | - |
724 | { | - |
725 | const QFixed newSpacing = QFixed::fromReal(spacing); | - |
726 | const bool absoluteSpacing = type == AbsoluteSpacing; | - |
727 | if ((resolve_mask & QFont::LetterSpacingResolved) && | - |
728 | d->letterSpacingIsAbsolute == absoluteSpacing && | - |
729 | d->letterSpacing == newSpacing) | - |
730 | return; | - |
731 | | - |
732 | QFontPrivate::detachButKeepEngineData(this); | - |
733 | | - |
734 | d->letterSpacing = newSpacing; | - |
735 | d->letterSpacingIsAbsolute = absoluteSpacing; | - |
736 | resolve_mask |= QFont::LetterSpacingResolved; | - |
737 | } | - |
738 | | - |
739 | | - |
740 | | - |
741 | | - |
742 | | - |
743 | | - |
744 | | - |
745 | QFont::SpacingType QFont::letterSpacingType() const | - |
746 | { | - |
747 | return d->letterSpacingIsAbsolute ? AbsoluteSpacing : PercentageSpacing; | - |
748 | } | - |
749 | | - |
750 | | - |
751 | | - |
752 | | - |
753 | | - |
754 | | - |
755 | | - |
756 | qreal QFont::wordSpacing() const | - |
757 | { | - |
758 | return d->wordSpacing.toReal(); | - |
759 | } | - |
760 | void QFont::setWordSpacing(qreal spacing) | - |
761 | { | - |
762 | const QFixed newSpacing = QFixed::fromReal(spacing); | - |
763 | if ((resolve_mask & QFont::WordSpacingResolved) && | - |
764 | d->wordSpacing == newSpacing) | - |
765 | return; | - |
766 | | - |
767 | QFontPrivate::detachButKeepEngineData(this); | - |
768 | | - |
769 | d->wordSpacing = newSpacing; | - |
770 | resolve_mask |= QFont::WordSpacingResolved; | - |
771 | } | - |
772 | void QFont::setCapitalization(Capitalization caps) | - |
773 | { | - |
774 | if ((resolve_mask & QFont::CapitalizationResolved) && | - |
775 | capitalization() == caps) | - |
776 | return; | - |
777 | | - |
778 | QFontPrivate::detachButKeepEngineData(this); | - |
779 | | - |
780 | d->capital = caps; | - |
781 | resolve_mask |= QFont::CapitalizationResolved; | - |
782 | } | - |
783 | | - |
784 | | - |
785 | | - |
786 | | - |
787 | | - |
788 | | - |
789 | | - |
790 | QFont::Capitalization QFont::capitalization() const | - |
791 | { | - |
792 | return static_cast<QFont::Capitalization> (d->capital); | - |
793 | } | - |
794 | void QFont::setRawMode(bool enable) | - |
795 | { | - |
796 | if ((bool) d->rawMode == enable) return; | - |
797 | | - |
798 | | - |
799 | detach(); | - |
800 | | - |
801 | d->rawMode = enable; | - |
802 | } | - |
803 | | - |
804 | | - |
805 | | - |
806 | | - |
807 | | - |
808 | | - |
809 | | - |
810 | bool QFont::exactMatch() const | - |
811 | { | - |
812 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
813 | qt_noop(); | - |
814 | return (d->rawMode | - |
815 | ? engine->type() != QFontEngine::Box | - |
816 | : d->request.exactMatch(engine->fontDef)); | - |
817 | } | - |
818 | bool QFont::operator==(const QFont &f) const | - |
819 | { | - |
820 | return (f.d == d | - |
821 | || (f.d->request == d->request | - |
822 | && f.d->request.pointSize == d->request.pointSize | - |
823 | && f.d->underline == d->underline | - |
824 | && f.d->overline == d->overline | - |
825 | && f.d->strikeOut == d->strikeOut | - |
826 | && f.d->kerning == d->kerning | - |
827 | && f.d->capital == d->capital | - |
828 | && f.d->letterSpacingIsAbsolute == d->letterSpacingIsAbsolute | - |
829 | && f.d->letterSpacing == d->letterSpacing | - |
830 | && f.d->wordSpacing == d->wordSpacing | - |
831 | )); | - |
832 | } | - |
833 | bool QFont::operator<(const QFont &f) const | - |
834 | { | - |
835 | if (f.d == d) return false; | - |
836 | | - |
837 | QFontDef &r1 = f.d->request; | - |
838 | QFontDef &r2 = d->request; | - |
839 | if (r1.pointSize != r2.pointSize) return r1.pointSize < r2.pointSize; | - |
840 | if (r1.pixelSize != r2.pixelSize) return r1.pixelSize < r2.pixelSize; | - |
841 | if (r1.weight != r2.weight) return r1.weight < r2.weight; | - |
842 | if (r1.style != r2.style) return r1.style < r2.style; | - |
843 | if (r1.stretch != r2.stretch) return r1.stretch < r2.stretch; | - |
844 | if (r1.styleHint != r2.styleHint) return r1.styleHint < r2.styleHint; | - |
845 | if (r1.styleStrategy != r2.styleStrategy) return r1.styleStrategy < r2.styleStrategy; | - |
846 | if (r1.family != r2.family) return r1.family < r2.family; | - |
847 | if (f.d->capital != d->capital) return f.d->capital < d->capital; | - |
848 | | - |
849 | if (f.d->letterSpacingIsAbsolute != d->letterSpacingIsAbsolute) return f.d->letterSpacingIsAbsolute < d->letterSpacingIsAbsolute; | - |
850 | if (f.d->letterSpacing != d->letterSpacing) return f.d->letterSpacing < d->letterSpacing; | - |
851 | if (f.d->wordSpacing != d->wordSpacing) return f.d->wordSpacing < d->wordSpacing; | - |
852 | | - |
853 | int f1attrs = (f.d->underline << 3) + (f.d->overline << 2) + (f.d->strikeOut<<1) + f.d->kerning; | - |
854 | int f2attrs = (d->underline << 3) + (d->overline << 2) + (d->strikeOut<<1) + d->kerning; | - |
855 | return f1attrs < f2attrs; | - |
856 | } | - |
857 | bool QFont::operator!=(const QFont &f) const | - |
858 | { | - |
859 | return !(operator==(f)); | - |
860 | } | - |
861 | | - |
862 | | - |
863 | | - |
864 | | - |
865 | QFont::operator QVariant() const | - |
866 | { | - |
867 | return QVariant(QVariant::Font, this); | - |
868 | } | - |
869 | bool QFont::isCopyOf(const QFont & f) const | - |
870 | { | - |
871 | return d == f.d; | - |
872 | } | - |
873 | | - |
874 | | - |
875 | | - |
876 | | - |
877 | | - |
878 | | - |
879 | | - |
880 | bool QFont::rawMode() const | - |
881 | { | - |
882 | return d->rawMode; | - |
883 | } | - |
884 | | - |
885 | | - |
886 | | - |
887 | | - |
888 | | - |
889 | QFont QFont::resolve(const QFont &other) const | - |
890 | { | - |
891 | if (*this == other | - |
892 | && (resolve_mask == other.resolve_mask || resolve_mask == 0) | - |
893 | && d->dpi == other.d->dpi) { | - |
894 | QFont o = other; | - |
895 | o.resolve_mask = resolve_mask; | - |
896 | return o; | - |
897 | } | - |
898 | | - |
899 | QFont font(*this); | - |
900 | font.detach(); | - |
901 | font.d->resolve(resolve_mask, other.d.data()); | - |
902 | | - |
903 | return font; | - |
904 | } | - |
905 | typedef QHash<QString, QStringList> QFontSubst; | - |
906 | static QFontSubst *globalFontSubst() { static QGlobalStatic<QFontSubst > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QFontSubst *x = new QFontSubst; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QFontSubst > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); } | - |
907 | QString QFont::substitute(const QString &familyName) | - |
908 | { | - |
909 | QFontSubst *fontSubst = globalFontSubst(); | - |
910 | qt_noop(); | - |
911 | QFontSubst::ConstIterator it = fontSubst->constFind(familyName.toLower()); | - |
912 | if (it != fontSubst->constEnd() && !(*it).isEmpty()) | - |
913 | return (*it).first(); | - |
914 | | - |
915 | return familyName; | - |
916 | } | - |
917 | QStringList QFont::substitutes(const QString &familyName) | - |
918 | { | - |
919 | QFontSubst *fontSubst = globalFontSubst(); | - |
920 | qt_noop(); | - |
921 | return fontSubst->value(familyName.toLower(), QStringList()); | - |
922 | } | - |
923 | void QFont::insertSubstitution(const QString &familyName, | - |
924 | const QString &substituteName) | - |
925 | { | - |
926 | QFontSubst *fontSubst = globalFontSubst(); | - |
927 | qt_noop(); | - |
928 | QStringList &list = (*fontSubst)[familyName.toLower()]; | - |
929 | QString s = substituteName.toLower(); | - |
930 | if (!list.contains(s)) | - |
931 | list.append(s); | - |
932 | } | - |
933 | void QFont::insertSubstitutions(const QString &familyName, | - |
934 | const QStringList &substituteNames) | - |
935 | { | - |
936 | QFontSubst *fontSubst = globalFontSubst(); | - |
937 | qt_noop(); | - |
938 | QStringList &list = (*fontSubst)[familyName.toLower()]; | - |
939 | for (QForeachContainer<__typeof__(substituteNames)> _container_(substituteNames); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QString &substituteName = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
940 | const QString lowerSubstituteName = substituteName.toLower(); | - |
941 | if (!list.contains(lowerSubstituteName)) | - |
942 | list.append(lowerSubstituteName); | - |
943 | } | - |
944 | } | - |
945 | void QFont::removeSubstitutions(const QString &familyName) | - |
946 | { | - |
947 | QFontSubst *fontSubst = globalFontSubst(); | - |
948 | qt_noop(); | - |
949 | fontSubst->remove(familyName.toLower()); | - |
950 | } | - |
951 | QStringList QFont::substitutions() | - |
952 | { | - |
953 | typedef QFontSubst::const_iterator QFontSubstConstIterator; | - |
954 | | - |
955 | QFontSubst *fontSubst = globalFontSubst(); | - |
956 | qt_noop(); | - |
957 | QStringList ret; | - |
958 | const QFontSubstConstIterator cend = fontSubst->constEnd(); | - |
959 | for (QFontSubstConstIterator it = fontSubst->constBegin(); it != cend; ++it) | - |
960 | ret.append(it.key()); | - |
961 | | - |
962 | ret.sort(); | - |
963 | return ret; | - |
964 | } | - |
965 | | - |
966 | | - |
967 | | - |
968 | | - |
969 | | - |
970 | | - |
971 | static quint8 get_font_bits(int version, const QFontPrivate *f) | - |
972 | { | - |
973 | qt_noop(); | - |
974 | quint8 bits = 0; | - |
975 | if (f->request.style) | - |
976 | bits |= 0x01; | - |
977 | if (f->underline) | - |
978 | bits |= 0x02; | - |
979 | if (f->overline) | - |
980 | bits |= 0x40; | - |
981 | if (f->strikeOut) | - |
982 | bits |= 0x04; | - |
983 | if (f->request.fixedPitch) | - |
984 | bits |= 0x08; | - |
985 | | - |
986 | | - |
987 | if (f->rawMode) | - |
988 | bits |= 0x20; | - |
989 | if (version >= QDataStream::Qt_4_0) { | - |
990 | if (f->kerning) | - |
991 | bits |= 0x10; | - |
992 | } | - |
993 | if (f->request.style == QFont::StyleOblique) | - |
994 | bits |= 0x80; | - |
995 | return bits; | - |
996 | } | - |
997 | | - |
998 | static quint8 get_extended_font_bits(const QFontPrivate *f) | - |
999 | { | - |
1000 | qt_noop(); | - |
1001 | quint8 bits = 0; | - |
1002 | if (f->request.ignorePitch) | - |
1003 | bits |= 0x01; | - |
1004 | if (f->letterSpacingIsAbsolute) | - |
1005 | bits |= 0x02; | - |
1006 | return bits; | - |
1007 | } | - |
1008 | | - |
1009 | | - |
1010 | | - |
1011 | | - |
1012 | | - |
1013 | | - |
1014 | | - |
1015 | static void set_font_bits(int version, quint8 bits, QFontPrivate *f) | - |
1016 | { | - |
1017 | qt_noop(); | - |
1018 | f->request.style = (bits & 0x01) != 0 ? QFont::StyleItalic : QFont::StyleNormal; | - |
1019 | f->underline = (bits & 0x02) != 0; | - |
1020 | f->overline = (bits & 0x40) != 0; | - |
1021 | f->strikeOut = (bits & 0x04) != 0; | - |
1022 | f->request.fixedPitch = (bits & 0x08) != 0; | - |
1023 | | - |
1024 | f->rawMode = (bits & 0x20) != 0; | - |
1025 | if (version >= QDataStream::Qt_4_0) | - |
1026 | f->kerning = (bits & 0x10) != 0; | - |
1027 | if ((bits & 0x80) != 0) | - |
1028 | f->request.style = QFont::StyleOblique; | - |
1029 | } | - |
1030 | | - |
1031 | static void set_extended_font_bits(quint8 bits, QFontPrivate *f) | - |
1032 | { | - |
1033 | qt_noop(); | - |
1034 | f->request.ignorePitch = (bits & 0x01) != 0; | - |
1035 | f->letterSpacingIsAbsolute = (bits & 0x02) != 0; | - |
1036 | } | - |
1037 | QString QFont::key() const | - |
1038 | { | - |
1039 | return toString(); | - |
1040 | } | - |
1041 | QString QFont::toString() const | - |
1042 | { | - |
1043 | const QChar comma(QLatin1Char(',')); | - |
1044 | return family() + comma + | - |
1045 | QString::number( pointSizeF()) + comma + | - |
1046 | QString::number( pixelSize()) + comma + | - |
1047 | QString::number((int) styleHint()) + comma + | - |
1048 | QString::number( weight()) + comma + | - |
1049 | QString::number((int) style()) + comma + | - |
1050 | QString::number((int) underline()) + comma + | - |
1051 | QString::number((int) strikeOut()) + comma + | - |
1052 | QString::number((int)fixedPitch()) + comma + | - |
1053 | QString::number((int) rawMode()); | - |
1054 | } | - |
1055 | bool QFont::fromString(const QString &descrip) | - |
1056 | { | - |
1057 | QStringList l(descrip.split(QLatin1Char(','))); | - |
1058 | | - |
1059 | int count = l.count(); | - |
1060 | if (!count || (count > 2 && count < 9) || count > 11) { | - |
1061 | QMessageLogger("text/qfont.cpp", 2079, __PRETTY_FUNCTION__).warning("QFont::fromString: Invalid description '%s'", | - |
1062 | descrip.isEmpty() ? "(empty)" : descrip.toLatin1().data()); | - |
1063 | return false; | - |
1064 | } | - |
1065 | | - |
1066 | setFamily(l[0]); | - |
1067 | if (count > 1 && l[1].toDouble() > 0.0) | - |
1068 | setPointSizeF(l[1].toDouble()); | - |
1069 | if (count == 9) { | - |
1070 | setStyleHint((StyleHint) l[2].toInt()); | - |
1071 | setWeight(qMax(qMin(99, l[3].toInt()), 0)); | - |
1072 | setItalic(l[4].toInt()); | - |
1073 | setUnderline(l[5].toInt()); | - |
1074 | setStrikeOut(l[6].toInt()); | - |
1075 | setFixedPitch(l[7].toInt()); | - |
1076 | setRawMode(l[8].toInt()); | - |
1077 | } else if (count == 10) { | - |
1078 | if (l[2].toInt() > 0) | - |
1079 | setPixelSize(l[2].toInt()); | - |
1080 | setStyleHint((StyleHint) l[3].toInt()); | - |
1081 | setWeight(qMax(qMin(99, l[4].toInt()), 0)); | - |
1082 | setStyle((QFont::Style)l[5].toInt()); | - |
1083 | setUnderline(l[6].toInt()); | - |
1084 | setStrikeOut(l[7].toInt()); | - |
1085 | setFixedPitch(l[8].toInt()); | - |
1086 | setRawMode(l[9].toInt()); | - |
1087 | } | - |
1088 | if (count >= 9 && !d->request.fixedPitch) | - |
1089 | d->request.ignorePitch = true; | - |
1090 | | - |
1091 | return true; | - |
1092 | } | - |
1093 | | - |
1094 | | - |
1095 | | - |
1096 | | - |
1097 | | - |
1098 | void QFont::cacheStatistics() | - |
1099 | { | - |
1100 | | - |
1101 | | - |
1102 | } | - |
1103 | QDataStream &operator<<(QDataStream &s, const QFont &font) | - |
1104 | { | - |
1105 | if (s.version() == 1) { | - |
1106 | s << font.d->request.family.toLatin1(); | - |
1107 | } else { | - |
1108 | s << font.d->request.family; | - |
1109 | } | - |
1110 | | - |
1111 | if (s.version() >= QDataStream::Qt_4_0) { | - |
1112 | | - |
1113 | double pointSize = font.d->request.pointSize; | - |
1114 | qint32 pixelSize = font.d->request.pixelSize; | - |
1115 | s << pointSize; | - |
1116 | s << pixelSize; | - |
1117 | } else if (s.version() <= 3) { | - |
1118 | qint16 pointSize = (qint16) (font.d->request.pointSize * 10); | - |
1119 | if (pointSize < 0) { | - |
1120 | pointSize = (qint16)QFontInfo(font).pointSize() * 10; | - |
1121 | } | - |
1122 | s << pointSize; | - |
1123 | } else { | - |
1124 | s << (qint16) (font.d->request.pointSize * 10); | - |
1125 | s << (qint16) font.d->request.pixelSize; | - |
1126 | } | - |
1127 | | - |
1128 | s << (quint8) font.d->request.styleHint; | - |
1129 | if (s.version() >= QDataStream::Qt_3_1) | - |
1130 | s << (quint8) font.d->request.styleStrategy; | - |
1131 | s << (quint8) 0 | - |
1132 | << (quint8) font.d->request.weight | - |
1133 | << get_font_bits(s.version(), font.d.data()); | - |
1134 | if (s.version() >= QDataStream::Qt_4_3) | - |
1135 | s << (quint16)font.d->request.stretch; | - |
1136 | if (s.version() >= QDataStream::Qt_4_4) | - |
1137 | s << get_extended_font_bits(font.d.data()); | - |
1138 | if (s.version() >= QDataStream::Qt_4_5) { | - |
1139 | s << font.d->letterSpacing.value(); | - |
1140 | s << font.d->wordSpacing.value(); | - |
1141 | } | - |
1142 | return s; | - |
1143 | } | - |
1144 | QDataStream &operator>>(QDataStream &s, QFont &font) | - |
1145 | { | - |
1146 | font.d = new QFontPrivate; | - |
1147 | font.resolve_mask = QFont::AllPropertiesResolved; | - |
1148 | | - |
1149 | quint8 styleHint, styleStrategy = QFont::PreferDefault, charSet, weight, bits; | - |
1150 | | - |
1151 | if (s.version() == 1) { | - |
1152 | QByteArray fam; | - |
1153 | s >> fam; | - |
1154 | font.d->request.family = QString::fromLatin1(fam); | - |
1155 | } else { | - |
1156 | s >> font.d->request.family; | - |
1157 | } | - |
1158 | | - |
1159 | if (s.version() >= QDataStream::Qt_4_0) { | - |
1160 | | - |
1161 | double pointSize; | - |
1162 | qint32 pixelSize; | - |
1163 | s >> pointSize; | - |
1164 | s >> pixelSize; | - |
1165 | font.d->request.pointSize = qreal(pointSize); | - |
1166 | font.d->request.pixelSize = pixelSize; | - |
1167 | } else { | - |
1168 | qint16 pointSize, pixelSize = -1; | - |
1169 | s >> pointSize; | - |
1170 | if (s.version() >= 4) | - |
1171 | s >> pixelSize; | - |
1172 | font.d->request.pointSize = qreal(pointSize / 10.); | - |
1173 | font.d->request.pixelSize = pixelSize; | - |
1174 | } | - |
1175 | s >> styleHint; | - |
1176 | if (s.version() >= QDataStream::Qt_3_1) | - |
1177 | s >> styleStrategy; | - |
1178 | | - |
1179 | s >> charSet; | - |
1180 | s >> weight; | - |
1181 | s >> bits; | - |
1182 | | - |
1183 | font.d->request.styleHint = styleHint; | - |
1184 | font.d->request.styleStrategy = styleStrategy; | - |
1185 | font.d->request.weight = weight; | - |
1186 | | - |
1187 | set_font_bits(s.version(), bits, font.d.data()); | - |
1188 | | - |
1189 | if (s.version() >= QDataStream::Qt_4_3) { | - |
1190 | quint16 stretch; | - |
1191 | s >> stretch; | - |
1192 | font.d->request.stretch = stretch; | - |
1193 | } | - |
1194 | | - |
1195 | if (s.version() >= QDataStream::Qt_4_4) { | - |
1196 | quint8 extendedBits; | - |
1197 | s >> extendedBits; | - |
1198 | set_extended_font_bits(extendedBits, font.d.data()); | - |
1199 | } | - |
1200 | if (s.version() >= QDataStream::Qt_4_5) { | - |
1201 | int value; | - |
1202 | s >> value; | - |
1203 | font.d->letterSpacing.setValue(value); | - |
1204 | s >> value; | - |
1205 | font.d->wordSpacing.setValue(value); | - |
1206 | } | - |
1207 | | - |
1208 | return s; | - |
1209 | } | - |
1210 | QFontInfo::QFontInfo(const QFont &font) | - |
1211 | : d(font.d.data()) | - |
1212 | { | - |
1213 | } | - |
1214 | | - |
1215 | | - |
1216 | | - |
1217 | | - |
1218 | QFontInfo::QFontInfo(const QFontInfo &fi) | - |
1219 | : d(fi.d.data()) | - |
1220 | { | - |
1221 | } | - |
1222 | | - |
1223 | | - |
1224 | | - |
1225 | | - |
1226 | QFontInfo::~QFontInfo() | - |
1227 | { | - |
1228 | } | - |
1229 | | - |
1230 | | - |
1231 | | - |
1232 | | - |
1233 | QFontInfo &QFontInfo::operator=(const QFontInfo &fi) | - |
1234 | { | - |
1235 | d = fi.d.data(); | - |
1236 | return *this; | - |
1237 | } | - |
1238 | QString QFontInfo::family() const | - |
1239 | { | - |
1240 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
1241 | qt_noop(); | - |
1242 | return engine->fontDef.family; | - |
1243 | } | - |
1244 | QString QFontInfo::styleName() const | - |
1245 | { | - |
1246 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
1247 | qt_noop(); | - |
1248 | return engine->fontDef.styleName; | - |
1249 | } | - |
1250 | | - |
1251 | | - |
1252 | | - |
1253 | | - |
1254 | | - |
1255 | | - |
1256 | int QFontInfo::pointSize() const | - |
1257 | { | - |
1258 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
1259 | qt_noop(); | - |
1260 | return qRound(engine->fontDef.pointSize); | - |
1261 | } | - |
1262 | | - |
1263 | | - |
1264 | | - |
1265 | | - |
1266 | | - |
1267 | | - |
1268 | qreal QFontInfo::pointSizeF() const | - |
1269 | { | - |
1270 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
1271 | qt_noop(); | - |
1272 | return engine->fontDef.pointSize; | - |
1273 | } | - |
1274 | | - |
1275 | | - |
1276 | | - |
1277 | | - |
1278 | | - |
1279 | | - |
1280 | int QFontInfo::pixelSize() const | - |
1281 | { | - |
1282 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
1283 | qt_noop(); | - |
1284 | return engine->fontDef.pixelSize; | - |
1285 | } | - |
1286 | | - |
1287 | | - |
1288 | | - |
1289 | | - |
1290 | | - |
1291 | | - |
1292 | bool QFontInfo::italic() const | - |
1293 | { | - |
1294 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
1295 | qt_noop(); | - |
1296 | return engine->fontDef.style != QFont::StyleNormal; | - |
1297 | } | - |
1298 | | - |
1299 | | - |
1300 | | - |
1301 | | - |
1302 | | - |
1303 | | - |
1304 | QFont::Style QFontInfo::style() const | - |
1305 | { | - |
1306 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
1307 | qt_noop(); | - |
1308 | return (QFont::Style)engine->fontDef.style; | - |
1309 | } | - |
1310 | | - |
1311 | | - |
1312 | | - |
1313 | | - |
1314 | | - |
1315 | | - |
1316 | int QFontInfo::weight() const | - |
1317 | { | - |
1318 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
1319 | qt_noop(); | - |
1320 | return engine->fontDef.weight; | - |
1321 | | - |
1322 | } | - |
1323 | bool QFontInfo::underline() const | - |
1324 | { | - |
1325 | return d->underline; | - |
1326 | } | - |
1327 | bool QFontInfo::overline() const | - |
1328 | { | - |
1329 | return d->overline; | - |
1330 | } | - |
1331 | bool QFontInfo::strikeOut() const | - |
1332 | { | - |
1333 | return d->strikeOut; | - |
1334 | } | - |
1335 | | - |
1336 | | - |
1337 | | - |
1338 | | - |
1339 | | - |
1340 | | - |
1341 | bool QFontInfo::fixedPitch() const | - |
1342 | { | - |
1343 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
1344 | qt_noop(); | - |
1345 | return engine->fontDef.fixedPitch; | - |
1346 | } | - |
1347 | QFont::StyleHint QFontInfo::styleHint() const | - |
1348 | { | - |
1349 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
1350 | qt_noop(); | - |
1351 | return (QFont::StyleHint) engine->fontDef.styleHint; | - |
1352 | } | - |
1353 | bool QFontInfo::rawMode() const | - |
1354 | { | - |
1355 | return d->rawMode; | - |
1356 | } | - |
1357 | | - |
1358 | | - |
1359 | | - |
1360 | | - |
1361 | | - |
1362 | | - |
1363 | | - |
1364 | bool QFontInfo::exactMatch() const | - |
1365 | { | - |
1366 | QFontEngine *engine = d->engineForScript(QUnicodeTables::Common); | - |
1367 | qt_noop(); | - |
1368 | return (d->rawMode | - |
1369 | ? engine->type() != QFontEngine::Box | - |
1370 | : d->request.exactMatch(engine->fontDef)); | - |
1371 | } | - |
1372 | static const int fast_timeout = 10000; | - |
1373 | static const int slow_timeout = 300000; | - |
1374 | | - |
1375 | | - |
1376 | const uint QFontCache::min_cost = 4*1024; | - |
1377 | static QThreadStorage<QFontCache *> *theFontCache() { static QGlobalStatic<QThreadStorage<QFontCache *> > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QThreadStorage<QFontCache *> *x = new QThreadStorage<QFontCache *>; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QThreadStorage<QFontCache *> > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); } | - |
1378 | | - |
1379 | QFontCache *QFontCache::instance() | - |
1380 | { | - |
1381 | QFontCache *&fontCache = theFontCache()->localData(); | - |
1382 | if (!fontCache) | - |
1383 | fontCache = new QFontCache; | - |
1384 | return fontCache; | - |
1385 | } | - |
1386 | | - |
1387 | void QFontCache::cleanup() | - |
1388 | { | - |
1389 | QThreadStorage<QFontCache *> *cache = 0; | - |
1390 | if (true) { | - |
1391 | cache = theFontCache(); | - |
1392 | } else { | - |
1393 | | - |
1394 | } | - |
1395 | if (cache && cache->hasLocalData()) | - |
1396 | cache->setLocalData(0); | - |
1397 | } | - |
1398 | | - |
1399 | | - |
1400 | QFontCache::QFontCache() | - |
1401 | : QObject(), total_cost(0), max_cost(min_cost), | - |
1402 | current_timestamp(0), fast(false), timer_id(-1) | - |
1403 | { | - |
1404 | } | - |
1405 | | - |
1406 | QFontCache::~QFontCache() | - |
1407 | { | - |
1408 | clear(); | - |
1409 | { | - |
1410 | EngineDataCache::ConstIterator it = engineDataCache.constBegin(), | - |
1411 | end = engineDataCache.constEnd(); | - |
1412 | while (it != end) { | - |
1413 | if (it.value()->ref.load() == 0) | - |
1414 | delete it.value(); | - |
1415 | else | - |
1416 | if (false) QMessageLogger("text/qfont.cpp", 2646, __PRETTY_FUNCTION__).debug("QFontCache::~QFontCache: engineData %p still has refcount %d", | - |
1417 | it.value(), it.value()->ref.load()); | - |
1418 | ++it; | - |
1419 | } | - |
1420 | } | - |
1421 | EngineCache::ConstIterator it = engineCache.constBegin(), | - |
1422 | end = engineCache.constEnd(); | - |
1423 | while (it != end) { | - |
1424 | if (--it.value().data->cache_count == 0) { | - |
1425 | if (it.value().data->ref.load() == 0) { | - |
1426 | if (false) QMessageLogger("text/qfont.cpp", 2656, __PRETTY_FUNCTION__).debug("QFontCache::~QFontCache: deleting engine %p key=(%d / %g %g %d %d %d)", | - |
1427 | it.value().data, it.key().script, it.key().def.pointSize, | - |
1428 | it.key().def.pixelSize, it.key().def.weight, it.key().def.style, | - |
1429 | it.key().def.fixedPitch); | - |
1430 | | - |
1431 | delete it.value().data; | - |
1432 | } else { | - |
1433 | if (false) QMessageLogger("text/qfont.cpp", 2663, __PRETTY_FUNCTION__).debug("QFontCache::~QFontCache: engine = %p still has refcount %d", | - |
1434 | it.value().data, it.value().data->ref.load()); | - |
1435 | } | - |
1436 | } | - |
1437 | ++it; | - |
1438 | } | - |
1439 | } | - |
1440 | | - |
1441 | void QFontCache::clear() | - |
1442 | { | - |
1443 | { | - |
1444 | EngineDataCache::Iterator it = engineDataCache.begin(), | - |
1445 | end = engineDataCache.end(); | - |
1446 | while (it != end) { | - |
1447 | QFontEngineData *data = it.value(); | - |
1448 | for (int i = 0; i < QUnicodeTables::ScriptCount; ++i) { | - |
1449 | if (data->engines[i]) { | - |
1450 | data->engines[i]->ref.deref(); | - |
1451 | data->engines[i] = 0; | - |
1452 | } | - |
1453 | } | - |
1454 | ++it; | - |
1455 | } | - |
1456 | } | - |
1457 | | - |
1458 | for (EngineCache::Iterator it = engineCache.begin(), end = engineCache.end(); | - |
1459 | it != end; ++it) { | - |
1460 | if (it->data->ref.load() == 0) { | - |
1461 | delete it->data; | - |
1462 | it->data = 0; | - |
1463 | } | - |
1464 | } | - |
1465 | | - |
1466 | for (EngineCache::Iterator it = engineCache.begin(), end = engineCache.end(); | - |
1467 | it != end; ++it) { | - |
1468 | if (it->data && it->data->ref.load() == 0) { | - |
1469 | delete it->data; | - |
1470 | it->data = 0; | - |
1471 | } | - |
1472 | } | - |
1473 | | - |
1474 | engineCache.clear(); | - |
1475 | } | - |
1476 | | - |
1477 | | - |
1478 | QFontEngineData *QFontCache::findEngineData(const QFontDef &def) const | - |
1479 | { | - |
1480 | EngineDataCache::ConstIterator it = engineDataCache.constFind(def); | - |
1481 | if (it == engineDataCache.constEnd()) | - |
1482 | return 0; | - |
1483 | | - |
1484 | | - |
1485 | return it.value(); | - |
1486 | } | - |
1487 | | - |
1488 | void QFontCache::insertEngineData(const QFontDef &def, QFontEngineData *engineData) | - |
1489 | { | - |
1490 | if (false) QMessageLogger("text/qfont.cpp", 2720, __PRETTY_FUNCTION__).debug("QFontCache: inserting new engine data %p", engineData); | - |
1491 | | - |
1492 | engineDataCache.insert(def, engineData); | - |
1493 | increaseCost(sizeof(QFontEngineData)); | - |
1494 | } | - |
1495 | | - |
1496 | QFontEngine *QFontCache::findEngine(const Key &key) | - |
1497 | { | - |
1498 | EngineCache::Iterator it = engineCache.find(key), | - |
1499 | end = engineCache.end(); | - |
1500 | if (it == end) return 0; | - |
1501 | | - |
1502 | updateHitCountAndTimeStamp(it.value()); | - |
1503 | | - |
1504 | return it.value().data; | - |
1505 | } | - |
1506 | | - |
1507 | void QFontCache::updateHitCountAndTimeStamp(Engine &value) | - |
1508 | { | - |
1509 | value.hits++; | - |
1510 | value.timestamp = ++current_timestamp; | - |
1511 | | - |
1512 | if (false) QMessageLogger("text/qfont.cpp", 2742, __PRETTY_FUNCTION__).debug("QFontCache: found font engine\n" | - |
1513 | " %p: timestamp %4u hits %3u ref %2d/%2d, type '%s'", | - |
1514 | value.data, value.timestamp, value.hits, | - |
1515 | value.data->ref.load(), value.data->cache_count, | - |
1516 | value.data->name()); | - |
1517 | } | - |
1518 | | - |
1519 | void QFontCache::insertEngine(const Key &key, QFontEngine *engine, bool insertMulti) | - |
1520 | { | - |
1521 | if (false) QMessageLogger("text/qfont.cpp", 2751, __PRETTY_FUNCTION__).debug("QFontCache: inserting new engine %p", engine); | - |
1522 | | - |
1523 | Engine data(engine); | - |
1524 | data.timestamp = ++current_timestamp; | - |
1525 | | - |
1526 | if (insertMulti) | - |
1527 | engineCache.insertMulti(key, data); | - |
1528 | else | - |
1529 | engineCache.insert(key, data); | - |
1530 | | - |
1531 | | - |
1532 | if (engine->cache_count == 0) | - |
1533 | increaseCost(engine->cache_cost); | - |
1534 | | - |
1535 | ++engine->cache_count; | - |
1536 | } | - |
1537 | | - |
1538 | void QFontCache::increaseCost(uint cost) | - |
1539 | { | - |
1540 | cost = (cost + 512) / 1024; | - |
1541 | cost = cost > 0 ? cost : 1; | - |
1542 | total_cost += cost; | - |
1543 | | - |
1544 | if (false) QMessageLogger("text/qfont.cpp", 2774, __PRETTY_FUNCTION__).debug(" COST: increased %u kb, total_cost %u kb, max_cost %u kb", | - |
1545 | cost, total_cost, max_cost); | - |
1546 | | - |
1547 | if (total_cost > max_cost) { | - |
1548 | max_cost = total_cost; | - |
1549 | | - |
1550 | if (timer_id == -1 || ! fast) { | - |
1551 | if (false) QMessageLogger("text/qfont.cpp", 2781, __PRETTY_FUNCTION__).debug(" TIMER: starting fast timer (%d ms)", fast_timeout); | - |
1552 | | - |
1553 | if (timer_id != -1) killTimer(timer_id); | - |
1554 | timer_id = startTimer(fast_timeout); | - |
1555 | fast = true; | - |
1556 | } | - |
1557 | } | - |
1558 | } | - |
1559 | | - |
1560 | void QFontCache::decreaseCost(uint cost) | - |
1561 | { | - |
1562 | cost = (cost + 512) / 1024; | - |
1563 | cost = cost > 0 ? cost : 1; | - |
1564 | qt_noop(); | - |
1565 | total_cost -= cost; | - |
1566 | | - |
1567 | if (false) QMessageLogger("text/qfont.cpp", 2797, __PRETTY_FUNCTION__).debug(" COST: decreased %u kb, total_cost %u kb, max_cost %u kb", | - |
1568 | cost, total_cost, max_cost); | - |
1569 | } | - |
1570 | | - |
1571 | void QFontCache::timerEvent(QTimerEvent *) | - |
1572 | { | - |
1573 | if (false) QMessageLogger("text/qfont.cpp", 2803, __PRETTY_FUNCTION__).debug("QFontCache::timerEvent: performing cache maintenance (timestamp %u)", | - |
1574 | current_timestamp); | - |
1575 | | - |
1576 | if (total_cost <= max_cost && max_cost <= min_cost) { | - |
1577 | if (false) QMessageLogger("text/qfont.cpp", 2807, __PRETTY_FUNCTION__).debug(" cache redused sufficiently, stopping timer"); | - |
1578 | | - |
1579 | killTimer(timer_id); | - |
1580 | timer_id = -1; | - |
1581 | fast = false; | - |
1582 | | - |
1583 | return; | - |
1584 | } | - |
1585 | | - |
1586 | | - |
1587 | uint in_use_cost = 0; | - |
1588 | | - |
1589 | { | - |
1590 | if (false) QMessageLogger("text/qfont.cpp", 2820, __PRETTY_FUNCTION__).debug(" SWEEP engine data:"); | - |
1591 | | - |
1592 | | - |
1593 | const uint engine_data_cost = | - |
1594 | sizeof(QFontEngineData) > 1024 ? sizeof(QFontEngineData) : 1024; | - |
1595 | | - |
1596 | EngineDataCache::ConstIterator it = engineDataCache.constBegin(), | - |
1597 | end = engineDataCache.constEnd(); | - |
1598 | for (; it != end; ++it) { | - |
1599 | | - |
1600 | | - |
1601 | | - |
1602 | | - |
1603 | | - |
1604 | if (it.value()->ref.load() != 0) | - |
1605 | in_use_cost += engine_data_cost; | - |
1606 | } | - |
1607 | } | - |
1608 | | - |
1609 | { | - |
1610 | if (false) QMessageLogger("text/qfont.cpp", 2840, __PRETTY_FUNCTION__).debug(" SWEEP engine:"); | - |
1611 | | - |
1612 | EngineCache::ConstIterator it = engineCache.constBegin(), | - |
1613 | end = engineCache.constEnd(); | - |
1614 | for (; it != end; ++it) { | - |
1615 | if (false) QMessageLogger("text/qfont.cpp", 2845, __PRETTY_FUNCTION__).debug(" %p: timestamp %4u hits %2u ref %2d/%2d, cost %u bytes", | - |
1616 | it.value().data, it.value().timestamp, it.value().hits, | - |
1617 | it.value().data->ref.load(), it.value().data->cache_count, | - |
1618 | it.value().data->cache_cost); | - |
1619 | | - |
1620 | if (it.value().data->ref.load() != 0) | - |
1621 | in_use_cost += it.value().data->cache_cost / it.value().data->cache_count; | - |
1622 | } | - |
1623 | | - |
1624 | | - |
1625 | in_use_cost += engineCache.size(); | - |
1626 | } | - |
1627 | | - |
1628 | in_use_cost = (in_use_cost + 512) / 1024; | - |
1629 | uint new_max_cost = qMax(qMax(max_cost / 2, in_use_cost), min_cost); | - |
1630 | | - |
1631 | if (false) QMessageLogger("text/qfont.cpp", 2870, __PRETTY_FUNCTION__).debug(" after sweep, in use %u kb, total %u kb, max %u kb, new max %u kb", | - |
1632 | in_use_cost, total_cost, max_cost, new_max_cost); | - |
1633 | | - |
1634 | if (new_max_cost == max_cost) { | - |
1635 | if (fast) { | - |
1636 | if (false) QMessageLogger("text/qfont.cpp", 2875, __PRETTY_FUNCTION__).debug(" cannot shrink cache, slowing timer"); | - |
1637 | | - |
1638 | killTimer(timer_id); | - |
1639 | timer_id = startTimer(slow_timeout); | - |
1640 | fast = false; | - |
1641 | } | - |
1642 | | - |
1643 | return; | - |
1644 | } else if (! fast) { | - |
1645 | if (false) QMessageLogger("text/qfont.cpp", 2884, __PRETTY_FUNCTION__).debug(" dropping into passing gear"); | - |
1646 | | - |
1647 | killTimer(timer_id); | - |
1648 | timer_id = startTimer(fast_timeout); | - |
1649 | fast = true; | - |
1650 | } | - |
1651 | | - |
1652 | max_cost = new_max_cost; | - |
1653 | | - |
1654 | { | - |
1655 | if (false) QMessageLogger("text/qfont.cpp", 2894, __PRETTY_FUNCTION__).debug(" CLEAN engine data:"); | - |
1656 | | - |
1657 | | - |
1658 | EngineDataCache::Iterator it = engineDataCache.begin(), | - |
1659 | end = engineDataCache.end(); | - |
1660 | while (it != end) { | - |
1661 | if (it.value()->ref.load() != 0) { | - |
1662 | ++it; | - |
1663 | continue; | - |
1664 | } | - |
1665 | | - |
1666 | EngineDataCache::Iterator rem = it++; | - |
1667 | | - |
1668 | decreaseCost(sizeof(QFontEngineData)); | - |
1669 | | - |
1670 | if (false) QMessageLogger("text/qfont.cpp", 2909, __PRETTY_FUNCTION__).debug(" %p", rem.value()); | - |
1671 | | - |
1672 | delete rem.value(); | - |
1673 | engineDataCache.erase(rem); | - |
1674 | } | - |
1675 | } | - |
1676 | | - |
1677 | | - |
1678 | uint current_cost; | - |
1679 | do { | - |
1680 | current_cost = total_cost; | - |
1681 | | - |
1682 | EngineCache::Iterator it = engineCache.begin(), | - |
1683 | end = engineCache.end(); | - |
1684 | | - |
1685 | uint oldest = ~0u; | - |
1686 | uint least_popular = ~0u; | - |
1687 | | - |
1688 | for (; it != end; ++it) { | - |
1689 | if (it.value().data->ref.load() != 0) | - |
1690 | continue; | - |
1691 | | - |
1692 | if (it.value().timestamp < oldest && | - |
1693 | it.value().hits <= least_popular) { | - |
1694 | oldest = it.value().timestamp; | - |
1695 | least_popular = it.value().hits; | - |
1696 | } | - |
1697 | } | - |
1698 | | - |
1699 | if (false) QMessageLogger("text/qfont.cpp", 2938, __PRETTY_FUNCTION__).debug(" oldest %u least popular %u", oldest, least_popular); | - |
1700 | | - |
1701 | for (it = engineCache.begin(); it != end; ++it) { | - |
1702 | if (it.value().data->ref.load() == 0 && | - |
1703 | it.value().timestamp == oldest && | - |
1704 | it.value().hits == least_popular) | - |
1705 | break; | - |
1706 | } | - |
1707 | | - |
1708 | if (it != end) { | - |
1709 | if (false) QMessageLogger("text/qfont.cpp", 2948, __PRETTY_FUNCTION__).debug(" %p: timestamp %4u hits %2u ref %2d/%2d, type '%s'", | - |
1710 | it.value().data, it.value().timestamp, it.value().hits, | - |
1711 | it.value().data->ref.load(), it.value().data->cache_count, | - |
1712 | it.value().data->name()); | - |
1713 | | - |
1714 | if (--it.value().data->cache_count == 0) { | - |
1715 | if (false) QMessageLogger("text/qfont.cpp", 2954, __PRETTY_FUNCTION__).debug(" DELETE: last occurrence in cache"); | - |
1716 | | - |
1717 | decreaseCost(it.value().data->cache_cost); | - |
1718 | delete it.value().data; | - |
1719 | } else { | - |
1720 | | - |
1721 | | - |
1722 | | - |
1723 | | - |
1724 | | - |
1725 | current_cost = 0; | - |
1726 | } | - |
1727 | | - |
1728 | engineCache.erase(it); | - |
1729 | } | - |
1730 | } while (current_cost != total_cost && total_cost > max_cost); | - |
1731 | } | - |
1732 | | - |
1733 | | - |
1734 | | - |
1735 | QDebug operator<<(QDebug stream, const QFont &font) | - |
1736 | { | - |
1737 | return stream << "QFont(" << font.toString() << ')'; | - |
1738 | } | - |
1739 | | - |
1740 | | - |
1741 | | - |
1742 | | - |
| | |