src/gui/text/qfontmetrics.cpp
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
   524 
   524 
   525     \sa boundingRect()
   525     \sa boundingRect()
   526 */
   526 */
   527 int QFontMetrics::width(const QString &text, int len) const
   527 int QFontMetrics::width(const QString &text, int len) const
   528 {
   528 {
       
   529     return width(text, len, 0);
       
   530 }
       
   531 
       
   532 /*!
       
   533     \internal
       
   534 */
       
   535 int QFontMetrics::width(const QString &text, int len, int flags) const
       
   536 {
   529     int pos = text.indexOf(QLatin1Char('\x9c'));
   537     int pos = text.indexOf(QLatin1Char('\x9c'));
   530     if (pos != -1) {
   538     if (pos != -1) {
   531         len = (len < 0) ? pos : qMin(pos, len);
   539         len = (len < 0) ? pos : qMin(pos, len);
   532     } else if (len < 0) {
   540     } else if (len < 0) {
   533         len = text.length();
   541         len = text.length();
   534     }
   542     }
   535     if (len == 0)
   543     if (len == 0)
   536         return 0;
   544         return 0;
       
   545 
       
   546     if (flags & Qt::TextBypassShaping) {
       
   547         // Skip harfbuzz complex shaping, only use advances
       
   548         int numGlyphs = len;
       
   549         QVarLengthGlyphLayoutArray glyphs(numGlyphs);
       
   550         QFontEngine *engine = d->engineForScript(QUnicodeTables::Common);
       
   551         if (!engine->stringToCMap(text.data(), len, &glyphs, &numGlyphs, 0)) {
       
   552             glyphs.resize(numGlyphs);
       
   553             if (!engine->stringToCMap(text.data(), len, &glyphs, &numGlyphs, 0))
       
   554                 Q_ASSERT_X(false, Q_FUNC_INFO, "stringToCMap shouldn't fail twice");
       
   555         }
       
   556 
       
   557         QFixed width;
       
   558         for (int i = 0; i < numGlyphs; ++i)
       
   559             width += glyphs.advances_x[i];
       
   560         return qRound(width);
       
   561     }
   537 
   562 
   538     QStackTextEngine layout(text, d.data());
   563     QStackTextEngine layout(text, d.data());
   539     layout.ignoreBidi = true;
   564     layout.ignoreBidi = true;
   540     return qRound(layout.width(0, len));
   565     return qRound(layout.width(0, len));
   541 }
   566 }