diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2019-05-24 13:40:31 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2019-05-24 15:21:05 +0200 |
commit | 14fa4591eb34a35cf3d485fd901e3f1e2caa7770 (patch) | |
tree | 892b767206e6d44513c1a01390fe504c66098e68 /tests/auto | |
parent | 357a5bd4d6682a50d85c88ba485ed34c745fae85 (diff) | |
download | qtsvg-14fa4591eb34a35cf3d485fd901e3f1e2caa7770.tar.gz |
Fix rendering of SVGs with viewBoxes
The presence of the viewBox attribute in the svg tag implies the
presence of the preserveAspectRatio attribute as well. It defaults to
scaling the view box to the view port while preserving the aspect ratio
and the box is also centered.
This patch does not implement the full preserveAspectRatio attribute,
but it does implement the default of aspect ratio preservation and
centering, as that is what caused the rendering error in the linked
task.
This causes some tests in the SVG Tiny 1.2 test suite to differ. This is
visible using the rendertestsuite helper program (see other change).
In particular it corrects the rendering of struct-svg-203-t.svg to
correctly center the text and avoid scaling it.
For animate-elem-38-t.svg the rendering improved by making the entire
text visible, as in the reference. The same applies to
media-video-216-t.svg. In both rendering the scaling changes slightly.
Done-With: Rainer Keller <rainer.keller@qt.io>
Fixes: QTBUG-70256
Change-Id: I9142c511890765993ee3e316f0383550919fdcd4
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp index e0646f2..cf19213 100644 --- a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp +++ b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp @@ -268,6 +268,16 @@ void tst_QSvgRenderer::testMapViewBoxToTarget() QCOMPARE(picture.boundingRect(), QRect(125, 125, 250, 250)); } + { // Viewport and viewBox specified -> scale 500x500 square to 1000x750 while preserving aspect ratio gives 750x750 + // however the box is centered at 375, 250 + data = "<svg width=\"1000\" height=\"750\" viewBox=\"-250 -250 500 500\"><g><rect x=\"0\" y=\"0\" width=\"500\" height=\"500\" /></g></svg>"; + QPicture picture; + QPainter painter(&picture); + QSvgRenderer rend(data); + rend.render(&painter); + painter.end(); + QCOMPARE(picture.boundingRect(), QRect(375, 250, 750, 750)); + } } void tst_QSvgRenderer::testRenderElement() |