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

Setting pen on QPainter using print engine may result in distorted painting

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.6.1
    • 4.3.2
    • GUI: Printing
    • None
    • de43f6f89e1344045f0fb5a319a44e5d604d414e

    Description

      Consider the following example:

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

      QPrinter printer;
      QPrintDialog printDialog(&printer, 0);

      if(printDialog.exec() == QDialog::Accepted)

      { QPainter painter(&printer); painter.setMatrix(QMatrix(0.000153778, 0.0, 0.0, -0.000153778, 0136.581, 01236.72)); painter.setPen(Qt::black); painter.setBrush(QBrush(Qt::red)); painter.drawRect(4099900, 5099900, 300000, 300000); painter.setPen(Qt::blue); painter.drawLine(-6001000, 5099900, 4799900, 5099900); painter.end(); }

      return 0;
      }

      The expected result is that the blue line is aligned with the top of the rectangle (visually at the bottom since the matrix is scaled with a negative factor), as the two have the same y-coordinate.

      The actual result is that the blue line is painted a little bit above the rectangle (visually under the rectangle because of the matrix scaling). If the blue pen is not set, the line is aligned correctly with the rectangle. The line should be painted the same regardless of whether or not the pen is set on it.

      The difference between setting the pen and not setting the pen is that setting the pen causes an incorrect matrix to be written to the pdf file. If a pen is not set, the matrix is not written to the file. The problem seems to be caused by qt_real_to_string() in qpdf.cpp.

      The written matrix has a too low precision and results in the problem. Here are the events in the wrong program:

      1. The rectangle is written out using the following matrix:
      QTransform(
      11=0.000153778
      12=0
      13=0
      21=0
      22=-0.000153778
      23=0
      31=136.581
      32=1236.72
      33=1)

      This results in the coordinates:
      MoveTo: QPointF(767.055, 452.468)
      LineTo: QPointF(813.189, 452.468)
      LineTo: QPointF(813.189, 406.334)
      LineTo: QPointF(767.055, 406.334)
      LineTo: QPointF(767.055, 452.468)

      2. The pen is set and the matrix is written to the pdf file. But instead of the above matrix the following one is written:

      11 = 0.000153
      12 = 0
      13 = 0
      21 = 0
      22 = -0.000153
      23 = 0
      31 = 136.580
      32 = 1236.72
      33 = 1

      One sees that the values 11 and 22 have been truncated. Additionally value 31 is wrong.

      3. The line is written in its own coordinates and the PDF-Viewer has to perform the matrix transformation.

      Altogether the problem lies in qt_real_to_string() in qpdf.cpp. This function truncates values and performs wrong rounding.

      Attachments

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

        Activity

          People

            sletta Gunnar Sletta
            sthomass Stian Sandvik Thomassen (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes