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

Brush transformations are not supported by the PDF engine

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 6.2.1, 6.3.0 Alpha
    • 6.2.0 RC2
    • PDF
    • None
    • 2a546690bf457f4bfee0910ba979441511843f8b (qt/qtbase/dev) 4901e9215b9a406ca45e6efe676cf21961f7d774 (qt/qtbase/6.2)

    Description

       

      When executing the following code

       

      #include <QGuiApplication>
      #include <QImage>
      #include <QPainter>
      #include <QPdfWriter>
      static const int TEXTURE_SIZE = 64;
      static const int PAINT_SCALE = 40;
      static const int PAINT_SIZE = 256;
      static QImage createTexture() {
       QImage image(TEXTURE_SIZE, TEXTURE_SIZE, QImage::Format_ARGB32);
       QPainter p(&image);
       p.setPen(Qt::NoPen);
       p.fillRect(0, 0, TEXTURE_SIZE, TEXTURE_SIZE, Qt::red);
       p.setBrush(QBrush(Qt::white, Qt::BDiagPattern));
       p.drawRect(0, 0, TEXTURE_SIZE, TEXTURE_SIZE);
       p.end();
       return image;
      }
      static void drawOnPainter(QPainter *painter) {
       painter->setPen(Qt::NoPen);
       painter->scale(PAINT_SCALE, PAINT_SCALE);
       QBrush brush(createTexture());
       brush.setTransform(painter->worldTransform().inverted());
       painter->setBrush(brush);
       painter->drawRect(0, 0, PAINT_SIZE, PAINT_SIZE);
      }
      static void drawOnPdf() {
       QPdfWriter pdf("test.pdf");
       pdf.setResolution(72);
       pdf.setPageSize(QPageSize::A4);
       QPainter p(&pdf);
       drawOnPainter(&p);
       p.end();
      }
      static void drawOnImage() {
       QImage i(700, 700, QImage::Format_ARGB32);
       QPainter p(&i);
       drawOnPainter(&p);
       p.end();
       i.save("test.png");
      }
      int main (int argc, char **argv) {
       QGuiApplication app(argc, argv);
       drawOnPdf();
       drawOnImage();
       return 0;
      }
       

       

      The generated PDF file is "terrible" compared to the PNG file (attached both)

      Attachments

        1. test_with_patch.pdf
          235 kB
        2. test.pdf
          4 kB
        3. test.png
          test.png
          6 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            vgt Eirik Aavitsland
            tsdgeos_kdab Albert Astals Cid
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes