summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2020-01-07 03:03:20 +0100
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2020-01-07 03:03:20 +0100
commit2f58f925cc16946a474f066c739c4682246afa0f (patch)
tree0ba495f8a83eba922c0eb8226cf8bdde05c6dbfb
parentbf173000d90a718d4a4c36fd1f8ceb5720ff87ac (diff)
parentacb66cad2280bda20d26d08d606a66b9660b17aa (diff)
downloadqtsvg-2f58f925cc16946a474f066c739c4682246afa0f.tar.gz
Merge remote-tracking branch 'origin/5.14' into 5.15
Change-Id: If6bf34ca3216ab9e0866d8c4eea7c4e92a7f3f4d
-rw-r--r--src/svg/qsvgrenderer.cpp8
-rw-r--r--src/svg/qsvgtinydocument.cpp12
-rw-r--r--tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp31
3 files changed, 41 insertions, 10 deletions
diff --git a/src/svg/qsvgrenderer.cpp b/src/svg/qsvgrenderer.cpp
index d4ad373..da31a31 100644
--- a/src/svg/qsvgrenderer.cpp
+++ b/src/svg/qsvgrenderer.cpp
@@ -401,10 +401,10 @@ void QSvgRenderer::render(QPainter *painter, const QString &elementId,
}
/*!
- Renders the current document, or the current frame of an animated
- document, using the given \a painter on the specified \a bounds within
- the painter. If the bounding rectangle is not specified
- the SVG file is mapped to the whole paint device.
+ Renders the current document, or the current frame of an animated document,
+ using the given \a painter on the specified \a bounds within the painter.
+ If \a bounds is not empty, the output will be scaled to fill it, ignoring
+ any aspect ratio implied by the SVG.
*/
void QSvgRenderer::render(QPainter *painter, const QRectF &bounds)
{
diff --git a/src/svg/qsvgtinydocument.cpp b/src/svg/qsvgtinydocument.cpp
index 56960bf..173baaa 100644
--- a/src/svg/qsvgtinydocument.cpp
+++ b/src/svg/qsvgtinydocument.cpp
@@ -420,9 +420,10 @@ void QSvgTinyDocument::mapSourceToTarget(QPainter *p, const QRectF &targetRect,
source = viewBox();
if (source != target && !source.isNull()) {
- if (m_implicitViewBox || !sourceRect.isNull()) {
+ if (m_implicitViewBox || !sourceRect.isNull() || !targetRect.isNull()) {
// Code path used when no view box is set, or when an explicit source size is given which
- // overrides it (which is the case when we're rendering only a specific element by id).
+ // overrides it (which is the case when we're rendering only a specific element by id),
+ // or when user has given explicit target bounds that overrides viebox aspect ratio
QTransform transform;
transform.scale(target.width() / source.width(),
target.height() / source.height());
@@ -441,15 +442,14 @@ void QSvgTinyDocument::mapSourceToTarget(QPainter *p, const QRectF &targetRect,
viewBoxSize.scale(target.width(), target.height(), Qt::KeepAspectRatio);
// Center the view box in the view port
- p->translate((target.width() - viewBoxSize.width()) / 2,
- (target.height() - viewBoxSize.height()) / 2);
+ p->translate(target.x() + (target.width() - viewBoxSize.width()) / 2,
+ target.y() + (target.height() - viewBoxSize.height()) / 2);
p->scale(viewBoxSize.width() / source.width(),
viewBoxSize.height() / source.height());
// Apply the view box translation if specified.
- p->translate(target.x() - source.x(),
- target.y() - source.y());
+ p->translate(-source.x(), -source.y());
}
}
}
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);