Qt 4.8
qfontmetrics.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 "qpaintdevice.h"
44 #include "qfontmetrics.h"
45 
46 #include "qfont_p.h"
47 #include "qfontengine_p.h"
48 #include <private/qunicodetables_p.h>
49 
50 #include <math.h>
51 
52 #ifdef Q_WS_X11
53 #include "qx11info_x11.h"
54 #endif
55 
57 
58 #ifdef Q_WS_X11
59 extern const QX11Info *qt_x11Info(const QPaintDevice *pd);
60 #endif
61 
62 extern void qt_format_text(const QFont& font, const QRectF &_r,
63  int tf, const QString &text, QRectF *brect,
64  int tabStops, int *tabArray, int tabArrayLen,
65  QPainter *painter);
66 
67 /*****************************************************************************
68  QFontMetrics member functions
69  *****************************************************************************/
70 
168  : d(font.d.data())
169 {
170 }
171 
186 {
187  int dpi = paintdevice ? paintdevice->logicalDpiY() : qt_defaultDpi();
188 #ifdef Q_WS_X11
189  const QX11Info *info = qt_x11Info(paintdevice);
190  int screen = info ? info->screen() : 0;
191 #else
192  const int screen = 0;
193 #endif
194  if (font.d->dpi != dpi || font.d->screen != screen ) {
195  d = new QFontPrivate(*font.d);
196  d->dpi = dpi;
197  d->screen = screen;
198  } else {
199  d = font.d.data();
200  }
201 
202 }
203 
208  : d(fm.d.data())
209 {
210 }
211 
217 {
218 }
219 
224 {
225  d = fm.d.data();
226  return *this;
227 }
228 
243 bool QFontMetrics::operator ==(const QFontMetrics &other) const
244 {
245  return d == other.d;
246 }
247 
259 {
260  return d == other.d;
261 }
262 
306 {
308  Q_ASSERT(engine != 0);
309  return qRound(engine->ascent());
310 }
311 
312 
324 {
326  Q_ASSERT(engine != 0);
327  return qRound(engine->descent());
328 }
329 
339 {
341  Q_ASSERT(engine != 0);
342  return qRound(engine->ascent()) + qRound(engine->descent()) + 1;
343 }
344 
353 {
355  Q_ASSERT(engine != 0);
356  return qRound(engine->leading());
357 }
358 
367 {
369  Q_ASSERT(engine != 0);
370  return qRound(engine->leading()) + qRound(engine->ascent()) + qRound(engine->descent()) + 1;
371 }
372 
384 {
386  Q_ASSERT(engine != 0);
387  return qRound(engine->minLeftBearing());
388 }
389 
401 {
403  Q_ASSERT(engine != 0);
404  return qRound(engine->minRightBearing());
405 }
406 
411 {
413  Q_ASSERT(engine != 0);
414  return qRound(engine->maxCharWidth());
415 }
416 
422 {
424  Q_ASSERT(engine != 0);
425  if (d->capital == QFont::SmallCaps)
427  return qRound(engine->xHeight());
428 }
429 
439 {
441  Q_ASSERT(engine != 0);
442  return qRound(engine->averageCharWidth());
443 }
444 
450 {
451  const int script = QUnicodeTables::script(ch);
452  QFontEngine *engine = d->engineForScript(script);
453  Q_ASSERT(engine != 0);
454  if (engine->type() == QFontEngine::Box)
455  return false;
456  return engine->canRender(&ch, 1);
457 }
458 
470 {
471  const int script = QUnicodeTables::script(ucs4);
472  QFontEngine *engine = d->engineForScript(script);
473  Q_ASSERT(engine != 0);
474  if (engine->type() == QFontEngine::Box)
475  return false;
476  QString utf16 = QString::fromUcs4(&ucs4, 1);
477  return engine->canRender(utf16.data(), utf16.length());
478 }
479 
493 {
494  const int script = QUnicodeTables::script(ch);
495  QFontEngine *engine;
496  if (d->capital == QFont::SmallCaps && ch.isLower())
497  engine = d->smallCapsFontPrivate()->engineForScript(script);
498  else
499  engine = d->engineForScript(script);
500  Q_ASSERT(engine != 0);
501  if (engine->type() == QFontEngine::Box)
502  return 0;
503 
505 
506  QGlyphLayoutArray<10> glyphs;
507  int nglyphs = 9;
508  engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0);
509  // ### can nglyphs != 1 happen at all? Not currently I think
510  qreal lb;
511  engine->getGlyphBearings(glyphs.glyphs[0], &lb);
512  return qRound(lb);
513 }
514 
528 {
529  const int script = QUnicodeTables::script(ch);
530  QFontEngine *engine;
531  if (d->capital == QFont::SmallCaps && ch.isLower())
532  engine = d->smallCapsFontPrivate()->engineForScript(script);
533  else
534  engine = d->engineForScript(script);
535  Q_ASSERT(engine != 0);
536  if (engine->type() == QFontEngine::Box)
537  return 0;
538 
540 
541  QGlyphLayoutArray<10> glyphs;
542  int nglyphs = 9;
543  engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0);
544  // ### can nglyphs != 1 happen at all? Not currently I think
545  qreal rb;
546  engine->getGlyphBearings(glyphs.glyphs[0], 0, &rb);
547  return qRound(rb);
548 }
549 
562 int QFontMetrics::width(const QString &text, int len) const
563 {
564  return width(text, len, 0);
565 }
566 
570 int QFontMetrics::width(const QString &text, int len, int flags) const
571 {
572  int pos = text.indexOf(QLatin1Char('\x9c'));
573  if (pos != -1) {
574  len = (len < 0) ? pos : qMin(pos, len);
575  } else if (len < 0) {
576  len = text.length();
577  }
578  if (len == 0)
579  return 0;
580 
581  if (flags & Qt::TextBypassShaping) {
582  // Skip harfbuzz complex shaping, only use advances
583  int numGlyphs = len;
584  QVarLengthGlyphLayoutArray glyphs(numGlyphs);
586  if (!engine->stringToCMap(text.data(), len, &glyphs, &numGlyphs, 0)) {
587  glyphs.resize(numGlyphs);
588  if (!engine->stringToCMap(text.data(), len, &glyphs, &numGlyphs, 0))
589  Q_ASSERT_X(false, Q_FUNC_INFO, "stringToCMap shouldn't fail twice");
590  }
591 
592  QFixed width;
593  for (int i = 0; i < numGlyphs; ++i)
594  width += glyphs.advances_x[i];
595  return qRound(width);
596  }
597 
598  QStackTextEngine layout(text, d.data());
599  layout.ignoreBidi = true;
600  return qRound(layout.width(0, len));
601 }
602 
631 {
633  return 0;
634 
635  const int script = QUnicodeTables::script(ch);
636  QFontEngine *engine;
637  if (d->capital == QFont::SmallCaps && ch.isLower())
638  engine = d->smallCapsFontPrivate()->engineForScript(script);
639  else
640  engine = d->engineForScript(script);
641  Q_ASSERT(engine != 0);
642 
644 
645  QGlyphLayoutArray<8> glyphs;
646  int nglyphs = 7;
647  engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0);
648  return qRound(glyphs.advances_x[0]);
649 }
650 
666 int QFontMetrics::charWidth(const QString &text, int pos) const
667 {
668  if (pos < 0 || pos > (int)text.length())
669  return 0;
670 
671  QChar ch = text.unicode()[pos];
672  const int script = QUnicodeTables::script(ch);
673  int width;
674 
675  if (script != QUnicodeTables::Common) {
676  // complex script shaping. Have to do some hard work
677  int from = qMax(0, pos - 8);
678  int to = qMin(text.length(), pos + 8);
679  QString cstr = QString::fromRawData(text.unicode() + from, to - from);
680  QStackTextEngine layout(cstr, d.data());
681  layout.ignoreBidi = true;
682  layout.itemize();
683  width = qRound(layout.width(pos-from, 1));
684  } else if (QChar::category(ch.unicode()) == QChar::Mark_NonSpacing) {
685  width = 0;
686  } else {
687  QFontEngine *engine;
688  if (d->capital == QFont::SmallCaps && ch.isLower())
689  engine = d->smallCapsFontPrivate()->engineForScript(script);
690  else
691  engine = d->engineForScript(script);
692  Q_ASSERT(engine != 0);
693 
695 
696  QGlyphLayoutArray<8> glyphs;
697  int nglyphs = 7;
698  engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0);
699  width = qRound(glyphs.advances_x[0]);
700  }
701  return width;
702 }
703 
725 {
726  if (text.length() == 0)
727  return QRect();
728 
729  QStackTextEngine layout(text, d.data());
730  layout.ignoreBidi = true;
731  layout.itemize();
732  glyph_metrics_t gm = layout.boundingBox(0, text.length());
733  return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height));
734 }
735 
754 {
755  const int script = QUnicodeTables::script(ch);
756  QFontEngine *engine;
757  if (d->capital == QFont::SmallCaps && ch.isLower())
758  engine = d->smallCapsFontPrivate()->engineForScript(script);
759  else
760  engine = d->engineForScript(script);
761  Q_ASSERT(engine != 0);
762 
764 
765  QGlyphLayoutArray<10> glyphs;
766  int nglyphs = 9;
767  engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0);
768  glyph_metrics_t gm = engine->boundingBox(glyphs.glyphs[0]);
769  return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height));
770 }
771 
831 QRect QFontMetrics::boundingRect(const QRect &rect, int flags, const QString &text, int tabStops,
832  int *tabArray) const
833 {
834  int tabArrayLen = 0;
835  if (tabArray)
836  while (tabArray[tabArrayLen])
837  tabArrayLen++;
838 
839  QRectF rb;
840  QRectF rr(rect);
841  qt_format_text(QFont(d.data()), rr, flags | Qt::TextDontPrint, text, &rb, tabStops, tabArray,
842  tabArrayLen, 0);
843 
844  return rb.toAlignedRect();
845 }
846 
870 QSize QFontMetrics::size(int flags, const QString &text, int tabStops, int *tabArray) const
871 {
872  return boundingRect(QRect(0,0,0,0), flags | Qt::TextLongestVariant, text, tabStops, tabArray).size();
873 }
874 
901 {
902  if (text.length() == 0)
903  return QRect();
904 
905  QStackTextEngine layout(text, d.data());
906  layout.ignoreBidi = true;
907  layout.itemize();
908  glyph_metrics_t gm = layout.tightBoundingBox(0, text.length());
909  return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height));
910 }
911 
912 
938 {
939  QString _text = text;
940  if (!(flags & Qt::TextLongestVariant)) {
941  int posA = 0;
942  int posB = _text.indexOf(QLatin1Char('\x9c'));
943  while (posB >= 0) {
944  QString portion = _text.mid(posA, posB - posA);
945  if (size(flags, portion).width() <= width)
946  return portion;
947  posA = posB + 1;
948  posB = _text.indexOf(QLatin1Char('\x9c'), posA);
949  }
950  _text = _text.mid(posA);
951  }
952  QStackTextEngine engine(_text, QFont(d.data()));
953  return engine.elidedText(mode, width, flags);
954 }
955 
963 {
965  Q_ASSERT(engine != 0);
966  return qRound(engine->underlinePosition());
967 }
968 
976 {
977  return ascent() + 1;
978 }
979 
987 {
988  int pos = ascent() / 3;
989  return pos > 0 ? pos : 1;
990 }
991 
999 {
1001  Q_ASSERT(engine != 0);
1002  return qRound(engine->lineThickness());
1003 }
1004 
1005 
1006 
1007 
1008 /*****************************************************************************
1009  QFontMetricsF member functions
1010  *****************************************************************************/
1011 
1071  : d(fontMetrics.d.data())
1072 {
1073 }
1074 
1084 {
1085  d = other.d.data();
1086  return *this;
1087 }
1088 
1103  : d(font.d.data())
1104 {
1105 }
1106 
1121 {
1122  int dpi = paintdevice ? paintdevice->logicalDpiY() : qt_defaultDpi();
1123 #ifdef Q_WS_X11
1124  const QX11Info *info = qt_x11Info(paintdevice);
1125  int screen = info ? info->screen() : 0;
1126 #else
1127  const int screen = 0;
1128 #endif
1129  if (font.d->dpi != dpi || font.d->screen != screen ) {
1130  d = new QFontPrivate(*font.d);
1131  d->dpi = dpi;
1132  d->screen = screen;
1133  } else {
1134  d = font.d.data();
1135  }
1136 
1137 }
1138 
1143  : d(fm.d.data())
1144 {
1145 }
1146 
1152 {
1153 }
1154 
1159 {
1160  d = fm.d.data();
1161  return *this;
1162 }
1163 
1177 {
1178  return d == other.d;
1179 }
1180 
1190 {
1191  return d == other.d;
1192 }
1193 
1232 {
1234  Q_ASSERT(engine != 0);
1235  return engine->ascent().toReal();
1236 }
1237 
1238 
1251 {
1253  Q_ASSERT(engine != 0);
1254  return engine->descent().toReal();
1255 }
1256 
1266 {
1268  Q_ASSERT(engine != 0);
1269 
1270  return (engine->ascent() + engine->descent() + 1).toReal();
1271 }
1272 
1281 {
1283  Q_ASSERT(engine != 0);
1284  return engine->leading().toReal();
1285 }
1286 
1295 {
1297  Q_ASSERT(engine != 0);
1298  return (engine->leading() + engine->ascent() + engine->descent() + 1).toReal();
1299 }
1300 
1312 {
1314  Q_ASSERT(engine != 0);
1315  return engine->minLeftBearing();
1316 }
1317 
1329 {
1331  Q_ASSERT(engine != 0);
1332  return engine->minRightBearing();
1333 }
1334 
1339 {
1341  Q_ASSERT(engine != 0);
1342  return engine->maxCharWidth();
1343 }
1344 
1350 {
1352  Q_ASSERT(engine != 0);
1353  if (d->capital == QFont::SmallCaps)
1355  return engine->xHeight().toReal();
1356 }
1357 
1367 {
1369  Q_ASSERT(engine != 0);
1370  return engine->averageCharWidth().toReal();
1371 }
1372 
1378 {
1379  const int script = QUnicodeTables::script(ch);
1380  QFontEngine *engine = d->engineForScript(script);
1381  Q_ASSERT(engine != 0);
1382  if (engine->type() == QFontEngine::Box)
1383  return false;
1384  return engine->canRender(&ch, 1);
1385 }
1386 
1398 {
1399  const int script = QUnicodeTables::script(ucs4);
1400  QFontEngine *engine = d->engineForScript(script);
1401  Q_ASSERT(engine != 0);
1402  if (engine->type() == QFontEngine::Box)
1403  return false;
1404  QString utf16 = QString::fromUcs4(&ucs4, 1);
1405  return engine->canRender(utf16.data(), utf16.length());
1406 }
1407 
1421 {
1422  const int script = QUnicodeTables::script(ch);
1423  QFontEngine *engine;
1424  if (d->capital == QFont::SmallCaps && ch.isLower())
1425  engine = d->smallCapsFontPrivate()->engineForScript(script);
1426  else
1427  engine = d->engineForScript(script);
1428  Q_ASSERT(engine != 0);
1429  if (engine->type() == QFontEngine::Box)
1430  return 0;
1431 
1433 
1434  QGlyphLayoutArray<10> glyphs;
1435  int nglyphs = 9;
1436  engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0);
1437  // ### can nglyphs != 1 happen at all? Not currently I think
1438  qreal lb;
1439  engine->getGlyphBearings(glyphs.glyphs[0], &lb);
1440  return lb;
1441 }
1442 
1456 {
1457  const int script = QUnicodeTables::script(ch);
1458  QFontEngine *engine;
1459  if (d->capital == QFont::SmallCaps && ch.isLower())
1460  engine = d->smallCapsFontPrivate()->engineForScript(script);
1461  else
1462  engine = d->engineForScript(script);
1463  Q_ASSERT(engine != 0);
1464  if (engine->type() == QFontEngine::Box)
1465  return 0;
1466 
1468 
1469  QGlyphLayoutArray<10> glyphs;
1470  int nglyphs = 9;
1471  engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0);
1472  // ### can nglyphs != 1 happen at all? Not currently I think
1473  qreal rb;
1474  engine->getGlyphBearings(glyphs.glyphs[0], 0, &rb);
1475  return rb;
1476 
1477 }
1478 
1490 {
1491  int pos = text.indexOf(QLatin1Char('\x9c'));
1492  int len = (pos != -1) ? pos : text.length();
1493 
1494  QStackTextEngine layout(text, d.data());
1495  layout.ignoreBidi = true;
1496  layout.itemize();
1497  return layout.width(0, len).toReal();
1498 }
1499 
1528 {
1530  return 0.;
1531 
1532  const int script = QUnicodeTables::script(ch);
1533  QFontEngine *engine;
1534  if (d->capital == QFont::SmallCaps && ch.isLower())
1535  engine = d->smallCapsFontPrivate()->engineForScript(script);
1536  else
1537  engine = d->engineForScript(script);
1538  Q_ASSERT(engine != 0);
1539 
1541 
1542  QGlyphLayoutArray<8> glyphs;
1543  int nglyphs = 7;
1544  engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0);
1545  return glyphs.advances_x[0].toReal();
1546 }
1547 
1569 {
1570  int len = text.length();
1571  if (len == 0)
1572  return QRectF();
1573 
1574  QStackTextEngine layout(text, d.data());
1575  layout.ignoreBidi = true;
1576  layout.itemize();
1577  glyph_metrics_t gm = layout.boundingBox(0, len);
1578  return QRectF(gm.x.toReal(), gm.y.toReal(),
1579  gm.width.toReal(), gm.height.toReal());
1580 }
1581 
1596 {
1597  const int script = QUnicodeTables::script(ch);
1598  QFontEngine *engine;
1599  if (d->capital == QFont::SmallCaps && ch.isLower())
1600  engine = d->smallCapsFontPrivate()->engineForScript(script);
1601  else
1602  engine = d->engineForScript(script);
1603  Q_ASSERT(engine != 0);
1604 
1606 
1607  QGlyphLayoutArray<10> glyphs;
1608  int nglyphs = 9;
1609  engine->stringToCMap(&ch, 1, &glyphs, &nglyphs, 0);
1610  glyph_metrics_t gm = engine->boundingBox(glyphs.glyphs[0]);
1611  return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal());
1612 }
1613 
1676 QRectF QFontMetricsF::boundingRect(const QRectF &rect, int flags, const QString& text,
1677  int tabStops, int *tabArray) const
1678 {
1679  int tabArrayLen = 0;
1680  if (tabArray)
1681  while (tabArray[tabArrayLen])
1682  tabArrayLen++;
1683 
1684  QRectF rb;
1685  qt_format_text(QFont(d.data()), rect, flags | Qt::TextDontPrint, text, &rb, tabStops, tabArray,
1686  tabArrayLen, 0);
1687  return rb;
1688 }
1689 
1718 QSizeF QFontMetricsF::size(int flags, const QString &text, int tabStops, int *tabArray) const
1719 {
1720  return boundingRect(QRectF(), flags | Qt::TextLongestVariant, text, tabStops, tabArray).size();
1721 }
1722 
1749 {
1750  if (text.length() == 0)
1751  return QRect();
1752 
1753  QStackTextEngine layout(text, d.data());
1754  layout.ignoreBidi = true;
1755  layout.itemize();
1756  glyph_metrics_t gm = layout.tightBoundingBox(0, text.length());
1757  return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal());
1758 }
1759 
1780 {
1781  QString _text = text;
1782  if (!(flags & Qt::TextLongestVariant)) {
1783  int posA = 0;
1784  int posB = _text.indexOf(QLatin1Char('\x9c'));
1785  while (posB >= 0) {
1786  QString portion = _text.mid(posA, posB - posA);
1787  if (size(flags, portion).width() <= width)
1788  return portion;
1789  posA = posB + 1;
1790  posB = _text.indexOf(QLatin1Char('\x9c'), posA);
1791  }
1792  _text = _text.mid(posA);
1793  }
1794  QStackTextEngine engine(_text, QFont(d.data()));
1795  return engine.elidedText(mode, QFixed::fromReal(width), flags);
1796 }
1797 
1805 {
1807  Q_ASSERT(engine != 0);
1808  return engine->underlinePosition().toReal();
1809 }
1810 
1818 {
1819  return ascent() + 1;
1820 }
1821 
1829 {
1830  return ascent() / 3.;
1831 }
1832 
1840 {
1842  Q_ASSERT(engine != 0);
1843  return engine->lineThickness().toReal();
1844 }
1845 
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
virtual QFixed lineThickness() const
double d
Definition: qnumeric_p.h:62
QRect toAlignedRect() const
Returns a QRect based on the values of this rectangle that is the smallest possible integer rectangle...
Definition: qrect.cpp:2817
QFontMetricsF(const QFont &)
Constructs a font metrics object for font.
virtual qreal minRightBearing() const
qreal maxWidth() const
Returns the width of the widest character in the font.
virtual QFixed averageCharWidth() const
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
bool inFontUcs4(uint ucs4) const
Returns true if the given character encoded in UCS-4/UTF-32 is a valid character in the font; otherwi...
double qreal
Definition: qglobal.h:1193
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontmetrics.h:201
static mach_timebase_info_data_t info
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
QString elidedText(Qt::TextElideMode mode, const QFixed &width, int flags=0) const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int leading() const
Returns the leading of the font.
QFixed * advances_x
qreal ascent() const
Returns the ascent of the font.
int maxWidth() const
Returns the width of the widest character in the font.
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
int logicalDpiY() const
Definition: qpaintdevice.h:96
int descent() const
Returns the descent of the font.
HB_Glyph * glyphs
qreal descent() const
Returns the descent of the font.
int rightBearing(QChar) const
Returns the right bearing of character ch in the font.
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
TextElideMode
Definition: qnamespace.h:263
friend class QFontPrivate
Definition: qfontmetrics.h:136
~QFontMetricsF()
Destroys the font metrics object and frees all allocated resources.
QRect tightBoundingRect(const QString &text) const
Returns a tight bounding rectangle around the characters in the string specified by text...
int strikeOutPos() const
Returns the distance from the base line to where the strikeout line should be drawn.
QRectF tightBoundingRect(const QString &text) const
Returns a tight bounding rectangle around the characters in the string specified by text...
qreal minRightBearing() const
Returns the minimum right bearing of the font.
QSizeF size(int flags, const QString &str, int tabstops=0, int *tabarray=0) const
Returns the size in pixels of the characters in the given text.
The QString class provides a Unicode character string.
Definition: qstring.h:83
qreal lineSpacing() const
Returns the distance from one base line to the next.
static QFixed fromReal(qreal r)
Definition: qfixed_p.h:70
int minLeftBearing() const
Returns the minimum left bearing of the font.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal averageCharWidth() const
Returns the average width of glyphs in the font.
virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const =0
QFontPrivate * smallCapsFontPrivate() const
Definition: qfont.cpp:323
qreal rightBearing(QChar) const
Returns the right bearing of character ch in the font.
virtual Type type() const =0
~QFontMetrics()
Destroys the font metrics object and frees all allocated resources.
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
static QString fromRawData(const QChar *, int size)
Constructs a QString that uses the first size Unicode characters in the array unicode.
Definition: qstring.cpp:7673
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags=0) const
If the string text is wider than width, returns an elided version of the string (i.
Category category() const
Returns the character&#39;s category.
Definition: qchar.cpp:853
bool isLower() const
Returns true if the character is a lowercase letter, i.
Definition: qchar.h:272
int minRightBearing() const
Returns the minimum right bearing of the font.
virtual void getGlyphBearings(glyph_t glyph, qreal *leftBearing=0, qreal *rightBearing=0)
int ascent() const
Returns the ascent of the font.
QRect boundingRect(QChar) const
Returns the rectangle that is covered by ink if character ch were to be drawn at the origin of the co...
virtual qreal maxCharWidth() const =0
QFontMetricsF & operator=(const QFontMetricsF &)
Assigns the font metrics fm to this font metrics object.
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
int leftBearing(QChar) const
Returns the left bearing of character ch in the font.
int averageCharWidth() const
Returns the average width of glyphs in the font.
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
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
bool operator==(const QFontMetrics &other)
Returns true if other is equal to this object; otherwise returns false.
QRectF boundingRect(const QString &string) const
Returns the bounding rectangle of the characters in the string specified by text. ...
QSize size(int flags, const QString &str, int tabstops=0, int *tabarray=0) const
Returns the size in pixels of text.
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
bool inFontUcs4(uint ucs4) const
Returns true if the character given by ch, encoded in UCS-4/UTF-32, is a valid character in the font;...
QFontMetrics(const QFont &)
Constructs a font metrics object for font.
virtual bool canRender(const QChar *string, int len)=0
uint capital
Definition: qfont_p.h:192
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
virtual QFixed ascent() const =0
const char * layout
virtual QFixed descent() const =0
qreal height() const
Returns the height of the font.
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
bool inFont(QChar) const
Returns true if character ch is a valid character in the font; otherwise returns false.
bool inFont(QChar) const
Returns true if character ch is a valid character in the font; otherwise returns false.
int lineWidth() const
Returns the width of the underline and strikeout lines, adjusted for the point size of the font...
qreal minLeftBearing() const
Returns the minimum left bearing of the font.
virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs)=0
int xHeight() const
Returns the &#39;x&#39; height of the font.
int charWidth(const QString &str, int pos) const
Returns the width of the character at position pos in the string text.
QFontMetrics & operator=(const QFontMetrics &)
Assigns the font metrics fm.
virtual qreal minLeftBearing() const
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
virtual QFixed xHeight() const
QFontEngine * engineForScript(int script) const
Definition: qfont.cpp:294
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
The QX11Info class provides information about the X display configuration.
Definition: qx11info_x11.h:63
qreal leading() const
Returns the leading of the font.
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
Q_GUI_EXPORT int qt_defaultDpi()
Definition: qfont.cpp:240
int underlinePos() const
Returns the distance from the base line to where an underscore should be drawn.
int overlinePos() const
Returns the distance from the base line to where an overline should be drawn.
qreal lineWidth() const
Returns the width of the underline and strikeout lines, adjusted for the point size of the font...
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfont.h:343
qreal underlinePos() const
Returns the distance from the base line to where an underscore should be drawn.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
qreal toReal() const
Definition: qfixed_p.h:77
QSizeF size() const
Returns the size of the rectangle.
Definition: qrect.h:713
bool operator==(const QFontMetricsF &other)
Returns true if the font metrics are equal to the other font metrics; otherwise returns false...
int lineSpacing() const
Returns the distance from one base line to the next.
The QFontMetricsF class provides font metrics information.
Definition: qfontmetrics.h:145
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
qreal xHeight() const
Returns the &#39;x&#39; height of the font.
qreal width(const QString &string) const
Returns the width in pixels of the characters in the given text.
void qt_format_text(const QFont &font, const QRectF &_r, int tf, const QString &text, QRectF *brect, int tabStops, int *tabArray, int tabArrayLen, QPainter *painter)
Definition: qpainter.cpp:8448
int height() const
Returns the height of the font.
void alterCharForCapitalization(QChar &c) const
Definition: qfont.cpp:309
qreal leftBearing(QChar) const
Returns the left bearing of character ch in the font.
qreal strikeOutPos() const
Returns the distance from the base line to where the strikeout line should be drawn.
QString elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags=0) const
If the string text is wider than width, returns an elided version of the string (i.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
const QX11Info * qt_x11Info(const QPaintDevice *pd)
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
virtual QFixed underlinePosition() const
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontmetrics.h:141
#define text
Definition: qobjectdefs.h:80
virtual QFixed leading() const =0
qreal overlinePos() const
Returns the distance from the base line to where an overline should be drawn.
int screen() const
Returns the number of the screen currently in use.
static qreal toReal(Register *reg, int type, bool *ok=0)
#define Q_FUNC_INFO
Definition: qglobal.h:1871
static QString fromUcs4(const uint *, int size=-1)
Returns a QString initialized with the first size characters of the Unicode string unicode (ISO-10646...
Definition: qstring.cpp:4356