summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2019-12-20 16:43:48 +0100
committerAlessandro Portale <alessandro.portale@qt.io>2020-01-03 15:09:44 +0100
commitacb66cad2280bda20d26d08d606a66b9660b17aa (patch)
tree9dfb4ea681ab2af549f2e8941487f2279890ba08 /tests
parent2eba1572ee49c22f4734b1fb80aa8023d60a8e70 (diff)
downloadqtsvg-acb66cad2280bda20d26d08d606a66b9660b17aa.tar.gz
Fix yet another viewbox scaling issue, for render to bounds
The recent introduction of keepAspectRation scaling led to wrong output (outside bounds) in the case of an explicitly specified target bounds rect, i.e. QSVGRenderer::render(QPainter *p, QRectF bounds). Fix by reverting to old code path in this case, i.e. allow the user to override the keepAspectRatio behavior by explicitly specifying target bounds. As a driveby, also fix the keepAspectRatio code path in case of a target rect having non-zero x/y coordinates. Now the fix above means that this will never happen in the code as it stands, but it may come in handy later. [ChangeLog][QSVGRenderer] From Qt 5.14.0, normal rendering will keep aspect ratio implied by the viewbox. The render() methods taking an explicit target bounds QRectF parameter can now be used to override that behavior. They will scale the output to the bounds while ignoring aspect ratio, as was the default rendering prior to 5.14.0. Fixes: QTBUG-80888 Change-Id: I399b05ca50d290b8e4b01bdc47b5b6f74c890c9a Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
index 309c646..8ad74f2 100644
--- a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
+++ b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
@@ -60,6 +60,7 @@ private slots:
void testMapViewBoxToTarget();
void testRenderElement();
void testRenderElementToBounds();
+ void testRenderDocumentWithSizeToBounds();
void constructorQXmlStreamReader() const;
void loadQXmlStreamReader() const;
void nestedQXmlStreamReader() const;
@@ -372,6 +373,36 @@ void tst_QSvgRenderer::testRenderElementToBounds()
QCOMPARE(reference, rendering);
}
+void tst_QSvgRenderer::testRenderDocumentWithSizeToBounds()
+{
+ // QTBUG-80888
+ QImage reference(400, 200, QImage::Format_ARGB32);
+ {
+ reference.fill(Qt::transparent);
+ QPainter p(&reference);
+ p.fillRect(100, 100, 100, 50, Qt::blue);
+ p.fillRect(200, 50, 100, 50, Qt::blue);
+ }
+
+ QImage rendering(400, 200, QImage::Format_ARGB32);
+ {
+ const char *const src = R"src(
+ <svg width="20" height="80">
+ <g transform="translate(-100,-100)">
+ <path d="m 110,180 v -80 h 10 v 40 h -20 v 40 z" fill="blue" />
+ </g>
+ </svg>
+ )src";
+ const QByteArray data(src);
+ QSvgRenderer rend(data);
+ rendering.fill(Qt::transparent);
+ QPainter p(&rendering);
+ rend.render(&p, QRectF(100, 50, 200, 100));
+ }
+
+ QCOMPARE(reference, rendering);
+}
+
void tst_QSvgRenderer::constructorQXmlStreamReader() const
{
const QByteArray data(src);