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

Mac: QImage::drawText() can miss pixel in some characters when drawn with some fonts at small sizes

    XMLWordPrintable

Details

    • macOS

    Description

      QImage can in some cases draw text wrongly when comparing it to how QPixmap draws it.

      This only happens on Mac.

      Reproducible with the following example:

      • The letter '7' in the bad.png is missing a pixel.
        #include <qpainter>
        #include <qimage>
        #include <qpixmap>
        #include <qapplication>
        #include <qcolor>

      int main(int argc, char** argv)
      {
      QApplication app(argc, argv);

      QPixmap pm(QSize(100, 100));
      pm.fill(QColor(0, 0, 0, 0));
      QFont f("Courier", 8);
      f.setStyleHint(QFont::AnyStyle, QFont::NoAntialias);

      QPainter ppm(&pm);
      ppm.setFont(f);
      ppm.setPen(Qt::white);

      ppm.drawText(QRect(0, 0, 100, 100), 0x484, "012345678 abcdefg");
      pm.save("good.png", "PNG");

      QImage img(QSize(100, 100), QImage::Format_ARGB32);

      QPainter imgP(&img);
      imgP.setFont(f);
      imgP.setPen(Qt::white);

      imgP.drawText(QRect(0, 0, 100, 100), 0x484, "012345678 abcdefg");

      img.save("bad.png", "PNG");
      }

      Attachments

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

        Activity

          People

            shausman Simon Hausmann
            admin Administrator
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes