src/gui/text/qfontmetrics.cpp
changeset 30 5dc02b23752f
parent 22 79de32ba3296
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
   326 */
   326 */
   327 int QFontMetrics::height() const
   327 int QFontMetrics::height() const
   328 {
   328 {
   329     QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
   329     QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
   330     Q_ASSERT(engine != 0);
   330     Q_ASSERT(engine != 0);
   331     return qRound(engine->ascent() + engine->descent()) + 1;
   331     return qRound(engine->ascent()) + qRound(engine->descent()) + 1;
   332 }
   332 }
   333 
   333 
   334 /*!
   334 /*!
   335     Returns the leading of the font.
   335     Returns the leading of the font.
   336 
   336 
   354 */
   354 */
   355 int QFontMetrics::lineSpacing() const
   355 int QFontMetrics::lineSpacing() const
   356 {
   356 {
   357     QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
   357     QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
   358     Q_ASSERT(engine != 0);
   358     Q_ASSERT(engine != 0);
   359     return qRound(engine->leading() + engine->ascent() + engine->descent()) + 1;
   359     return qRound(engine->leading()) + qRound(engine->ascent()) + qRound(engine->descent()) + 1;
   360 }
   360 }
   361 
   361 
   362 /*!
   362 /*!
   363     Returns the minimum left bearing of the font.
   363     Returns the minimum left bearing of the font.
   364 
   364 
   533         len = text.length();
   533         len = text.length();
   534     }
   534     }
   535     if (len == 0)
   535     if (len == 0)
   536         return 0;
   536         return 0;
   537 
   537 
   538     QTextEngine layout(text, d.data());
   538     QStackTextEngine layout(text, d.data());
   539     layout.ignoreBidi = true;
   539     layout.ignoreBidi = true;
   540     return qRound(layout.width(0, len));
   540     return qRound(layout.width(0, len));
   541 }
   541 }
   542 
   542 
   543 /*!
   543 /*!
   609     if (script != QUnicodeTables::Common) {
   609     if (script != QUnicodeTables::Common) {
   610         // complex script shaping. Have to do some hard work
   610         // complex script shaping. Have to do some hard work
   611         int from = qMax(0, pos - 8);
   611         int from = qMax(0, pos - 8);
   612         int to = qMin(text.length(), pos + 8);
   612         int to = qMin(text.length(), pos + 8);
   613         QString cstr = QString::fromRawData(text.unicode() + from, to - from);
   613         QString cstr = QString::fromRawData(text.unicode() + from, to - from);
   614         QTextEngine layout(cstr, d.data());
   614         QStackTextEngine layout(cstr, d.data());
   615         layout.ignoreBidi = true;
   615         layout.ignoreBidi = true;
   616         layout.itemize();
   616         layout.itemize();
   617         width = qRound(layout.width(pos-from, 1));
   617         width = qRound(layout.width(pos-from, 1));
   618     } else if (QChar::category(ch.unicode()) == QChar::Mark_NonSpacing) {
   618     } else if (QChar::category(ch.unicode()) == QChar::Mark_NonSpacing) {
   619         width = 0;
   619         width = 0;
   658 QRect QFontMetrics::boundingRect(const QString &text) const
   658 QRect QFontMetrics::boundingRect(const QString &text) const
   659 {
   659 {
   660     if (text.length() == 0)
   660     if (text.length() == 0)
   661         return QRect();
   661         return QRect();
   662 
   662 
   663     QTextEngine layout(text, d.data());
   663     QStackTextEngine layout(text, d.data());
   664     layout.ignoreBidi = true;
   664     layout.ignoreBidi = true;
   665     layout.itemize();
   665     layout.itemize();
   666     glyph_metrics_t gm = layout.boundingBox(0, text.length());
   666     glyph_metrics_t gm = layout.boundingBox(0, text.length());
   667     return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height));
   667     return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height));
   668 }
   668 }
   828 QRect QFontMetrics::tightBoundingRect(const QString &text) const
   828 QRect QFontMetrics::tightBoundingRect(const QString &text) const
   829 {
   829 {
   830     if (text.length() == 0)
   830     if (text.length() == 0)
   831         return QRect();
   831         return QRect();
   832 
   832 
   833     QTextEngine layout(text, d.data());
   833     QStackTextEngine layout(text, d.data());
   834     layout.ignoreBidi = true;
   834     layout.ignoreBidi = true;
   835     layout.itemize();
   835     layout.itemize();
   836     glyph_metrics_t gm = layout.tightBoundingBox(0, text.length());
   836     glyph_metrics_t gm = layout.tightBoundingBox(0, text.length());
   837     return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height));
   837     return QRect(qRound(gm.x), qRound(gm.y), qRound(gm.width), qRound(gm.height));
   838 }
   838 }
  1373 qreal QFontMetricsF::width(const QString &text) const
  1373 qreal QFontMetricsF::width(const QString &text) const
  1374 {
  1374 {
  1375     int pos = text.indexOf(QLatin1Char('\x9c'));
  1375     int pos = text.indexOf(QLatin1Char('\x9c'));
  1376     int len = (pos != -1) ? pos : text.length();
  1376     int len = (pos != -1) ? pos : text.length();
  1377 
  1377 
  1378     QTextEngine layout(text, d.data());
  1378     QStackTextEngine layout(text, d.data());
  1379     layout.ignoreBidi = true;
  1379     layout.ignoreBidi = true;
  1380     layout.itemize();
  1380     layout.itemize();
  1381     return layout.width(0, len).toReal();
  1381     return layout.width(0, len).toReal();
  1382 }
  1382 }
  1383 
  1383 
  1450 {
  1450 {
  1451     int len = text.length();
  1451     int len = text.length();
  1452     if (len == 0)
  1452     if (len == 0)
  1453         return QRectF();
  1453         return QRectF();
  1454 
  1454 
  1455     QTextEngine layout(text, d.data());
  1455     QStackTextEngine layout(text, d.data());
  1456     layout.ignoreBidi = true;
  1456     layout.ignoreBidi = true;
  1457     layout.itemize();
  1457     layout.itemize();
  1458     glyph_metrics_t gm = layout.boundingBox(0, len);
  1458     glyph_metrics_t gm = layout.boundingBox(0, len);
  1459     return QRectF(gm.x.toReal(), gm.y.toReal(),
  1459     return QRectF(gm.x.toReal(), gm.y.toReal(),
  1460                   gm.width.toReal(), gm.height.toReal());
  1460                   gm.width.toReal(), gm.height.toReal());
  1623 QRectF QFontMetricsF::tightBoundingRect(const QString &text) const
  1623 QRectF QFontMetricsF::tightBoundingRect(const QString &text) const
  1624 {
  1624 {
  1625     if (text.length() == 0)
  1625     if (text.length() == 0)
  1626         return QRect();
  1626         return QRect();
  1627 
  1627 
  1628     QTextEngine layout(text, d.data());
  1628     QStackTextEngine layout(text, d.data());
  1629     layout.ignoreBidi = true;
  1629     layout.ignoreBidi = true;
  1630     layout.itemize();
  1630     layout.itemize();
  1631     glyph_metrics_t gm = layout.tightBoundingBox(0, text.length());
  1631     glyph_metrics_t gm = layout.tightBoundingBox(0, text.length());
  1632     return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal());
  1632     return QRectF(gm.x.toReal(), gm.y.toReal(), gm.width.toReal(), gm.height.toReal());
  1633 }
  1633 }