From 3e2823a147b2dca492fece187facfe39f4d33bed Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Thu, 9 Jan 2020 11:03:44 +0100 Subject: Revert the keep-aspectratio feature for 5.14.1 This was introduced as non-optional behavior for 5.14.0, but caused many regressions. This patch reverts that, and instead prepares for introducing it as an opt-in feature in Qt 5.15. [ChangeLog][QSVGRenderer] In Qt 5.14.0, rendering would keep aspect ratio implied by the viewbox, independently of the specified target area. This caused many regressions with existing code, so is reverted now in 5.14.1. The feature will instead be available as an opt-in in Qt 5.15. Task-number: QTBUG-81259 Change-Id: I3efa2db864eb80ee00e8a067e56d9912bab36442 Reviewed-by: Eirik Aavitsland --- src/svg/qsvgtinydocument.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/svg/qsvgtinydocument.cpp') diff --git a/src/svg/qsvgtinydocument.cpp b/src/svg/qsvgtinydocument.cpp index 173baaa..0877e41 100644 --- a/src/svg/qsvgtinydocument.cpp +++ b/src/svg/qsvgtinydocument.cpp @@ -420,10 +420,10 @@ void QSvgTinyDocument::mapSourceToTarget(QPainter *p, const QRectF &targetRect, source = viewBox(); if (source != target && !source.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), - // or when user has given explicit target bounds that overrides viebox aspect ratio +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + if (m_implicitViewBox || !preserveAspectRatio()) { + // Code path used when no view box is set, or IgnoreAspectRatio requested +#endif QTransform transform; transform.scale(target.width() / source.width(), target.height() / source.height()); @@ -432,10 +432,10 @@ void QSvgTinyDocument::mapSourceToTarget(QPainter *p, const QRectF &targetRect, target.y() - c2.y()); p->scale(target.width() / source.width(), target.height() / source.height()); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) } else { - // Code path used when a view box is specified and we're not rendering a specific element by id - // but the entire document. This attempts to emulate the default values of the - // tag that's implicitly defined when is used. + // Code path used when KeepAspectRatio is requested. This attempts to emulate the default values + // of the is used. // Scale the view box into the view port (target) by preserve the aspect ratio. QSizeF viewBoxSize = source.size(); @@ -451,6 +451,7 @@ void QSvgTinyDocument::mapSourceToTarget(QPainter *p, const QRectF &targetRect, // Apply the view box translation if specified. p->translate(-source.x(), -source.y()); } +#endif } } -- cgit v1.2.1 From 84bc219fb1e9f586c1f7ac2c10172c4da2605f96 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Mon, 27 Jan 2020 14:22:19 +0100 Subject: Add API to enable opt-in aspect ratio feature in QSvgRenderer [ChangeLog][QSvgRenderer] Introduced aspect ratio mode property, so that rendering may be set to preserve the view box aspect ratio. Task-number: QTBUG-81259 Change-Id: I9802788cdaf2c30974c1ffc34ad5b67cdc74ed57 Reviewed-by: Simon Hausmann --- src/svg/qsvgtinydocument.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/svg/qsvgtinydocument.cpp') diff --git a/src/svg/qsvgtinydocument.cpp b/src/svg/qsvgtinydocument.cpp index 8f6aac1..b4b9526 100644 --- a/src/svg/qsvgtinydocument.cpp +++ b/src/svg/qsvgtinydocument.cpp @@ -336,6 +336,11 @@ void QSvgTinyDocument::setHeight(int len, bool percent) m_heightPercent = percent; } +void QSvgTinyDocument::setPreserveAspectRatio(bool on) +{ + m_preserveAspectRatio = on; +} + void QSvgTinyDocument::setViewBox(const QRectF &rect) { m_viewBox = rect; -- cgit v1.2.1