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.
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:
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?
|For Gerrit Dashboard: QTBUG-79933|
|281290,5||Re-fix scaling when rendering a specific element by id||5.14||qt/qtsvg||Status: MERGED||+2||0|
|281295,2||QSvgRenderer: Allow to remove a viewBox||5.14||qt/qtsvg||Status: MERGED||+2||0|