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

[REG 5.13->5.14] Drawing of SVG elements into bounds broke (if a viewBox is present)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 5.14.0 RC1
    • 5.14.0 Beta2
    • SVG Support
    • None
    • e489a325769d295ee3b3948d98f5d07814dffd97 (qt/qtsvg/5.14)

    Description

      QSvgRenderer has a render function that allows to draw any SVG element into a user-defined area/bounds (onto a paint device). That function is in QtSvg since early Qt4 times, and adds a useful addition to just rendering whole SVG documents.

      From the documentation:
      void QSvgRenderer::render(QPainter *painter, const QString &elementId, const QRectF &bounds = QRectF())

      Renders the given element with elementId using the given painter on the specified bounds. If the bounding rectangle is not specified the SVG element is mapped to the whole paint device.

      I created an example. This is the SVG document with two elements:

      The following code draws both elements once into the upper left corner and once into the bottom right corner of an area:

      [...]
              svgRenderer->render(&p, "element1", QRectF(rect.topLeft(), rect.center()));
              svgRenderer->render(&p, "element2", QRectF(rect.topLeft(), rect.center()));
      
              svgRenderer->render(&p, "element1", QRectF(rect.center(), rect.bottomRight()));
              svgRenderer->render(&p, "element2", QRectF(rect.center(), rect.bottomRight()));
      [...]
      

      The result:

      Unfortunatelly, this feature broke with 14fa459, which made the output of above program look like:

      The following fix c3ba576 addressed the use-case of rendering the whole SVG document but did not fix this issue here. After c3ba576, the program output looks like:

      I think that in the case of void QSvgRenderer::render(QPainter *painter, const QString &elementId, const QRectF &bounds = QRectF()), the viewport of the document should be ignored, and scaling should be allow to be non-proportional.

      Shall I make an auto test for this?

      Attachments

        1. after-14fa459.png
          after-14fa459.png
          3 kB
        2. after-c3ba576.png
          after-c3ba576.png
          2 kB
        3. origin_document.png
          origin_document.png
          5 kB
        4. origin_document.svg
          5 kB
        5. svg-render-element-to-bounds.zip
          3 kB
        6. until-qt-5.14.png
          until-qt-5.14.png
          2 kB

        Issue Links

          For Gerrit Dashboard: QTBUG-79933
          # Subject Branch Project Status CR V

          Activity

            People

              vgt Eirik Aavitsland
              portale Alessandro Portale
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes