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

PostScript printing engine outputs garbage on SVG rect element

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P3: Somewhat important
    • 4.8.x
    • 4.7.2
    • GUI: Printing, SVG Support
    • None
    • Windows 7; Ubuntu 10.10

    Description

      If you render a QGraphicsScene containing a QGraphicsSvgItem to a QPrinter, the generated PostScript is garbage if the SVG contains a <rect> element.

      To reproduce:

      1. Run the program below as-is, printing to a Postscript printer. (I am using the "Print to file" option in Ubuntu so as not to waste paper, but the results are the same if you actually print to a physical printer.) Notice:
        • It finishes quickly
        • If you open the PS document in an image viewer, the full image is printed
        • If you open the PS document in a text editor, it is relatively clean (by postscript standards...)
      2. Next, uncomment the line in the SVG containing the <rect> element (marked with comment "problem" at the end of the line) and run it again. Notice:
        • It takes a long, long time to generate the output.
        • If you open the PS document in an image viewer, the image is clipped at the size of the rectangle.
        • If you open the PS document in a text editor, it contains a huge block of garbage commands.
      main.cpp
      #include <QtGui>
      #include <QtSvg>
      
      int main(int argc, char **argv) {
        QApplication app(argc, argv);
      
        QTemporaryFile temp;
        temp.open();
        temp.write(
              "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
              "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.2\" "
                  "baseProfile=\"tiny\" width=\"500\" height=\"500\" "
                  "viewBox=\"0 0 500 500\">"
      //        "<rect width=\"200\" height=\"200\" fill=\"white\"/>"       // problem
              "<circle cx=\"100\" cy=\"100\" r=\"50\" stroke=\"black\" "
                  "stroke-width=\"2\" fill=\"red\"/>"
              "<circle cx=\"400\" cy=\"400\" r=\"50\" stroke=\"black\" "
                  "stroke-width=\"2\" fill=\"blue\"/>"
              "<circle cx=\"250\" cy=\"250\" r=\"180\" stroke=\"black\" "
                  "stroke-width=\"2\" fill=\"green\"/>"
              "</svg>");
        temp.flush();
        temp.close();
      
        QGraphicsScene scene;
        QGraphicsSvgItem *item = new QGraphicsSvgItem(temp.fileName());
        scene.addItem(item);
      
      //  // It displays fine in the graphics view.
      //  QGraphicsView view(&scene);
      //  view.show();
      //  return app.exec();
      
        // It vomits using the postscript printer.
        QPrinter printer(QPrinter::HighResolution);
        QPrintDialog dialog(&printer);
        if (dialog.exec() == QDialog::Accepted) {
          QPainter painter(&printer);
          scene.render(&painter);
        }
      }
      

      It is fine going to a QGraphicsView. I have reproduced this problem on Ubuntu 10.10 and Windows 7 (physical print and XPS print), although on one Windows 7 machine I was not able to reproduce it. It also works fine if printing to PDF; just postscript is generating garbage.

      Attachments

        Issue Links

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

          Activity

            People

              Unassigned Unassigned
              dmateer Dave Mateer
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes