433int QFontMetrics::leftBearing(QChar ch)
const
435 const int script = ch.script();
437 if (d->capital == QFont::SmallCaps && ch.isLower())
438 engine = d->smallCapsFontPrivate()->engineForScript(script);
440 engine = d->engineForScript(script);
441 Q_ASSERT(engine !=
nullptr);
442 if (engine->type() == QFontEngine::Box)
445 d->alterCharForCapitalization(ch);
447 glyph_t glyph = engine->glyphIndex(ch.unicode());
450 engine->getGlyphBearings(glyph, &lb);
466int QFontMetrics::rightBearing(QChar ch)
const
468 const int script = ch.script();
470 if (d->capital == QFont::SmallCaps && ch.isLower())
471 engine = d->smallCapsFontPrivate()->engineForScript(script);
473 engine = d->engineForScript(script);
474 Q_ASSERT(engine !=
nullptr);
475 if (engine->type() == QFontEngine::Box)
478 d->alterCharForCapitalization(ch);
480 glyph_t glyph = engine->glyphIndex(ch.unicode());
483 engine->getGlyphBearings(glyph,
nullptr, &rb);
502int QFontMetrics::horizontalAdvance(
const QString &text,
int len)
const
505 ? QStringView(text).left(len).indexOf(s_variableLengthStringSeparator)
506 : text.indexOf(s_variableLengthStringSeparator);
509 }
else if (len < 0) {
515 Q_DECL_UNINITIALIZED QStackTextEngine layout(text, QFont(d.data()));
516 return qRound(layout.width(0, len));
529int QFontMetrics::horizontalAdvance(
const QString &text,
const QTextOption &option)
const
531 int pos = text.indexOf(s_variableLengthStringSeparator);
541 Q_DECL_UNINITIALIZED QStackTextEngine layout(text, QFont(d.data()));
542 layout.option = option;
543 return qRound(layout.width(0, len));
572int QFontMetrics::horizontalAdvance(QChar ch)
const
574 if (QChar::category(ch.unicode()) == QChar::Mark_NonSpacing)
577 const int script = ch.script();
579 if (d->capital == QFont::SmallCaps && ch.isLower())
580 engine = d->smallCapsFontPrivate()->engineForScript(script);
582 engine = d->engineForScript(script);
583 Q_ASSERT(engine !=
nullptr);
585 d->alterCharForCapitalization(ch);
587 glyph_t glyph = engine->glyphIndex(ch.unicode());
591 glyphs.numGlyphs = 1;
592 glyphs.glyphs = &glyph;
593 glyphs.advances = &advance;
594 engine->recalcAdvances(&glyphs, { });
596 return qRound(advance);
621QRect QFontMetrics::boundingRect(
const QString &text)
const
623 if (text.size() == 0)
626 Q_DECL_UNINITIALIZED QStackTextEngine layout(text, QFont(d.data()));
628 glyph_metrics_t gm = layout.boundingBox(0, text.size());
629 return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height));
656QRect QFontMetrics::boundingRect(
const QString &text,
const QTextOption &option)
const
658 if (text.size() == 0)
661 Q_DECL_UNINITIALIZED QStackTextEngine layout(text, QFont(d.data()));
662 layout.option = option;
664 glyph_metrics_t gm = layout.boundingBox(0, text.size());
665 return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height));
685QRect QFontMetrics::boundingRect(QChar ch)
const
687 const int script = ch.script();
689 if (d->capital == QFont::SmallCaps && ch.isLower())
690 engine = d->smallCapsFontPrivate()->engineForScript(script);
692 engine = d->engineForScript(script);
693 Q_ASSERT(engine !=
nullptr);
695 d->alterCharForCapitalization(ch);
697 glyph_t glyph = engine->glyphIndex(ch.unicode());
699 glyph_metrics_t gm = engine->boundingBox(glyph);
700 return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height));
759QRect QFontMetrics::boundingRect(
const QRect &rect,
int flags,
const QString &text,
int tabStops,
764 while (tabArray[tabArrayLen])
769 qt_format_text(QFont(d.data()), rr, flags | Qt::TextDontPrint, text, &rb, tabStops, tabArray,
770 tabArrayLen,
nullptr);
772 return rb.toAlignedRect();
798QSize QFontMetrics::size(
int flags,
const QString &text,
int tabStops,
int *tabArray)
const
800 return boundingRect(QRect(0,0,0,0), flags | Qt::TextLongestVariant, text, tabStops, tabArray).size();
824QRect QFontMetrics::tightBoundingRect(
const QString &text)
const
826 if (text.size() == 0)
829 Q_DECL_UNINITIALIZED QStackTextEngine layout(text, QFont(d.data()));
831 glyph_metrics_t gm = layout.tightBoundingBox(0, text.size());
832 return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height));
856QRect QFontMetrics::tightBoundingRect(
const QString &text,
const QTextOption &option)
const
858 if (text.size() == 0)
861 Q_DECL_UNINITIALIZED QStackTextEngine layout(text, QFont(d.data()));
862 layout.option = option;
864 glyph_metrics_t gm = layout.tightBoundingBox(0, text.size());
865 return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height));
890QString QFontMetrics::elidedText(
const QString &text, Qt::TextElideMode mode,
int width,
int flags)
const
892 QString _text = text;
893 if (!(flags & Qt::TextLongestVariant)) {
895 int posB = _text.indexOf(s_variableLengthStringSeparator);
897 QString portion = _text.mid(posA, posB - posA);
898 if (size(flags, portion).width() <= width)
901 posB = _text.indexOf(s_variableLengthStringSeparator, posA);
903 _text = _text.mid(posA);
905 Q_DECL_UNINITIALIZED QStackTextEngine engine(_text, QFont(d.data()));
906 return engine.elidedText(mode, width, flags);
1288qreal QFontMetricsF::xHeight()
const
1290 QFontEngine *engine = d->engineForScript(QChar::Script_Common);
1291 Q_ASSERT(engine !=
nullptr);
1292 if (d->capital == QFont::SmallCaps)
1293 return d->smallCapsFontPrivate()->engineForScript(QChar::Script_Common)->ascent().toReal();
1294 return engine->xHeight().toReal();
1346qreal QFontMetricsF::leftBearing(QChar ch)
const
1348 const int script = ch.script();
1349 QFontEngine *engine;
1350 if (d->capital == QFont::SmallCaps && ch.isLower())
1351 engine = d->smallCapsFontPrivate()->engineForScript(script);
1353 engine = d->engineForScript(script);
1354 Q_ASSERT(engine !=
nullptr);
1355 if (engine->type() == QFontEngine::Box)
1358 d->alterCharForCapitalization(ch);
1360 glyph_t glyph = engine->glyphIndex(ch.unicode());
1363 engine->getGlyphBearings(glyph, &lb);
1379qreal QFontMetricsF::rightBearing(QChar ch)
const
1381 const int script = ch.script();
1382 QFontEngine *engine;
1383 if (d->capital == QFont::SmallCaps && ch.isLower())
1384 engine = d->smallCapsFontPrivate()->engineForScript(script);
1386 engine = d->engineForScript(script);
1387 Q_ASSERT(engine !=
nullptr);
1388 if (engine->type() == QFontEngine::Box)
1391 d->alterCharForCapitalization(ch);
1393 glyph_t glyph = engine->glyphIndex(ch.unicode());
1396 engine->getGlyphBearings(glyph,
nullptr, &rb);
1414qreal QFontMetricsF::horizontalAdvance(
const QString &text,
int length)
const
1416 int pos = (length >= 0)
1417 ? QStringView(text).left(length).indexOf(s_variableLengthStringSeparator)
1418 : text.indexOf(s_variableLengthStringSeparator);
1421 else if (length < 0)
1422 length = text.size();
1427 Q_DECL_UNINITIALIZED QStackTextEngine layout(text, QFont(d.data()));
1429 return layout.width(0, length).toReal();
1442qreal QFontMetricsF::horizontalAdvance(
const QString &text,
const QTextOption &option)
const
1444 int pos = text.indexOf(s_variableLengthStringSeparator);
1449 length = text.size();
1454 Q_DECL_UNINITIALIZED QStackTextEngine layout(text, QFont(d.data()));
1455 layout.option = option;
1457 return layout.width(0, length).toReal();
1486qreal QFontMetricsF::horizontalAdvance(QChar ch)
const
1488 if (ch.category() == QChar::Mark_NonSpacing)
1491 const int script = ch.script();
1492 QFontEngine *engine;
1493 if (d->capital == QFont::SmallCaps && ch.isLower())
1494 engine = d->smallCapsFontPrivate()->engineForScript(script);
1496 engine = d->engineForScript(script);
1497 Q_ASSERT(engine !=
nullptr);
1499 d->alterCharForCapitalization(ch);
1501 glyph_t glyph = engine->glyphIndex(ch.unicode());
1504 QGlyphLayout glyphs;
1505 glyphs.numGlyphs = 1;
1506 glyphs.glyphs = &glyph;
1507 glyphs.advances = &advance;
1508 engine->recalcAdvances(&glyphs, { });
1510 return advance.toReal();
1534QRectF QFontMetricsF::boundingRect(
const QString &text)
const
1536 int len = text.size();
1540 Q_DECL_UNINITIALIZED QStackTextEngine layout(text, QFont(d.data()));
1542 glyph_metrics_t gm = layout.boundingBox(0, len);
1543 return QRectF(gm.x.toReal(), gm.y.toReal(),
1544 gm.width.toReal(), gm.height.toReal());
1569QRectF QFontMetricsF::boundingRect(
const QString &text,
const QTextOption &option)
const
1571 if (text.size() == 0)
1574 Q_DECL_UNINITIALIZED QStackTextEngine layout(text, QFont(d.data()));
1575 layout.option = option;
1577 glyph_metrics_t gm = layout.boundingBox(0, text.size());
1578 return QRectF(gm.x.toReal(), gm.y.toReal(),
1579 gm.width.toReal(), gm.height.toReal());
1596QRectF QFontMetricsF::boundingRect(QChar ch)
const
1598 const int script = ch.script();
1599 QFontEngine *engine;
1600 if (d->capital == QFont::SmallCaps && ch.isLower())
1601 engine = d->smallCapsFontPrivate()->engineForScript(script);
1603 engine = d->engineForScript(script);
1604 Q_ASSERT(engine !=
nullptr);
1606 d->alterCharForCapitalization(ch);
1608 glyph_t glyph = engine->glyphIndex(ch.unicode());
1610 glyph_metrics_t gm = engine->boundingBox(glyph);
1611 return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal());
1675QRectF QFontMetricsF::boundingRect(
const QRectF &rect,
int flags,
const QString& text,
1676 int tabStops,
int *tabArray)
const
1678 int tabArrayLen = 0;
1680 while (tabArray[tabArrayLen])
1684 qt_format_text(QFont(d.data()), rect, flags | Qt::TextDontPrint, text, &rb, tabStops, tabArray,
1685 tabArrayLen,
nullptr);
1743QRectF QFontMetricsF::tightBoundingRect(
const QString &text)
const
1745 if (text.size() == 0)
1748 Q_DECL_UNINITIALIZED QStackTextEngine layout(text, QFont(d.data()));
1750 glyph_metrics_t gm = layout.tightBoundingBox(0, text.size());
1751 return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal());
1775QRectF QFontMetricsF::tightBoundingRect(
const QString &text,
const QTextOption &option)
const
1777 if (text.size() == 0)
1780 Q_DECL_UNINITIALIZED QStackTextEngine layout(text, QFont(d.data()));
1781 layout.option = option;
1783 glyph_metrics_t gm = layout.tightBoundingBox(0, text.size());
1784 return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal());
1808QString QFontMetricsF::elidedText(
const QString &text, Qt::TextElideMode mode, qreal width,
int flags)
const
1810 QString _text = text;
1811 if (!(flags & Qt::TextLongestVariant)) {
1813 int posB = _text.indexOf(s_variableLengthStringSeparator);
1815 QString portion = _text.mid(posA, posB - posA);
1816 if (size(flags, portion).width() <= width)
1819 posB = _text.indexOf(s_variableLengthStringSeparator, posA);
1821 _text = _text.mid(posA);
1823 Q_DECL_UNINITIALIZED QStackTextEngine engine(_text, QFont(d.data()));
1824 return engine.elidedText(mode, QFixed::fromReal(width), flags);
QT_BEGIN_NAMESPACE 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)