From d180cb47b147ca07874b7defe1ed2771d5cb73fc Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Fri, 19 Nov 2021 07:32:05 +0100 Subject: Fix boundsOnElement() for text nodes having transformations Text layout calculations are done with a local scaling, and that was mixed up with the node transformation when computing the bounds. Fixes: QTBUG-98139 Pick-to: 6.2 Change-Id: Id3ab0500cfba4578989b5766677a53340e8cecde Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/svg/qsvggraphics.cpp | 4 ++-- tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/svg/qsvggraphics.cpp b/src/svg/qsvggraphics.cpp index bc4f9d6..764c21e 100644 --- a/src/svg/qsvggraphics.cpp +++ b/src/svg/qsvggraphics.cpp @@ -289,7 +289,7 @@ QRectF QSvgText::bounds(QPainter *p, QSvgExtraStates &states) const { QRectF boundingRect; draw_helper(p, states, &boundingRect); - return boundingRect; + return p->transform().mapRect(boundingRect); } void QSvgText::draw(QPainter *p, QSvgExtraStates &states) @@ -465,7 +465,7 @@ void QSvgText::draw_helper(QPainter *p, QSvgExtraStates &states, QRectF *boundin brect.translate(m_coord * scale); if (bounds.height() > 0) brect.setBottom(qMin(brect.bottom(), bounds.bottom())); - *boundingRect = p->transform().mapRect(brect); + *boundingRect = QTransform::fromScale(1 / scale, 1 / scale).mapRect(brect); } } diff --git a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp index e368444..fca52ea 100644 --- a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp +++ b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp @@ -599,6 +599,8 @@ void tst_QSvgRenderer::boundsOnElement() const "" "" "" + "Lorem ipsum" + "Lorem ipsum" ""); qreal sqrt2 = qSqrt(2); @@ -610,6 +612,10 @@ void tst_QSvgRenderer::boundsOnElement() const QCOMPARE(renderer.boundsOnElement(QLatin1String("baconost")), QRectF(-10 * sqrt2, -10 * sqrt2, 20 * sqrt2, 20 * sqrt2)); QCOMPARE(renderer.boundsOnElement(QLatin1String("hapaa")), QRectF(-13, -9, 22, 22)); QCOMPARE(renderer.boundsOnElement(QLatin1String("prim")), QRectF(-10 * sqrt2 - 3, -10 * sqrt2 + 1, 20 * sqrt2, 20 * sqrt2)); + + QRectF textBoundsA = renderer.boundsOnElement(QLatin1String("textA")); + QVERIFY(!textBoundsA.isEmpty()); + QCOMPARE(renderer.boundsOnElement(QLatin1String("textB")), textBoundsA); } void tst_QSvgRenderer::gradientStops() const -- cgit v1.2.1