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

SVGs with gradient and opacity properties are not correctly rendered exported to PDF

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.8.1
    • GUI: Printing
    • None

    Description

      Having

      cm_grad.svg

      <svg width="40mm" height="40mm" version="1.1" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
       <defs>
        <linearGradient id="a" x2="40" y1="20" y2="20" gradientUnits="userSpaceOnUse">
         <stop stop-color="#00ddf2" offset="0"/>
         <stop stop-color="#ff1be8" stop-opacity=".2" offset="1"/>
        </linearGradient>
       </defs>
       <rect width="40" height="40" fill="url(#a)"/>
      </svg>
      

      bw_grad.svg

      <svg width="40mm" height="40mm" version="1.1" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
       <defs>
        <linearGradient id="a" x2="40" y1="20" y2="20" gradientUnits="userSpaceOnUse">
         <stop offset="0"/>
         <stop stop-opacity=".3" offset="1"/>
        </linearGradient>
       </defs>
       <rect width="40" height="40" fill="url(#a)"/>
      </svg>
      

      The following code creates a PDF, but the SVGs' opacitbw_grad.svgy gradient is not respected:

      pdf_writer = QPdfWriter('output.pdf')
      pdf_writer.setPageSize(QPageSize(QPageSize.PageSizeId.A4))
      painter = QPainter()
      painter.begin(pdf_writer)
      svg_renderer1 = QSvgRenderer('bw_grad.svg')
      svg_renderer2 = QSvgRenderer('cm_grad.svg')
      svg_renderer1.render(painter, QRectF(500, 500, 2500, 2500))
      svg_renderer2.render(painter, QRectF(1500, 1500, 2500, 2500))
      painter.end()
      

      How it is rendered:

      How it should be rendered:

      Attachments

        1. bw_grad.svg
          0.4 kB
        2. cm_grad.svg
          0.4 kB
        3. output_ok.png
          output_ok.png
          7 kB
        4. output.pdf
          5 kB
        5. output.png
          output.png
          6 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            srutledg Shawn Rutledge
            andreaerdna Andrea Giudiceandrea
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes