From a91a65632c4d830070e1ca9bbda7e355f1459414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Cr=C3=A9moux?= Date: Fri, 1 Feb 2019 11:54:25 +0300 Subject: Fix QSvgRenderer incorrect render of svg:image The bounds of QSvgImage are integer based (QRect) which cause rounding issues when decimals values are used to define image (image shifted and with incorrect size). Changing the bounds to QRectF solves the issue. Fixes: QTBUG-73445 Change-Id: I49828e2c0b1917ec878844d520aac182581c23fb Reviewed-by: Eirik Aavitsland --- src/svg/qsvggraphics.cpp | 10 +++++----- src/svg/qsvggraphics_p.h | 4 ++-- src/svg/qsvghandler.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/svg/qsvggraphics.cpp b/src/svg/qsvggraphics.cpp index 5b273af..12f2349 100644 --- a/src/svg/qsvggraphics.cpp +++ b/src/svg/qsvggraphics.cpp @@ -121,14 +121,14 @@ void QSvgArc::draw(QPainter *p, QSvgExtraStates &states) } QSvgImage::QSvgImage(QSvgNode *parent, const QImage &image, - const QRect &bounds) + const QRectF &bounds) : QSvgNode(parent), m_image(image), m_bounds(bounds) { - if (m_bounds.width() == 0) - m_bounds.setWidth(m_image.width()); - if (m_bounds.height() == 0) - m_bounds.setHeight(m_image.height()); + if (m_bounds.width() == 0.0) + m_bounds.setWidth(static_cast(m_image.width())); + if (m_bounds.height() == 0.0) + m_bounds.setHeight(static_cast(m_image.height())); } void QSvgImage::draw(QPainter *p, QSvgExtraStates &states) diff --git a/src/svg/qsvggraphics_p.h b/src/svg/qsvggraphics_p.h index 6e5b9d6..1138d1a 100644 --- a/src/svg/qsvggraphics_p.h +++ b/src/svg/qsvggraphics_p.h @@ -104,13 +104,13 @@ class Q_SVG_PRIVATE_EXPORT QSvgImage : public QSvgNode { public: QSvgImage(QSvgNode *parent, const QImage &image, - const QRect &bounds); + const QRectF &bounds); void draw(QPainter *p, QSvgExtraStates &states) override; Type type() const override; QRectF bounds(QPainter *p, QSvgExtraStates &states) const override; private: QImage m_image; - QRect m_bounds; + QRectF m_bounds; }; class Q_SVG_PRIVATE_EXPORT QSvgLine : public QSvgNode diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index 0468bbe..dd31965 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -2792,10 +2792,10 @@ static QSvgNode *createImageNode(QSvgNode *parent, QSvgNode *img = new QSvgImage(parent, image, - QRect(int(nx), - int(ny), - int(nwidth), - int(nheight))); + QRectF(nx, + ny, + nwidth, + nheight)); return img; } -- cgit v1.2.1