Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-91228

QFontMetricsF::horizontalAdvance returns negative value with high font dpi due to integer overflow

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.12.9, 5.15.2, 6.0.1
    • Fix Version/s: None
    • Component/s: GUI: Font handling
    • Labels:
      None
    • Platform/s:
      Linux/X11

      Description

      See the below sample code:

      #include <QtGui>
      
      int main(int argc, char **argv)
      {
      	QGuiApplication app(argc, argv);
      
      	QImage img(1, 1, QImage::Format_ARGB32);
      	img.setDotsPerMeterX(56692);
      	img.setDotsPerMeterY(56692);
      
      	QFont font(QFont("SimSun", 36), &img);
      
      	QFontMetrics fm(font);
      #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
      	qDebug() << "fontDpi: " << fm.fontDpi();
      #endif
      	qDebug() << "width: " << fm.horizontalAdvance(QChar(L','));
      
      	return 0;
      }
      

      Run on Linux platform it prints:

       

      fontDpi: 1440
      width: -304

      The width should be 720 but got -304.

      While debugging the horizontalAdvance, I found that the QFontEngineFT::loadGlyph internal assign an int to short:

       

      g = new Glyph;
      g->data = nullptr;
      g->linearAdvance = info.linearAdvance;
      

      The info.linearAdvance value is 46080 (0xB400), but g->linearAdvance is short!!!

       

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            esabraha Eskil Abrahamsen Blomfeldt
            Reporter:
            timxx Weitian Leung
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes