Qt 4.8
qfont.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 "qapplication.h"
52 #include "qstringlist.h"
53 
54 #include "qthread.h"
55 #include "qthreadstorage.h"
56 
57 #include <private/qunicodetables_p.h>
58 #include "qfont_p.h"
59 #include <private/qfontengine_p.h>
60 #include <private/qpainter_p.h>
61 #include <private/qtextengine_p.h>
62 #include <limits.h>
63 
64 #ifdef Q_WS_X11
65 #include "qx11info_x11.h"
66 #include <private/qt_x11_p.h>
67 #endif
68 #ifdef Q_WS_QWS
69 #include "qscreen_qws.h"
70 #if !defined(QT_NO_QWS_QPF2)
71 #include <qfile.h>
72 #include "qfontengine_qpf_p.h"
73 #endif
74 #endif
75 #ifdef Q_OS_SYMBIAN
76 #include <private/qt_s60_p.h>
77 #endif
78 #ifdef Q_WS_QPA
79 #include <QtGui/qplatformscreen_qpa.h>
80 #include <QtGui/private/qapplication_p.h>
81 #endif
82 
83 #include <QMutexLocker>
84 
85 // #define QFONTCACHE_DEBUG
86 #ifdef QFONTCACHE_DEBUG
87 # define FC_DEBUG qDebug
88 #else
89 # define FC_DEBUG if (false) qDebug
90 #endif
91 
93 
94 #ifdef Q_WS_WIN
95 extern HDC shared_dc();
96 #endif
97 
98 #ifdef Q_WS_X11
99 extern const QX11Info *qt_x11Info(const QPaintDevice *pd);
100 #endif
101 
102 bool QFontDef::exactMatch(const QFontDef &other) const
103 {
104  /*
105  QFontDef comparison is more complicated than just simple
106  per-member comparisons.
107 
108  When comparing point/pixel sizes, either point or pixelsize
109  could be -1. in This case we have to compare the non negative
110  size value.
111 
112  This test will fail if the point-sizes differ by 1/2 point or
113  more or they do not round to the same value. We have to do this
114  since our API still uses 'int' point-sizes in the API, but store
115  deci-point-sizes internally.
116 
117  To compare the family members, we need to parse the font names
118  and compare the family/foundry strings separately. This allows
119  us to compare e.g. "Helvetica" and "Helvetica [Adobe]" with
120  positive results.
121  */
122  if (pixelSize != -1 && other.pixelSize != -1) {
123  if (pixelSize != other.pixelSize)
124  return false;
125  } else if (pointSize != -1 && other.pointSize != -1) {
126  if (pointSize != other.pointSize)
127  return false;
128  } else {
129  return false;
130  }
131 
132  if (!ignorePitch && !other.ignorePitch && fixedPitch != other.fixedPitch)
133  return false;
134 
135  if (stretch != 0 && other.stretch != 0 && stretch != other.stretch)
136  return false;
137 
138  QString this_family, this_foundry, other_family, other_foundry;
139  QFontDatabase::parseFontName(family, this_foundry, this_family);
140  QFontDatabase::parseFontName(other.family, other_foundry, other_family);
141 
142  this_family = QFontDatabase::resolveFontFamilyAlias(this_family);
143  other_family = QFontDatabase::resolveFontFamilyAlias(other_family);
144 
145  return (styleHint == other.styleHint
146  && styleStrategy == other.styleStrategy
147  && weight == other.weight
148  && style == other.style
149  && this_family == other_family
150  && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName)
151  && (this_foundry.isEmpty()
152  || other_foundry.isEmpty()
153  || this_foundry == other_foundry)
154 #ifdef Q_WS_X11
155  && addStyle == other.addStyle
156 #endif // Q_WS_X11
157  );
158 }
159 
160 extern bool qt_is_gui_used;
161 
163 {
164  if (!qt_is_gui_used)
165  return 75;
166 
167  int dpi;
168 #ifdef Q_WS_X11
169  dpi = QX11Info::appDpiX();
170 #elif defined(Q_WS_WIN)
171  dpi = GetDeviceCaps(shared_dc(),LOGPIXELSX);
172 #elif defined(Q_WS_MAC)
173  extern float qt_mac_defaultDpi_x(); //qpaintdevice_mac.cpp
174  dpi = qt_mac_defaultDpi_x();
175 #elif defined(Q_WS_QWS)
176  if (!qt_screen)
177  return 72;
178  QScreen *screen = qt_screen;
179  const QList<QScreen*> subScreens = qt_screen->subScreens();
180  if (!subScreens.isEmpty())
181  screen = subScreens.at(0);
182  dpi = qRound(screen->width() / (screen->physicalWidth() / qreal(25.4)));
183 #elif defined(Q_WS_QPA)
184  QPlatformIntegration *pi = QApplicationPrivate::platformIntegration();
185  if (pi) {
186  QPlatformScreen *screen = QApplicationPrivate::platformIntegration()->screens().at(0);
187  const QSize screenSize = screen->geometry().size();
188  const QSize physicalSize = screen->physicalSize();
189  dpi = qRound(screenSize.width() / (physicalSize.width() / qreal(25.4)));
190  } else {
191  //PI has not been initialised, or it is being initialised. Give a default dpi
192  dpi = 100;
193  }
194 #elif defined(Q_OS_SYMBIAN)
195  dpi = S60->defaultDpiX;
196 #endif // Q_WS_X11
197 
198  return dpi;
199 }
200 
202 {
203  if (!qt_is_gui_used)
204  return 75;
205 
206  int dpi;
207 #ifdef Q_WS_X11
208  dpi = QX11Info::appDpiY();
209 #elif defined(Q_WS_WIN)
210  dpi = GetDeviceCaps(shared_dc(),LOGPIXELSY);
211 #elif defined(Q_WS_MAC)
212  extern float qt_mac_defaultDpi_y(); //qpaintdevice_mac.cpp
213  dpi = qt_mac_defaultDpi_y();
214 #elif defined(Q_WS_QWS)
215  if (!qt_screen)
216  return 72;
217  QScreen *screen = qt_screen;
218  const QList<QScreen*> subScreens = qt_screen->subScreens();
219  if (!subScreens.isEmpty())
220  screen = subScreens.at(0);
221  dpi = qRound(screen->height() / (screen->physicalHeight() / qreal(25.4)));
222 #elif defined(Q_WS_QPA)
223  QPlatformIntegration *pi = QApplicationPrivate::platformIntegration();
224  if (pi) {
225  QPlatformScreen *screen = QApplicationPrivate::platformIntegration()->screens().at(0);
226  const QSize screenSize = screen->geometry().size();
227  const QSize physicalSize = screen->physicalSize();
228  dpi = qRound(screenSize.height() / (physicalSize.height() / qreal(25.4)));
229  } else {
230  //PI has not been initialised, or it is being initialised. Give a default dpi
231  dpi = 100;
232  }
233 #elif defined(Q_OS_SYMBIAN)
234  dpi = S60->defaultDpiY;
235 #endif // Q_WS_X11
236 
237  return dpi;
238 }
239 
241 {
242  return qt_defaultDpiY();
243 }
244 
246  : engineData(0), dpi(qt_defaultDpi()), screen(0),
247  rawMode(false), underline(false), overline(false), strikeOut(false), kerning(true),
248  capital(0), letterSpacingIsAbsolute(false), scFont(0)
249 {
250 #ifdef Q_WS_X11
251  if (QX11Info::display())
253  else
254  screen = 0;
255 #endif
256 #ifdef Q_WS_WIN
257  hdc = 0;
258 #endif
259 }
260 
262  : request(other.request), engineData(0), dpi(other.dpi), screen(other.screen),
263  rawMode(other.rawMode), underline(other.underline), overline(other.overline),
264  strikeOut(other.strikeOut), kerning(other.kerning),
267  scFont(other.scFont)
268 {
269 #ifdef Q_WS_WIN
270  hdc = other.hdc;
271 #endif
272  if (scFont && scFont != this)
273  scFont->ref.ref();
274 }
275 
277 {
278  if (engineData)
279  engineData->ref.deref();
280  engineData = 0;
281  if (scFont && scFont != this)
282  scFont->ref.deref();
283  scFont = 0;
284 }
285 
286 extern QMutex *qt_fontdatabase_mutex();
287 
288 #if !defined(Q_WS_MAC)
289 #define QT_FONT_ENGINE_FROM_DATA(data, script) data->engines[script]
290 #else
291 #define QT_FONT_ENGINE_FROM_DATA(data, script) data->engine
292 #endif
293 
295 {
297  if (script >= QUnicodeTables::Inherited)
298  script = QUnicodeTables::Common;
300  // throw out engineData that came from a different thread
301  engineData->ref.deref();
302  engineData = 0;
303  }
305  QFontDatabase::load(this, script);
306  return QT_FONT_ENGINE_FROM_DATA(engineData, script);
307 }
308 
310  switch (capital) {
311  case QFont::AllUppercase:
312  case QFont::SmallCaps:
313  c = c.toUpper();
314  break;
315  case QFont::AllLowercase:
316  c = c.toLower();
317  break;
318  case QFont::MixedCase:
319  break;
320  }
321 }
322 
324 {
325  if (scFont)
326  return scFont;
327  QFont font(const_cast<QFontPrivate *>(this));
328  qreal pointSize = font.pointSizeF();
329  if (pointSize > 0)
330  font.setPointSizeF(pointSize * .7);
331  else
332  font.setPixelSize((font.pixelSize() * 7 + 5) / 10);
333  scFont = font.d.data();
334  if (scFont != this)
335  scFont->ref.ref();
336  return scFont;
337 }
338 
339 
340 void QFontPrivate::resolve(uint mask, const QFontPrivate *other)
341 {
342  Q_ASSERT(other != 0);
343 
344  dpi = other->dpi;
345 
346  if ((mask & QFont::AllPropertiesResolved) == QFont::AllPropertiesResolved) return;
347 
348  // assign the unset-bits with the set-bits of the other font def
349  if (! (mask & QFont::FamilyResolved))
350  request.family = other->request.family;
351 
352  if (! (mask & QFont::StyleNameResolved))
354 
355  if (! (mask & QFont::SizeResolved)) {
358  }
359 
360  if (! (mask & QFont::StyleHintResolved))
362 
363  if (! (mask & QFont::StyleStrategyResolved))
365 
366  if (! (mask & QFont::WeightResolved))
367  request.weight = other->request.weight;
368 
369  if (! (mask & QFont::StyleResolved))
370  request.style = other->request.style;
371 
372  if (! (mask & QFont::FixedPitchResolved))
374 
375  if (! (mask & QFont::StretchResolved))
376  request.stretch = other->request.stretch;
377 
378  if (! (mask & QFont::HintingPreferenceResolved))
380 
381  if (! (mask & QFont::UnderlineResolved))
382  underline = other->underline;
383 
384  if (! (mask & QFont::OverlineResolved))
385  overline = other->overline;
386 
387  if (! (mask & QFont::StrikeOutResolved))
388  strikeOut = other->strikeOut;
389 
390  if (! (mask & QFont::KerningResolved))
391  kerning = other->kerning;
392 
393  if (! (mask & QFont::LetterSpacingResolved)) {
394  letterSpacing = other->letterSpacing;
396  }
397  if (! (mask & QFont::WordSpacingResolved))
398  wordSpacing = other->wordSpacing;
399  if (! (mask & QFont::CapitalizationResolved))
400  capital = other->capital;
401 }
402 
403 
404 
405 
407  : ref(1), fontCache(QFontCache::instance())
408 {
409 #if !defined(Q_WS_MAC)
410  memset(engines, 0, QUnicodeTables::ScriptCount * sizeof(QFontEngine *));
411 #else
412  engine = 0;
413 #endif
414 }
415 
417 {
418 #if !defined(Q_WS_MAC)
419  for (int i = 0; i < QUnicodeTables::ScriptCount; ++i) {
420  if (engines[i])
421  engines[i]->ref.deref();
422  engines[i] = 0;
423  }
424 #else
425  if (engine)
426  engine->ref.deref();
427  engine = 0;
428 #endif // Q_WS_X11 || Q_WS_WIN || Q_WS_MAC
429 }
430 
431 
432 
433 
765 QFont::QFont(const QFont &font, QPaintDevice *pd)
766  : resolve_mask(font.resolve_mask)
767 {
768  Q_ASSERT(pd != 0);
769  int dpi = pd->logicalDpiY();
770 #ifdef Q_WS_X11
771  const QX11Info *info = qt_x11Info(pd);
772  int screen = info ? info->screen() : 0;
773 #else
774  const int screen = 0;
775 #endif
776  if (font.d->dpi != dpi || font.d->screen != screen ) {
777  d = new QFontPrivate(*font.d);
778  d->dpi = dpi;
779  d->screen = screen;
780  } else {
781  d = font.d.data();
782  }
783 #ifdef Q_WS_WIN
784  if (pd->devType() == QInternal::Printer && pd->getDC())
785  d->hdc = pd->getDC();
786 #endif
787 }
788 
794 {
795 }
796 
804 {
805  if (d->ref == 1) {
806  if (d->engineData)
807  d->engineData->ref.deref();
808  d->engineData = 0;
809  if (d->scFont && d->scFont != d.data())
810  d->scFont->ref.deref();
811  d->scFont = 0;
812  return;
813  }
814 
815  d.detach();
816 }
817 
824  : d(QApplication::font().d.data()), resolve_mask(0)
825 {
826 }
827 
848 {
849  if (pointSize <= 0) {
850 #ifdef Q_OS_SYMBIAN
851  pointSize = 7;
852 #else
853  pointSize = 12;
854 #endif
855  } else {
857  }
858 
859  if (weight < 0) {
860  weight = Normal;
861  } else {
863  }
864 
865  if (italic)
867 
868  d->request.family = family;
869  d->request.pointSize = qreal(pointSize);
870  d->request.pixelSize = -1;
871  d->request.weight = weight;
873 }
874 
878 QFont::QFont(const QFont &font)
879  : d(font.d.data()), resolve_mask(font.resolve_mask)
880 {
881 }
882 
887 {
888 }
889 
894 {
895  d = font.d.data();
896  resolve_mask = font.resolve_mask;
897  return *this;
898 }
899 
907 {
908  return d->request.family;
909 }
910 
925 {
926  detach();
927 
928  d->request.family = family;
929 #if defined(Q_WS_X11)
930  d->request.addStyle.clear();
931 #endif // Q_WS_X11
932 
934 }
935 
951 {
952  return d->request.styleName;
953 }
954 
968 {
969  detach();
970 
973 }
974 
981 int QFont::pointSize() const
982 {
983  return qRound(d->request.pointSize);
984 }
985 
1072 {
1073  detach();
1074 
1076 
1078 }
1079 
1089 {
1091 }
1092 
1100 {
1101  if (pointSize <= 0) {
1102  qWarning("QFont::setPointSize: Point size <= 0 (%d), must be greater than 0", pointSize);
1103  return;
1104  }
1105 
1106  detach();
1107 
1108  d->request.pointSize = qreal(pointSize);
1109  d->request.pixelSize = -1;
1110 
1112 }
1113 
1122 {
1123  if (pointSize <= 0) {
1124  qWarning("QFont::setPointSizeF: Point size <= 0 (%f), must be greater than 0", pointSize);
1125  return;
1126  }
1127 
1128  detach();
1129 
1131  d->request.pixelSize = -1;
1132 
1134 }
1135 
1143 {
1144  return d->request.pointSize;
1145 }
1146 
1157 {
1158  if (pixelSize <= 0) {
1159  qWarning("QFont::setPixelSize: Pixel size <= 0 (%d)", pixelSize);
1160  return;
1161  }
1162 
1163  detach();
1164 
1166  d->request.pointSize = -1;
1167 
1169 }
1170 
1178 int QFont::pixelSize() const
1179 {
1180  return d->request.pixelSize;
1181 }
1182 
1183 #ifdef QT3_SUPPORT
1184 
1192 void QFont::setPixelSizeFloat(qreal pixelSize)
1193 {
1194  setPixelSize((int)pixelSize);
1195 }
1196 #endif
1197 
1224 {
1225  return (QFont::Style)d->request.style;
1226 }
1227 
1228 
1235 {
1236  detach();
1237 
1238  d->request.style = style;
1240 }
1241 
1248 int QFont::weight() const
1249 {
1250  return d->request.weight;
1251 }
1252 
1279 {
1280  Q_ASSERT_X(weight >= 0 && weight <= 99, "QFont::setWeight", "Weight must be between 0 and 99");
1281 
1282  detach();
1283 
1284  d->request.weight = weight;
1286 }
1287 
1320 bool QFont::underline() const
1321 {
1322  return d->underline;
1323 }
1324 
1331 void QFont::setUnderline(bool enable)
1332 {
1333  detach();
1334 
1335  d->underline = enable;
1337 }
1338 
1344 bool QFont::overline() const
1345 {
1346  return d->overline;
1347 }
1348 
1354 void QFont::setOverline(bool enable)
1355 {
1356  detach();
1357 
1358  d->overline = enable;
1360 }
1361 
1367 bool QFont::strikeOut() const
1368 {
1369  return d->strikeOut;
1370 }
1371 
1378 void QFont::setStrikeOut(bool enable)
1379 {
1380  detach();
1381 
1382  d->strikeOut = enable;
1384 }
1385 
1391 bool QFont::fixedPitch() const
1392 {
1393  return d->request.fixedPitch;
1394 }
1395 
1402 void QFont::setFixedPitch(bool enable)
1403 {
1404  detach();
1405 
1406  d->request.fixedPitch = enable;
1407  d->request.ignorePitch = false;
1409 }
1410 
1416 bool QFont::kerning() const
1417 {
1418  return d->kerning;
1419 }
1420 
1432 void QFont::setKerning(bool enable)
1433 {
1434  detach();
1435  d->kerning = enable;
1437 }
1438 
1448 {
1450 }
1451 
1461 {
1462  return (StyleHint) d->request.styleHint;
1463 }
1464 
1555 {
1556  detach();
1557 
1559  (StyleHint) d->request.styleHint == hint &&
1560  (StyleStrategy) d->request.styleStrategy == strategy)
1561  return;
1562 
1563  d->request.styleHint = hint;
1564  d->request.styleStrategy = strategy;
1567 
1568 #if defined(Q_WS_X11)
1569  d->request.addStyle.clear();
1570 #endif // Q_WS_X11
1571 }
1572 
1579 {
1580  detach();
1581 
1584  return;
1585 
1586  d->request.styleStrategy = s;
1588 }
1589 
1590 
1618 int QFont::stretch() const
1619 {
1620  return d->request.stretch;
1621 }
1622 
1641 void QFont::setStretch(int factor)
1642 {
1643  if (factor < 1 || factor > 4000) {
1644  qWarning("QFont::setStretch: Parameter '%d' out of range", factor);
1645  return;
1646  }
1647 
1649  d->request.stretch == (uint)factor)
1650  return;
1651 
1652  detach();
1653 
1654  d->request.stretch = (uint)factor;
1656 }
1657 
1678 {
1679  return d->letterSpacing.toReal();
1680 }
1681 
1697 {
1698  const QFixed newSpacing = QFixed::fromReal(spacing);
1699  const bool absoluteSpacing = type == AbsoluteSpacing;
1701  d->letterSpacingIsAbsolute == absoluteSpacing &&
1702  d->letterSpacing == newSpacing)
1703  return;
1704 
1705  detach();
1706 
1707  d->letterSpacing = newSpacing;
1708  d->letterSpacingIsAbsolute = absoluteSpacing;
1710 }
1711 
1722 {
1724 }
1725 
1736 {
1737  return d->wordSpacing.toReal();
1738 }
1739 
1758 {
1759  const QFixed newSpacing = QFixed::fromReal(spacing);
1761  d->wordSpacing == newSpacing)
1762  return;
1763 
1764  detach();
1765 
1766  d->wordSpacing = newSpacing;
1768 }
1769 
1799 {
1801  capitalization() == caps)
1802  return;
1803 
1804  detach();
1805 
1806  d->capital = caps;
1808 }
1809 
1820 {
1821  return static_cast<QFont::Capitalization> (d->capital);
1822 }
1823 
1824 
1842 void QFont::setRawMode(bool enable)
1843 {
1844  detach();
1845 
1846  if ((bool) d->rawMode == enable) return;
1847 
1848  d->rawMode = enable;
1849 }
1850 
1857 bool QFont::exactMatch() const
1858 {
1860  Q_ASSERT(engine != 0);
1861  return (d->rawMode
1862  ? engine->type() != QFontEngine::Box
1863  : d->request.exactMatch(engine->fontDef));
1864 }
1865 
1876 bool QFont::operator==(const QFont &f) const
1877 {
1878  return (f.d == d
1879  || (f.d->request == d->request
1880  && f.d->request.pointSize == d->request.pointSize
1881  && f.d->underline == d->underline
1882  && f.d->overline == d->overline
1883  && f.d->strikeOut == d->strikeOut
1884  && f.d->kerning == d->kerning
1885  && f.d->capital == d->capital
1887  && f.d->letterSpacing == d->letterSpacing
1888  && f.d->wordSpacing == d->wordSpacing
1889  ));
1890 }
1891 
1892 
1904 bool QFont::operator<(const QFont &f) const
1905 {
1906  if (f.d == d) return false;
1907  // the < operator for fontdefs ignores point sizes.
1908  QFontDef &r1 = f.d->request;
1909  QFontDef &r2 = d->request;
1910  if (r1.pointSize != r2.pointSize) return r1.pointSize < r2.pointSize;
1911  if (r1.pixelSize != r2.pixelSize) return r1.pixelSize < r2.pixelSize;
1912  if (r1.weight != r2.weight) return r1.weight < r2.weight;
1913  if (r1.style != r2.style) return r1.style < r2.style;
1914  if (r1.stretch != r2.stretch) return r1.stretch < r2.stretch;
1915  if (r1.styleHint != r2.styleHint) return r1.styleHint < r2.styleHint;
1916  if (r1.styleStrategy != r2.styleStrategy) return r1.styleStrategy < r2.styleStrategy;
1917  if (r1.family != r2.family) return r1.family < r2.family;
1918 #ifdef Q_WS_X11
1919  if (r1.addStyle != r2.addStyle) return r1.addStyle < r2.addStyle;
1920 #endif // Q_WS_X11
1921  if (f.d->capital != d->capital) return f.d->capital < d->capital;
1922 
1924  if (f.d->letterSpacing != d->letterSpacing) return f.d->letterSpacing < d->letterSpacing;
1925  if (f.d->wordSpacing != d->wordSpacing) return f.d->wordSpacing < d->wordSpacing;
1926 
1927  int f1attrs = (f.d->underline << 3) + (f.d->overline << 2) + (f.d->strikeOut<<1) + f.d->kerning;
1928  int f2attrs = (d->underline << 3) + (d->overline << 2) + (d->strikeOut<<1) + d->kerning;
1929  return f1attrs < f2attrs;
1930 }
1931 
1932 
1943 bool QFont::operator!=(const QFont &f) const
1944 {
1945  return !(operator==(f));
1946 }
1947 
1951 QFont::operator QVariant() const
1952 {
1953  return QVariant(QVariant::Font, this);
1954 }
1955 
1963 bool QFont::isCopyOf(const QFont & f) const
1964 {
1965  return d == f.d;
1966 }
1967 
1974 bool QFont::rawMode() const
1975 {
1976  return d->rawMode;
1977 }
1978 
1983 QFont QFont::resolve(const QFont &other) const
1984 {
1985  if (*this == other
1986  && (resolve_mask == other.resolve_mask || resolve_mask == 0)
1987  && d->dpi == other.d->dpi) {
1988  QFont o = other;
1990  return o;
1991  }
1992 
1993  QFont font(*this);
1994  font.detach();
1995  font.d->resolve(resolve_mask, other.d.data());
1996 
1997  return font;
1998 }
1999 
2010 #ifdef QT3_SUPPORT
2011 
2019 QFont QFont::defaultFont()
2020 {
2021  return QApplication::font();
2022 }
2023 
2031 void QFont::setDefaultFont(const QFont &f)
2032 {
2034 }
2035 
2055 #endif
2056 
2057 
2058 
2059 
2060 /*****************************************************************************
2061  QFont substitution management
2062  *****************************************************************************/
2063 
2065 Q_GLOBAL_STATIC(QFontSubst, globalFontSubst)
2066 
2067 // create substitution dict
2068 static void initFontSubst()
2069 {
2070  // default substitutions
2071  static const char * const initTbl[] = {
2072 
2073 #if defined(Q_WS_X11)
2074  "arial", "helvetica",
2075  "times new roman", "times",
2076  "courier new", "courier",
2077  "sans serif", "helvetica",
2078 #elif defined(Q_WS_MAC)
2079  ".lucida grande ui", "lucida grande",
2080 #elif defined(Q_WS_WIN)
2081  "times", "times new roman",
2082  "courier", "courier new",
2083  "helvetica", "arial",
2084  "sans serif", "arial",
2085 #endif
2086 
2087  0, 0
2088  };
2089 
2090  QFontSubst *fontSubst = globalFontSubst();
2091  Q_ASSERT(fontSubst != 0);
2092  if (!fontSubst->isEmpty())
2093  return;
2094 #if defined(Q_WS_X11) && !defined(QT_NO_FONTCONFIG)
2095  if (X11->has_fontconfig)
2096  return;
2097 #endif
2098 
2099  for (int i=0; initTbl[i] != 0; i += 2) {
2100  QStringList &list = (*fontSubst)[QString::fromLatin1(initTbl[i])];
2101  list.append(QString::fromLatin1(initTbl[i+1]));
2102  }
2103 }
2104 
2117 {
2118  initFontSubst();
2119 
2120  QFontSubst *fontSubst = globalFontSubst();
2121  Q_ASSERT(fontSubst != 0);
2122  QFontSubst::ConstIterator it = fontSubst->constFind(familyName.toLower());
2123  if (it != fontSubst->constEnd() && !(*it).isEmpty())
2124  return (*it).first();
2125 
2126  return familyName;
2127 }
2128 
2129 
2140 {
2141  initFontSubst();
2142 
2143  QFontSubst *fontSubst = globalFontSubst();
2144  Q_ASSERT(fontSubst != 0);
2145  return fontSubst->value(familyName.toLower(), QStringList());
2146 }
2147 
2148 
2155 void QFont::insertSubstitution(const QString &familyName,
2156  const QString &substituteName)
2157 {
2158  initFontSubst();
2159 
2160  QFontSubst *fontSubst = globalFontSubst();
2161  Q_ASSERT(fontSubst != 0);
2162  QStringList &list = (*fontSubst)[familyName.toLower()];
2163  QString s = substituteName.toLower();
2164  if (!list.contains(s))
2165  list.append(s);
2166 }
2167 
2168 
2175 void QFont::insertSubstitutions(const QString &familyName,
2176  const QStringList &substituteNames)
2177 {
2178  initFontSubst();
2179 
2180  QFontSubst *fontSubst = globalFontSubst();
2181  Q_ASSERT(fontSubst != 0);
2182  QStringList &list = (*fontSubst)[familyName.toLower()];
2183  QStringList::ConstIterator it = substituteNames.constBegin();
2184  while (it != substituteNames.constEnd()) {
2185  QString s = (*it).toLower();
2186  if (!list.contains(s))
2187  list.append(s);
2188  it++;
2189  }
2190 }
2191 
2212 // ### mark: should be called removeSubstitutions()
2218 void QFont::removeSubstitution(const QString &familyName)
2219 { // ### function name should be removeSubstitutions() or
2220  // ### removeSubstitutionList()
2221  initFontSubst();
2222 
2223  QFontSubst *fontSubst = globalFontSubst();
2224  Q_ASSERT(fontSubst != 0);
2225  fontSubst->remove(familyName.toLower());
2226 }
2227 
2228 
2235 {
2236  initFontSubst();
2237 
2238  QFontSubst *fontSubst = globalFontSubst();
2239  Q_ASSERT(fontSubst != 0);
2240  QStringList ret;
2241  QFontSubst::ConstIterator it = fontSubst->constBegin();
2242 
2243  while (it != fontSubst->constEnd()) {
2244  ret.append(it.key());
2245  ++it;
2246  }
2247 
2248  ret.sort();
2249  return ret;
2250 }
2251 
2252 
2253 /* \internal
2254  Internal function. Converts boolean font settings to an unsigned
2255  8-bit number. Used for serialization etc.
2256 */
2257 static quint8 get_font_bits(int version, const QFontPrivate *f)
2258 {
2259  Q_ASSERT(f != 0);
2260  quint8 bits = 0;
2261  if (f->request.style)
2262  bits |= 0x01;
2263  if (f->underline)
2264  bits |= 0x02;
2265  if (f->overline)
2266  bits |= 0x40;
2267  if (f->strikeOut)
2268  bits |= 0x04;
2269  if (f->request.fixedPitch)
2270  bits |= 0x08;
2271  // if (f.hintSetByUser)
2272  // bits |= 0x10;
2273  if (f->rawMode)
2274  bits |= 0x20;
2275  if (version >= QDataStream::Qt_4_0) {
2276  if (f->kerning)
2277  bits |= 0x10;
2278  }
2279  if (f->request.style == QFont::StyleOblique)
2280  bits |= 0x80;
2281  return bits;
2282 }
2283 
2285 {
2286  Q_ASSERT(f != 0);
2287  quint8 bits = 0;
2288  if (f->request.ignorePitch)
2289  bits |= 0x01;
2290  if (f->letterSpacingIsAbsolute)
2291  bits |= 0x02;
2292  return bits;
2293 }
2294 
2295 #ifndef QT_NO_DATASTREAM
2296 
2297 /* \internal
2298  Internal function. Sets boolean font settings from an unsigned
2299  8-bit number. Used for serialization etc.
2300 */
2301 static void set_font_bits(int version, quint8 bits, QFontPrivate *f)
2302 {
2303  Q_ASSERT(f != 0);
2304  f->request.style = (bits & 0x01) != 0 ? QFont::StyleItalic : QFont::StyleNormal;
2305  f->underline = (bits & 0x02) != 0;
2306  f->overline = (bits & 0x40) != 0;
2307  f->strikeOut = (bits & 0x04) != 0;
2308  f->request.fixedPitch = (bits & 0x08) != 0;
2309  // f->hintSetByUser = (bits & 0x10) != 0;
2310  f->rawMode = (bits & 0x20) != 0;
2311  if (version >= QDataStream::Qt_4_0)
2312  f->kerning = (bits & 0x10) != 0;
2313  if ((bits & 0x80) != 0)
2315 }
2316 
2318 {
2319  Q_ASSERT(f != 0);
2320  f->request.ignorePitch = (bits & 0x01) != 0;
2321  f->letterSpacingIsAbsolute = (bits & 0x02) != 0;
2322 }
2323 #endif
2324 
2325 
2333 {
2334  return toString();
2335 }
2336 
2345 {
2346  const QChar comma(QLatin1Char(','));
2347  return family() + comma +
2348  QString::number( pointSizeF()) + comma +
2349  QString::number( pixelSize()) + comma +
2350  QString::number((int) styleHint()) + comma +
2351  QString::number( weight()) + comma +
2352  QString::number((int) style()) + comma +
2353  QString::number((int) underline()) + comma +
2354  QString::number((int) strikeOut()) + comma +
2355  QString::number((int)fixedPitch()) + comma +
2356  QString::number((int) rawMode());
2357 }
2358 
2359 
2367 bool QFont::fromString(const QString &descrip)
2368 {
2369  QStringList l(descrip.split(QLatin1Char(',')));
2370 
2371  int count = l.count();
2372  if (!count || (count > 2 && count < 9) || count > 11) {
2373  qWarning("QFont::fromString: Invalid description '%s'",
2374  descrip.isEmpty() ? "(empty)" : descrip.toLatin1().data());
2375  return false;
2376  }
2377 
2378  setFamily(l[0]);
2379  if (count > 1 && l[1].toDouble() > 0.0)
2380  setPointSizeF(l[1].toDouble());
2381  if (count == 9) {
2382  setStyleHint((StyleHint) l[2].toInt());
2383  setWeight(qMax(qMin(99, l[3].toInt()), 0));
2384  setItalic(l[4].toInt());
2385  setUnderline(l[5].toInt());
2386  setStrikeOut(l[6].toInt());
2387  setFixedPitch(l[7].toInt());
2388  setRawMode(l[8].toInt());
2389  } else if (count == 10) {
2390  if (l[2].toInt() > 0)
2391  setPixelSize(l[2].toInt());
2392  setStyleHint((StyleHint) l[3].toInt());
2393  setWeight(qMax(qMin(99, l[4].toInt()), 0));
2394  setStyle((QFont::Style)l[5].toInt());
2395  setUnderline(l[6].toInt());
2396  setStrikeOut(l[7].toInt());
2397  setFixedPitch(l[8].toInt());
2398  setRawMode(l[9].toInt());
2399  }
2400  if (count >= 9 && !d->request.fixedPitch) // assume 'false' fixedPitch equals default
2401  d->request.ignorePitch = true;
2402 
2403  return true;
2404 }
2405 
2406 #if !defined(Q_WS_QWS)
2407 
2414 void QFont::cacheStatistics()
2415 {
2416 
2417 
2418 }
2419 #endif // !Q_WS_QWS
2420 
2421 
2422 
2423 /*****************************************************************************
2424  QFont stream functions
2425  *****************************************************************************/
2426 #ifndef QT_NO_DATASTREAM
2427 
2440 {
2441  if (s.version() == 1) {
2442  s << font.d->request.family.toLatin1();
2443  } else {
2444  s << font.d->request.family;
2445  }
2446 
2447  if (s.version() >= QDataStream::Qt_4_0) {
2448  // 4.0
2449  double pointSize = font.d->request.pointSize;
2451  s << pointSize;
2452  s << pixelSize;
2453  } else if (s.version() <= 3) {
2454  qint16 pointSize = (qint16) (font.d->request.pointSize * 10);
2455  if (pointSize < 0) {
2456 #ifdef Q_WS_X11
2457  pointSize = (qint16)(font.d->request.pixelSize*720/QX11Info::appDpiY());
2458 #else
2459  pointSize = (qint16)QFontInfo(font).pointSize() * 10;
2460 #endif
2461  }
2462  s << pointSize;
2463  } else {
2464  s << (qint16) (font.d->request.pointSize * 10);
2465  s << (qint16) font.d->request.pixelSize;
2466  }
2467 
2468  s << (quint8) font.d->request.styleHint;
2469  if (s.version() >= QDataStream::Qt_3_1)
2470  s << (quint8) font.d->request.styleStrategy;
2471  s << (quint8) 0
2472  << (quint8) font.d->request.weight
2473  << get_font_bits(s.version(), font.d.data());
2474  if (s.version() >= QDataStream::Qt_4_3)
2475  s << (quint16)font.d->request.stretch;
2476  if (s.version() >= QDataStream::Qt_4_4)
2477  s << get_extended_font_bits(font.d.data());
2478  if (s.version() >= QDataStream::Qt_4_5) {
2479  s << font.d->letterSpacing.value();
2480  s << font.d->wordSpacing.value();
2481  }
2482  return s;
2483 }
2484 
2485 
2498 {
2499  font.d = new QFontPrivate;
2501 
2503 
2504  if (s.version() == 1) {
2505  QByteArray fam;
2506  s >> fam;
2507  font.d->request.family = QString::fromLatin1(fam);
2508  } else {
2509  s >> font.d->request.family;
2510  }
2511 
2512  if (s.version() >= QDataStream::Qt_4_0) {
2513  // 4.0
2514  double pointSize;
2515  qint32 pixelSize;
2516  s >> pointSize;
2517  s >> pixelSize;
2518  font.d->request.pointSize = qreal(pointSize);
2519  font.d->request.pixelSize = pixelSize;
2520  } else {
2521  qint16 pointSize, pixelSize = -1;
2522  s >> pointSize;
2523  if (s.version() >= 4)
2524  s >> pixelSize;
2525  font.d->request.pointSize = qreal(pointSize / 10.);
2526  font.d->request.pixelSize = pixelSize;
2527  }
2528  s >> styleHint;
2529  if (s.version() >= QDataStream::Qt_3_1)
2530  s >> styleStrategy;
2531 
2532  s >> charSet;
2533  s >> weight;
2534  s >> bits;
2535 
2536  font.d->request.styleHint = styleHint;
2538  font.d->request.weight = weight;
2539 
2540  set_font_bits(s.version(), bits, font.d.data());
2541 
2542  if (s.version() >= QDataStream::Qt_4_3) {
2543  quint16 stretch;
2544  s >> stretch;
2545  font.d->request.stretch = stretch;
2546  }
2547 
2548  if (s.version() >= QDataStream::Qt_4_4) {
2549  quint8 extendedBits;
2550  s >> extendedBits;
2551  set_extended_font_bits(extendedBits, font.d.data());
2552  }
2553  if (s.version() >= QDataStream::Qt_4_5) {
2554  int value;
2555  s >> value;
2556  font.d->letterSpacing.setValue(value);
2557  s >> value;
2558  font.d->wordSpacing.setValue(value);
2559  }
2560 
2561  return s;
2562 }
2563 
2564 #endif // QT_NO_DATASTREAM
2565 
2566 
2567 /*****************************************************************************
2568  QFontInfo member functions
2569  *****************************************************************************/
2570 
2635  : d(font.d.data())
2636 {
2637 }
2638 
2643  : d(fi.d.data())
2644 {
2645 }
2646 
2651 {
2652 }
2653 
2658 {
2659  d = fi.d.data();
2660  return *this;
2661 }
2662 
2669 {
2671  Q_ASSERT(engine != 0);
2672  return engine->fontDef.family;
2673 }
2674 
2687 {
2689  Q_ASSERT(engine != 0);
2690  return engine->fontDef.styleName;
2691 }
2692 
2699 {
2701  Q_ASSERT(engine != 0);
2702  return qRound(engine->fontDef.pointSize);
2703 }
2704 
2711 {
2713  Q_ASSERT(engine != 0);
2714  return engine->fontDef.pointSize;
2715 }
2716 
2723 {
2725  Q_ASSERT(engine != 0);
2726  return engine->fontDef.pixelSize;
2727 }
2728 
2734 bool QFontInfo::italic() const
2735 {
2737  Q_ASSERT(engine != 0);
2738  return engine->fontDef.style != QFont::StyleNormal;
2739 }
2740 
2747 {
2749  Q_ASSERT(engine != 0);
2750  return (QFont::Style)engine->fontDef.style;
2751 }
2752 
2759 {
2761  Q_ASSERT(engine != 0);
2762  return engine->fontDef.weight;
2763 
2764 }
2765 
2789 {
2790  return d->underline;
2791 }
2792 
2804 {
2805  return d->overline;
2806 }
2807 
2817 {
2818  return d->strikeOut;
2819 }
2820 
2827 {
2829  Q_ASSERT(engine != 0);
2830 #ifdef Q_OS_MAC
2831  if (!engine->fontDef.fixedPitchComputed) {
2832  QChar ch[2] = { QLatin1Char('i'), QLatin1Char('m') };
2834  int l = 2;
2835  engine->stringToCMap(ch, 2, &g, &l, 0);
2836  engine->fontDef.fixedPitch = g.advances_x[0] == g.advances_x[1];
2837  engine->fontDef.fixedPitchComputed = true;
2838  }
2839 #endif
2840  return engine->fontDef.fixedPitch;
2841 }
2842 
2851 {
2853  Q_ASSERT(engine != 0);
2854  return (QFont::StyleHint) engine->fontDef.styleHint;
2855 }
2856 
2868 {
2869  return d->rawMode;
2870 }
2871 
2879 {
2881  Q_ASSERT(engine != 0);
2882  return (d->rawMode
2883  ? engine->type() != QFontEngine::Box
2884  : d->request.exactMatch(engine->fontDef));
2885 }
2886 
2887 
2888 
2889 
2890 // **********************************************************************
2891 // QFontCache
2892 // **********************************************************************
2893 
2894 #ifdef QFONTCACHE_DEBUG
2895 // fast timeouts for debugging
2896 static const int fast_timeout = 1000; // 1s
2897 static const int slow_timeout = 5000; // 5s
2898 #else
2899 static const int fast_timeout = 10000; // 10s
2900 static const int slow_timeout = 300000; // 5m
2901 #endif // QFONTCACHE_DEBUG
2902 
2903 const uint QFontCache::min_cost = 4*1024; // 4mb
2904 
2905 #ifdef QT_NO_THREAD
2906 Q_GLOBAL_STATIC(QFontCache, theFontCache)
2907 
2909 {
2910  return theFontCache();
2911 }
2912 
2913 void QFontCache::cleanup()
2914 {
2915 }
2916 #else
2918 
2920 {
2921  QFontCache *&fontCache = theFontCache()->localData();
2922  if (!fontCache)
2923  fontCache = new QFontCache;
2924  return fontCache;
2925 }
2926 
2928 {
2929  QThreadStorage<QFontCache *> *cache = 0;
2930  QT_TRY {
2931  cache = theFontCache();
2932  } QT_CATCH (const std::bad_alloc &) {
2933  // no cache - just ignore
2934  }
2935  if (cache && cache->hasLocalData())
2936  cache->setLocalData(0);
2937 }
2938 #endif // QT_NO_THREAD
2939 
2941  : QObject(), total_cost(0), max_cost(min_cost),
2942  current_timestamp(0), fast(false), timer_id(-1)
2943 {
2944 }
2945 
2947 {
2948  clear();
2949  {
2952  while (it != end) {
2953  if (it.value()->ref == 0)
2954  delete it.value();
2955  else
2956  FC_DEBUG("QFontCache::~QFontCache: engineData %p still has refcount %d",
2957  it.value(), int(it.value()->ref));
2958  ++it;
2959  }
2960  }
2962  end = engineCache.constEnd();
2963  while (it != end) {
2964  if (--it.value().data->cache_count == 0) {
2965  if (it.value().data->ref == 0) {
2966  FC_DEBUG("QFontCache::~QFontCache: deleting engine %p key=(%d / %g %g %d %d %d)",
2967  it.value().data, it.key().script, it.key().def.pointSize,
2968  it.key().def.pixelSize, it.key().def.weight, it.key().def.style,
2969  it.key().def.fixedPitch);
2970 
2971  delete it.value().data;
2972  } else {
2973  FC_DEBUG("QFontCache::~QFontCache: engine = %p still has refcount %d",
2974  it.value().data, int(it.value().data->ref));
2975  }
2976  }
2977  ++it;
2978  }
2979 }
2980 
2982 {
2983  {
2985  end = engineDataCache.end();
2986  while (it != end) {
2987  QFontEngineData *data = it.value();
2988 #if !defined(Q_WS_MAC)
2989  for (int i = 0; i < QUnicodeTables::ScriptCount; ++i) {
2990  if (data->engines[i]) {
2991  data->engines[i]->ref.deref();
2992  data->engines[i] = 0;
2993  }
2994  }
2995 #else
2996  if (data->engine) {
2997  data->engine->ref.deref();
2998  data->engine = 0;
2999  }
3000 #endif
3001  ++it;
3002  }
3003  }
3004 
3006  it != end; ++it) {
3007  if (it->data->ref == 0) {
3008  delete it->data;
3009  it->data = 0;
3010  }
3011  }
3012 
3014  it != end; ++it) {
3015  if (it->data && it->data->ref == 0) {
3016  delete it->data;
3017  it->data = 0;
3018  }
3019  }
3020 
3021  engineCache.clear();
3022 }
3023 
3024 #if defined(Q_WS_QWS) && !defined(QT_NO_QWS_QPF2)
3026 {
3027 
3028  /* This could be optimized but the code becomes much more complex if we want to handle multi
3029  * font engines and it is probably not worth it. Therefore we just clear the entire font cache.
3030  */
3031  Q_UNUSED(_fontName);
3032  clear();
3033 }
3034 #endif
3035 
3037 {
3039  end = engineDataCache.end();
3040  if (it == end) return 0;
3041 
3042  // found
3043  return it.value();
3044 }
3045 
3047 {
3048  FC_DEBUG("QFontCache: inserting new engine data %p", engineData);
3049 
3050  engineDataCache.insert(key, engineData);
3051  increaseCost(sizeof(QFontEngineData));
3052 }
3053 
3055 {
3057  end = engineCache.end();
3058  if (it == end) return 0;
3059 
3060  // found... update the hitcount and timestamp
3061  it.value().hits++;
3062  it.value().timestamp = ++current_timestamp;
3063 
3064  FC_DEBUG("QFontCache: found font engine\n"
3065  " %p: timestamp %4u hits %3u ref %2d/%2d, type '%s'",
3066  it.value().data, it.value().timestamp, it.value().hits,
3067  int(it.value().data->ref), it.value().data->cache_count,
3068  it.value().data->name());
3069 
3070  return it.value().data;
3071 }
3072 
3074 {
3075  FC_DEBUG("QFontCache: inserting new engine %p", engine);
3076 
3077  Engine data(engine);
3078  data.timestamp = ++current_timestamp;
3079 
3080  engineCache.insert(key, data);
3081 
3082  // only increase the cost if this is the first time we insert the engine
3083  if (engine->cache_count == 0)
3084  increaseCost(engine->cache_cost);
3085 
3086  ++engine->cache_count;
3087 }
3088 
3090 {
3091  cost = (cost + 512) / 1024; // store cost in kb
3092  cost = cost > 0 ? cost : 1;
3093  total_cost += cost;
3094 
3095  FC_DEBUG(" COST: increased %u kb, total_cost %u kb, max_cost %u kb",
3096  cost, total_cost, max_cost);
3097 
3098  if (total_cost > max_cost) {
3099  max_cost = total_cost;
3100 
3101  if (timer_id == -1 || ! fast) {
3102  FC_DEBUG(" TIMER: starting fast timer (%d ms)", fast_timeout);
3103 
3104  if (timer_id != -1) killTimer(timer_id);
3106  fast = true;
3107  }
3108  }
3109 }
3110 
3112 {
3113  cost = (cost + 512) / 1024; // cost is stored in kb
3114  cost = cost > 0 ? cost : 1;
3115  Q_ASSERT(cost <= total_cost);
3116  total_cost -= cost;
3117 
3118  FC_DEBUG(" COST: decreased %u kb, total_cost %u kb, max_cost %u kb",
3119  cost, total_cost, max_cost);
3120 }
3121 
3122 #if defined(Q_WS_WIN) || defined (Q_WS_QWS)
3124 {
3125  FC_DEBUG("QFontCache::cleanupPrinterFonts");
3126 
3127  {
3128  FC_DEBUG(" CLEAN engine data:");
3129 
3130  // clean out all unused engine data
3132  end = engineDataCache.end();
3133  while (it != end) {
3134  if (it.key().screen == 0) {
3135  ++it;
3136  continue;
3137  }
3138 
3139  if(it.value()->ref != 0) {
3140  for(int i = 0; i < QUnicodeTables::ScriptCount; ++i) {
3141  if(it.value()->engines[i]) {
3142  it.value()->engines[i]->ref.deref();
3143  it.value()->engines[i] = 0;
3144  }
3145  }
3146  ++it;
3147  } else {
3148 
3149  EngineDataCache::Iterator rem = it++;
3150 
3151  decreaseCost(sizeof(QFontEngineData));
3152 
3153  FC_DEBUG(" %p", rem.value());
3154 
3155  delete rem.value();
3156  engineDataCache.erase(rem);
3157  }
3158  }
3159  }
3160 
3162  end = engineCache.end();
3163  while(it != end) {
3164  if (it.value().data->ref != 0 || it.key().screen == 0) {
3165  ++it;
3166  continue;
3167  }
3168 
3169  FC_DEBUG(" %p: timestamp %4u hits %2u ref %2d/%2d, type '%s'",
3170  it.value().data, it.value().timestamp, it.value().hits,
3171  int(it.value().data->ref), it.value().data->cache_count,
3172  it.value().data->name());
3173 
3174  if (--it.value().data->cache_count == 0) {
3175  FC_DEBUG(" DELETE: last occurrence in cache");
3176 
3177  decreaseCost(it.value().data->cache_cost);
3178  delete it.value().data;
3179  }
3180 
3181  engineCache.erase(it++);
3182  }
3183 }
3184 #endif
3185 
3187 {
3188  FC_DEBUG("QFontCache::timerEvent: performing cache maintenance (timestamp %u)",
3190 
3191  if (total_cost <= max_cost && max_cost <= min_cost) {
3192  FC_DEBUG(" cache redused sufficiently, stopping timer");
3193 
3195  timer_id = -1;
3196  fast = false;
3197 
3198  return;
3199  }
3200 
3201  // go through the cache and count up everything in use
3202  uint in_use_cost = 0;
3203 
3204  {
3205  FC_DEBUG(" SWEEP engine data:");
3206 
3207  // make sure the cost of each engine data is at least 1kb
3208  const uint engine_data_cost =
3209  sizeof(QFontEngineData) > 1024 ? sizeof(QFontEngineData) : 1024;
3210 
3213  for (; it != end; ++it) {
3214 #ifdef QFONTCACHE_DEBUG
3215  FC_DEBUG(" %p: ref %2d", it.value(), int(it.value()->ref));
3216 
3217 # if defined(Q_WS_X11) || defined(Q_WS_WIN)
3218  // print out all engines
3219  for (int i = 0; i < QUnicodeTables::ScriptCount; ++i) {
3220  if (! it.value()->engines[i])
3221  continue;
3222  FC_DEBUG(" contains %p", it.value()->engines[i]);
3223  }
3224 # endif // Q_WS_X11 || Q_WS_WIN
3225 #endif // QFONTCACHE_DEBUG
3226 
3227  if (it.value()->ref != 0)
3228  in_use_cost += engine_data_cost;
3229  }
3230  }
3231 
3232  {
3233  FC_DEBUG(" SWEEP engine:");
3234 
3236  end = engineCache.constEnd();
3237  for (; it != end; ++it) {
3238  FC_DEBUG(" %p: timestamp %4u hits %2u ref %2d/%2d, cost %u bytes",
3239  it.value().data, it.value().timestamp, it.value().hits,
3240  int(it.value().data->ref), it.value().data->cache_count,
3241  it.value().data->cache_cost);
3242 
3243  if (it.value().data->ref != 0)
3244  in_use_cost += it.value().data->cache_cost / it.value().data->cache_count;
3245  }
3246 
3247  // attempt to make up for rounding errors
3248  in_use_cost += engineCache.size();
3249  }
3250 
3251  in_use_cost = (in_use_cost + 512) / 1024; // cost is stored in kb
3252 
3253  /*
3254  calculate the new maximum cost for the cache
3255 
3256  NOTE: in_use_cost is *not* correct due to rounding errors in the
3257  above algorithm. instead of worrying about getting the
3258  calculation correct, we are more interested in speed, and use
3259  in_use_cost as a floor for new_max_cost
3260  */
3261  uint new_max_cost = qMax(qMax(max_cost / 2, in_use_cost), min_cost);
3262 
3263  FC_DEBUG(" after sweep, in use %u kb, total %u kb, max %u kb, new max %u kb",
3264  in_use_cost, total_cost, max_cost, new_max_cost);
3265 
3266  if (new_max_cost == max_cost) {
3267  if (fast) {
3268  FC_DEBUG(" cannot shrink cache, slowing timer");
3269 
3272  fast = false;
3273  }
3274 
3275  return;
3276  } else if (! fast) {
3277  FC_DEBUG(" dropping into passing gear");
3278 
3281  fast = true;
3282  }
3283 
3284  max_cost = new_max_cost;
3285 
3286  {
3287  FC_DEBUG(" CLEAN engine data:");
3288 
3289  // clean out all unused engine data
3291  end = engineDataCache.end();
3292  while (it != end) {
3293  if (it.value()->ref != 0) {
3294  ++it;
3295  continue;
3296  }
3297 
3298  EngineDataCache::Iterator rem = it++;
3299 
3300  decreaseCost(sizeof(QFontEngineData));
3301 
3302  FC_DEBUG(" %p", rem.value());
3303 
3304  delete rem.value();
3305  engineDataCache.erase(rem);
3306  }
3307  }
3308 
3309  // clean out the engine cache just enough to get below our new max cost
3310  uint current_cost;
3311  do {
3312  current_cost = total_cost;
3313 
3315  end = engineCache.end();
3316  // determine the oldest and least popular of the unused engines
3317  uint oldest = ~0u;
3318  uint least_popular = ~0u;
3319 
3320  for (; it != end; ++it) {
3321  if (it.value().data->ref != 0)
3322  continue;
3323 
3324  if (it.value().timestamp < oldest &&
3325  it.value().hits <= least_popular) {
3326  oldest = it.value().timestamp;
3327  least_popular = it.value().hits;
3328  }
3329  }
3330 
3331  FC_DEBUG(" oldest %u least popular %u", oldest, least_popular);
3332 
3333  for (it = engineCache.begin(); it != end; ++it) {
3334  if (it.value().data->ref == 0 &&
3335  it.value().timestamp == oldest &&
3336  it.value().hits == least_popular)
3337  break;
3338  }
3339 
3340  if (it != end) {
3341  FC_DEBUG(" %p: timestamp %4u hits %2u ref %2d/%2d, type '%s'",
3342  it.value().data, it.value().timestamp, it.value().hits,
3343  int(it.value().data->ref), it.value().data->cache_count,
3344  it.value().data->name());
3345 
3346  if (--it.value().data->cache_count == 0) {
3347  FC_DEBUG(" DELETE: last occurrence in cache");
3348 
3349  decreaseCost(it.value().data->cache_cost);
3350  delete it.value().data;
3351  } else {
3352  /*
3353  this particular font engine is in the cache multiple
3354  times... set current_cost to zero, so that we can
3355  keep looping to get rid of all occurrences
3356  */
3357  current_cost = 0;
3358  }
3359 
3360  engineCache.erase(it);
3361  }
3362  } while (current_cost != total_cost && total_cost > max_cost);
3363 }
3364 
3365 
3366 #ifndef QT_NO_DEBUG_STREAM
3368 {
3369  return stream << "QFont(" << font.toString() << ')';
3370 }
3371 #endif
3372 
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
uint resolve() const
Definition: qfont.h:287
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QAtomicInt ref
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
Q_GUI_EXPORT QScreen * qt_screen
Definition: qscreen_qws.cpp:69
void setWordSpacing(qreal spacing)
Sets the word spacing for the font to spacing.
Definition: qfont.cpp:1757
uint fixedPitch
Definition: qfont_p.h:96
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
void setPointSize(int)
Sets the point size to pointSize.
Definition: qfont.cpp:1099
QFontInfo(const QFont &)
Constructs a font info object for font.
Definition: qfont.cpp:2634
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
const Key & key() const
Returns the current item&#39;s key as a const reference.
Definition: qmap.h:250
void setCapitalization(Capitalization)
Sets the capitalization of the text in this font to caps.
Definition: qfont.cpp:1798
HintingPreference
This enum describes the different levels of hinting that can be applied to glyphs to improve legibili...
Definition: qfont.h:96
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
int type
Definition: qmetatype.cpp:239
QFontInfo & operator=(const QFontInfo &)
Assigns the font info in fi.
Definition: qfont.cpp:2657
int height() const
Returns the logical height of the framebuffer in pixels.
Definition: qscreen_qws.h:228
#define QT_FONT_ENGINE_FROM_DATA(data, script)
Definition: qfont.cpp:291
double qreal
Definition: qglobal.h:1193
uint fixedPitchComputed
Definition: qfont_p.h:102
static mach_timebase_info_data_t info
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int qint32
Definition: qglobal.h:937
int value() const
Definition: qfixed_p.h:73
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QFixed * advances_x
bool letterSpacingIsAbsolute
Definition: qfont_p.h:193
static int appScreen()
Returns the number of the screen where the application is being displayed.
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
void setKerning(bool)
Enables kerning for this font if enable is true; otherwise disables it.
Definition: qfont.cpp:1432
int physicalHeight() const
Returns the physical height of the screen in millimeters.
Definition: qscreen_qws.h:291
The QPlatformScreen class provides an abstraction for visual displays.
bool operator==(const QFont &) const
Returns true if this font is equal to f; otherwise returns false.
Definition: qfont.cpp:1876
HintingPreference hintingPreference() const
Returns the currently preferred hinting level for glyphs rendered with this font. ...
Definition: qfont.cpp:1088
qreal pointSize
Definition: qfont_p.h:89
#define it(className, varName)
int logicalDpiY() const
Definition: qpaintdevice.h:96
static const uint min_cost
Definition: qfont_p.h:281
bool fromString(const QString &)
Sets this font to match the description descrip.
Definition: qfont.cpp:2367
bool underline() const
Returns true if underline has been set; otherwise returns false.
Definition: qfont.cpp:1320
int weight() const
Returns the weight of the matched window system font.
Definition: qfont.cpp:2758
void setUnderline(bool)
If enable is true, sets underline on; otherwise sets underline off.
Definition: qfont.cpp:1331
Q_GUI_EXPORT int qt_defaultDpiY()
Definition: qfont.cpp:201
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
int pixelSize() const
Returns the pixel size of the font if it was set with setPixelSize().
Definition: qfont.cpp:1178
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
EngineCache engineCache
Definition: qfont_p.h:267
Q_GUI_EXPORT int qt_defaultDpiX()
Definition: qfont.cpp:162
Style style() const
Returns the style of the font.
Definition: qfont.cpp:1223
int size() const
Returns the number of (key, value) pairs in the map.
Definition: qmap.h:201
void insertEngine(const Key &key, QFontEngine *engine)
Definition: qfont.cpp:3073
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
Capitalization capitalization() const
Returns the current capitalization type of the font.
Definition: qfont.cpp:1819
QFontCache * fontCache
Definition: qfont_p.h:153
void decreaseCost(uint cost)
Definition: qfont.cpp:3111
quint16 u
unsigned char quint8
Definition: qglobal.h:934
void setRawMode(bool)
If enable is true, turns raw mode on; otherwise turns raw mode off.
Definition: qfont.cpp:1842
iterator find(const Key &key)
Returns an iterator pointing to the item with key key in the map.
Definition: qmap.h:618
bool ref()
Atomically increments the value of this QAtomicInt.
static void parseFontName(const QString &name, QString &foundry, QString &family)
friend Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QFont &)
Reads the font font from the data stream s.
Definition: qfont.cpp:2497
static int timer_id
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setItalic(bool b)
Sets the style() of the font to QFont::StyleItalic if enable is true; otherwise the style is set to Q...
Definition: qfont.h:360
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Capitalization
Rendering option for text this font applies to.
Definition: qfont.h:129
bool isCopyOf(const QFont &) const
Returns true if this font and f are copies of each other, i.e.
Definition: qfont.cpp:1963
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const =0
QFontPrivate * smallCapsFontPrivate() const
Definition: qfont.cpp:323
#define X11
Definition: qt_x11_p.h:724
static QString substitute(const QString &)
Returns the first family name to be used whenever familyName is specified.
Definition: qfont.cpp:2116
float qt_mac_defaultDpi_y()
QFont & operator=(const QFont &)
Assigns font to this font and returns a reference to it.
Definition: qfont.cpp:893
bool kerning() const
Returns true if kerning should be used when drawing text with this font.
Definition: qfont.cpp:1416
virtual Type type() const =0
virtual int devType() const
Definition: qpaintdevice.h:167
QFixed wordSpacing
Definition: qfont_p.h:196
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
void setHintingPreference(HintingPreference hintingPreference)
Set the preference for the hinting level of the glyphs to hintingPreference.
Definition: qfont.cpp:1071
QString styleName() const
Returns the requested font style name, it will be used to match the font with irregular styles (that ...
Definition: qfont.cpp:950
friend class QFontInfo
Definition: qfont.h:314
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
void setStyleStrategy(StyleStrategy s)
Sets the style strategy for the font to s.
Definition: qfont.cpp:1578
QString styleName() const
Returns the style name of the matched window system font on system that supports it.
Definition: qfont.cpp:2686
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
static QFontCache * instance()
Definition: qfont.cpp:2919
const QX11Info * qt_x11Info(const QPaintDevice *pd)
static QFont font()
Returns the default application font.
bool italic() const
Returns the italic value of the matched window system font.
Definition: qfont.cpp:2734
void setFamily(const QString &)
Sets the family name of the font.
Definition: qfont.cpp:924
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qmap.h:251
uint rawMode
Definition: qfont_p.h:187
const Key & key() const
Returns the current item&#39;s key.
Definition: qhash.h:419
uint overline
Definition: qfont_p.h:189
int width() const
Returns the logical width of the framebuffer in pixels.
Definition: qscreen_qws.h:227
int width() const
Returns the width.
Definition: qsize.h:126
uint underline
Definition: qfont_p.h:188
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
const Q_GUI_EXPORT QX11Info * qt_x11Info(const QPaintDevice *pd)
Returns the QX11Info structure for the pd paint device.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
qreal pointSizeF() const
Returns the point size of the font.
Definition: qfont.cpp:1142
void removeEngineForFont(const QByteArray &fontName)
Definition: qfont.cpp:3025
void setValue(int value)
Definition: qfixed_p.h:74
~QFontPrivate()
Definition: qfont.cpp:276
void sort()
Sorts the list of strings in ascending order (case sensitively).
Definition: qstringlist.h:152
static FILE * stream
#define FC_DEBUG
Definition: qfont.cpp:89
void setStretch(int)
Sets the stretch factor for the font.
Definition: qfont.cpp:1641
const_iterator ConstIterator
Qt-style synonym for QMap::const_iterator.
Definition: qmap.h:389
static void removeSubstitution(const QString &)
Removes all the substitutions for familyName.
Definition: qfont.cpp:2218
bool overline() const
Returns true if overline has been set; otherwise returns false.
Definition: qfont.cpp:1344
static QList< QAxEngineDescriptor > engines
Definition: qaxscript.cpp:69
QDebug operator<<(QDebug stream, const QFont &font)
Definition: qfont.cpp:3367
uint resolve_mask
Definition: qfont.h:344
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
bool strikeOut() const
Returns the strikeout value of the matched window system font.
Definition: qfont.cpp:2816
void setStrikeOut(bool)
If enable is true, sets strikeout on; otherwise sets strikeout off.
Definition: qfont.cpp:1378
QFontDef request
Definition: qfont_p.h:178
static int appDpiX(int screen=-1)
Returns the horizontal resolution of the given screen in terms of the number of dots per inch...
uint capital
Definition: qfont_p.h:192
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
void insertEngineData(const Key &key, QFontEngineData *engineData)
Definition: qfont.cpp:3046
static quint8 get_font_bits(int version, const QFontPrivate *f)
Definition: qfont.cpp:2257
static void insertSubstitutions(const QString &, const QStringList &)
Inserts the list of families substituteNames into the substitution list for familyName.
Definition: qfont.cpp:2175
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
bool deref()
Atomically decrements the value of this QAtomicInt.
bool underline() const
Returns the underline value of the matched window system font.
Definition: qfont.cpp:2788
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
short qint16
Definition: qglobal.h:935
iterator Iterator
Qt-style synonym for QMap::iterator.
Definition: qmap.h:388
static int toInt(const QByteArray &str)
Definition: generator.cpp:167
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297
unsigned short quint16
Definition: qglobal.h:936
Q_CORE_EXPORT void qWarning(const char *,...)
SpacingType letterSpacingType() const
Returns the spacing type used for letter spacing.
Definition: qfont.cpp:1721
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
const_iterator constFind(const Key &key) const
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:859
bool operator<(const QFont &) const
Provides an arbitrary comparison of this font and font f.
Definition: qfont.cpp:1904
uint weight
Definition: qfont_p.h:95
uint total_cost
Definition: qfont_p.h:282
QString toString() const
Returns a description of the font.
Definition: qfont.cpp:2344
QChar toUpper() const
Returns the uppercase equivalent if the character is lowercase or titlecase; otherwise returns the ch...
Definition: qchar.cpp:1287
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
static QString resolveFontFamilyAlias(const QString &family)
SpacingType
Definition: qfont.h:137
EngineDataCache engineDataCache
Definition: qfont_p.h:251
int pixelSize() const
Returns the pixel size of the matched window system font.
Definition: qfont.cpp:2722
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
QAtomicInt ref
Definition: qfont_p.h:152
static void set_font_bits(int version, quint8 bits, QFontPrivate *f)
Definition: qfont.cpp:2301
uint ignorePitch
Definition: qfont_p.h:100
void setStyleHint(StyleHint, StyleStrategy=PreferDefault)
Sets the style hint and strategy to hint and strategy, respectively.
Definition: qfont.cpp:1554
virtual QRect geometry() const =0
Reimplement in subclass to return the pixel geometry of the screen.
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the map.
Definition: qmap.h:374
#define QT_CATCH(A)
Definition: qglobal.h:1537
QFixed letterSpacing
Definition: qfont_p.h:195
friend class QFontPrivate
Definition: qfont.h:310
The QFontInfo class provides general information about fonts.
Definition: qfontinfo.h:54
Style
This enum describes the different styles of glyphs that are used to display text. ...
Definition: qfont.h:111
QFont::Style style() const
Returns the style value of the matched window system font.
Definition: qfont.cpp:2746
virtual QSize physicalSize() const
Reimplement this function in subclass to return the physical size of the screen.
static const int slow_timeout
Definition: qfont.cpp:2900
qreal wordSpacing() const
Returns the word spacing for the font.
Definition: qfont.cpp:1735
static void insertSubstitution(const QString &, const QString &)
Inserts substituteName into the substitution table for the family familyName.
Definition: qfont.cpp:2155
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
qreal pixelSize
Definition: qfont_p.h:90
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
QFont()
Constructs a font object that uses the application&#39;s default font.
Definition: qfont.cpp:823
The QPlatformIntegration class is the entry for WindowSystem specific functionality.
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:466
static quint8 get_extended_font_bits(const QFontPrivate *f)
Definition: qfont.cpp:2284
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap.
Definition: qmap.h:301
bool fixedPitch() const
Returns the fixed pitch value of the matched window system font.
Definition: qfont.cpp:2826
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QFontCache()
Definition: qfont.cpp:2940
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:380
uint current_timestamp
Definition: qfont_p.h:283
virtual HDC getDC() const
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
uint max_cost
Definition: qfont_p.h:282
bool hasLocalData() const
If T is a pointer type, returns true if the calling thread has non-zero data available.
~QFont()
Destroys the font object and frees all allocated resources.
Definition: qfont.cpp:886
StyleHint
Style hints are used by the font matching algorithm to find an appropriate default family if a select...
Definition: qfont.h:69
The QX11Info class provides information about the X display configuration.
Definition: qx11info_x11.h:63
static QStringList substitutes(const QString &)
Returns a list of family names to be used whenever familyName is specified.
Definition: qfont.cpp:2139
bool fixedPitch() const
Returns true if fixed pitch has been set; otherwise returns false.
Definition: qfont.cpp:1391
static void initFontSubst()
Definition: qfont.cpp:2068
The QMap::iterator class provides an STL-style non-const iterator for QMap and QMultiMap.
Definition: qmap.h:233
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontinfo.h:82
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QString family() const
Returns the requested font family name, i.e.
Definition: qfont.cpp:906
Q_GUI_EXPORT int qt_defaultDpi()
Definition: qfont.cpp:240
void setOverline(bool)
If enable is true, sets overline on; otherwise sets overline off.
Definition: qfont.cpp:1354
float qt_mac_defaultDpi_x()
QFont::StyleHint styleHint() const
Returns the style of the matched window system font.
Definition: qfont.cpp:2850
~QFontCache()
Definition: qfont.cpp:2946
void setLocalData(T t)
Sets the local data for the calling thread to data.
bool exactMatch() const
Returns true if the matched window system font is exactly the same as the one specified by the font; ...
Definition: qfont.cpp:2878
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
uint style
Definition: qfont_p.h:97
void setFixedPitch(bool)
If enable is true, sets fixed pitch on; otherwise sets fixed pitch off.
Definition: qfont.cpp:1402
virtual QList< QScreen * > subScreens() const
Definition: qscreen_qws.h:283
static void cleanup()
Definition: qfont.cpp:2927
QFontPrivate()
Definition: qfont.cpp:245
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
int key
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfont.h:343
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
QString styleName
Definition: qfont_p.h:83
void detach()
Detaches the font object from common font data.
Definition: qfont.cpp:803
void setStyleName(const QString &)
Sets the style name of the font to the given styleName.
Definition: qfont.cpp:967
qreal pointSizeF() const
Returns the point size of the matched window system font.
Definition: qfont.cpp:2710
void setWeight(int)
Sets the weight the font to weight, which should be a value from the QFont::Weight enumeration...
Definition: qfont.cpp:1278
int height() const
Returns the height.
Definition: qsize.h:129
void detach()
If the shared data object&#39;s reference count is greater than 1, this function creates a deep copy of t...
Definition: qshareddata.h:148
if(void) toggleToolbarShown
QFactoryLoader * l
int weight() const
Returns the weight of the font which is one of the enumerated values from QFont::Weight.
Definition: qfont.cpp:1248
const T & value() const
Returns the current item&#39;s value.
Definition: qmap.h:325
qreal toReal() const
Definition: qfixed_p.h:77
uint stretch
Definition: qfont_p.h:98
StyleStrategy
The style strategy tells the font matching algorithm what type of fonts should be used to find an app...
Definition: qfont.h:81
The QScreen class is a base class for screen drivers in Qt for Embedded Linux.
Definition: qscreen_qws.h:191
QMutex * qt_fontdatabase_mutex()
void increaseCost(uint cost)
Definition: qfont.cpp:3089
bool operator!=(const QFont &) const
Returns true if this font is different from f; otherwise returns false.
Definition: qfont.cpp:1943
void setPointSizeF(qreal)
Sets the point size to pointSize.
Definition: qfont.cpp:1121
friend Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QFont &)
Writes the font font to the data stream s.
Definition: qfont.cpp:2439
static QStringList substitutions()
Returns a sorted list of substituted family names.
Definition: qfont.cpp:2234
iterator erase(iterator it)
Removes the (key, value) pair pointed to by the iterator pos from the map, and returns an iterator to...
Definition: qmap.h:717
bool rawMode() const
Returns true if the font is a raw mode font; otherwise returns false.
Definition: qfont.cpp:2867
QString key() const
Returns the font&#39;s key, a textual representation of a font.
Definition: qfont.cpp:2332
static const int fast_timeout
Definition: qfont.cpp:2899
static qreal toDouble(const QChar *&str)
bool italic() const
Returns true if the style() of the font is not QFont::StyleNormal.
Definition: qfont.h:355
int pointSize() const
Returns the point size of the font.
Definition: qfont.cpp:981
int screen
Definition: qfont_p.h:181
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static QFixed kerning(int left, int right, const QFontEngine::KernPair *pairs, int numPairs)
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
QFontEngineData * findEngineData(const Key &key) const
Definition: qfont.cpp:3036
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
QFontEngine * findEngine(const Key &key)
Definition: qfont.cpp:3054
bool exactMatch(const QFontDef &other) const
Definition: qfont.cpp:102
HDC shared_dc()
QAtomicInt ref
Definition: qfont_p.h:177
QFontPrivate * scFont
Definition: qfont_p.h:198
QFontDef fontDef
void setLetterSpacing(SpacingType type, qreal spacing)
Sets the letter spacing for the font to spacing and the type of spacing to type.
Definition: qfont.cpp:1696
QFontEngine * engine
Definition: qfont_p.h:158
StyleStrategy styleStrategy() const
Returns the StyleStrategy.
Definition: qfont.cpp:1447
bool rawMode() const
Returns true if raw mode is used for font name matching; otherwise returns false. ...
Definition: qfont.cpp:1974
void setPixelSize(int)
Sets the font size to pixelSize pixels.
Definition: qfont.cpp:1156
~QFontInfo()
Destroys the font info object.
Definition: qfont.cpp:2650
uint kerning
Definition: qfont_p.h:191
QString addStyle
Definition: qfont_p.h:86
QString family
Definition: qfont_p.h:82
bool qt_is_gui_used
int timer_id
Definition: qfont_p.h:285
bool strikeOut() const
Returns true if strikeout has been set; otherwise returns false.
Definition: qfont.cpp:1367
static void setFont(const QFont &, const char *className=0)
Changes the default application font to font.
static const KeyPair *const end
void alterCharForCapitalization(QChar &c) const
Definition: qfont.cpp:309
QFontEngineData * engineData
Definition: qfont_p.h:179
void clear()
Definition: qfont.cpp:2981
StyleHint styleHint() const
Returns the StyleHint.
Definition: qfont.cpp:1460
uint hintingPreference
Definition: qfont_p.h:101
bool fast
Definition: qfont_p.h:284
int physicalWidth() const
Returns the physical width of the screen in millimeters.
Definition: qscreen_qws.h:290
uint styleHint
Definition: qfont_p.h:93
QHash< QString, QStringList > QFontSubst
Definition: qfont.cpp:2064
uint styleStrategy
Definition: qfont_p.h:92
The QThreadStorage class provides per-thread data storage.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
void resolve(uint mask, const QFontPrivate *other)
Definition: qfont.cpp:340
QChar toLower() const
Returns the lowercase equivalent if the character is uppercase or titlecase; otherwise returns the ch...
Definition: qchar.cpp:1239
void cleanupPrinterFonts()
Definition: qfont.cpp:3123
#define QT_TRY
Definition: qglobal.h:1536
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
static float pointSize(const QFontDef &fd, int dpi)
Definition: qfont_win.cpp:90
bool exactMatch() const
Returns true if a window system font exactly matching the settings of this font is available...
Definition: qfont.cpp:1857
void setStyle(Style style)
Sets the style of the font to style.
Definition: qfont.cpp:1234
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
void clear()
Removes all items from the map.
Definition: qmap.h:444
static Display * display()
Returns the default display for the application.
void timerEvent(QTimerEvent *event)
This event handler can be reimplemented in a subclass to receive timer events for the object...
Definition: qfont.cpp:3186
uint strikeOut
Definition: qfont_p.h:190
int stretch() const
Returns the stretch factor for the font.
Definition: qfont.cpp:1618
int screen() const
Returns the number of the screen currently in use.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static void set_extended_font_bits(quint8 bits, QFontPrivate *f)
Definition: qfont.cpp:2317
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272
qreal letterSpacing() const
Returns the letter spacing for the font.
Definition: qfont.cpp:1677
int pointSize() const
Returns the point size of the matched window system font.
Definition: qfont.cpp:2698
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650
QString family() const
Returns the family name of the matched window system font.
Definition: qfont.cpp:2668
bool overline() const
Returns the overline value of the matched window system font.
Definition: qfont.cpp:2803
static int appDpiY(int screen=-1)
Returns the vertical resolution of the given screen in terms of the number of dots per inch...