aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2025-04-02 12:49:59 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2025-04-09 17:12:15 +0000
commite323618c49ece669f494c5278a51b4dad0de9469 (patch)
tree118bd0fd09e7cc53b16b431c5cb3029ef01bafa2
parent69f652ea5da37ed26202e1ba690266f0676eb7c8 (diff)
vectorimage: Fix identical gradient stops in qml generator
In SVG, two subsequent identical gradient stops means a hard transition to the color of the second at that position. However, this is not the case in Qt and because of the way we sort the gradient stops, the order of the two identical stops will be wrong. This is addressed by adding an epsilon to identical stops in Qt Svg, but the epsilon is FLT_EPSILON, which is around 1e-7. The default output precision for doubles in Qt is 6, so when storing the numbers to file, the epsilon would be lost, the two positions would be considered identical and the reordering would happen. This caused a visual error when running svgtoqml on the paint-grad-16-t.svg test. Change-Id: I857958512c3de7dc843a705893b4c2d7d2a36fd4 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io> (cherry picked from commit 67d685eed9219deca960716cec2a4dfb085c5c62) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 20eb817ba2bcf38e28dc94591f048da8867beb40)
-rw-r--r--src/quickvectorimage/generator/qquickqmlgenerator.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/quickvectorimage/generator/qquickqmlgenerator.cpp b/src/quickvectorimage/generator/qquickqmlgenerator.cpp
index c9c94c34a3..2607a9bdb0 100644
--- a/src/quickvectorimage/generator/qquickqmlgenerator.cpp
+++ b/src/quickvectorimage/generator/qquickqmlgenerator.cpp
@@ -191,7 +191,8 @@ void QQuickQmlGenerator::generateGradient(const QGradient *grad)
stream() << "x2: " << gradRect.right();
stream() << "y2: " << gradRect.bottom();
for (auto &stop : linGrad->stops())
- stream() << "GradientStop { position: " << stop.first << "; color: \"" << stop.second.name(QColor::HexArgb) << "\" }";
+ stream() << "GradientStop { position: " << QString::number(stop.first, 'g', 7)
+ << "; color: \"" << stop.second.name(QColor::HexArgb) << "\" }";
m_indentLevel--;
stream() << "}";
} else if (grad->type() == QGradient::RadialGradient) {
@@ -205,7 +206,8 @@ void QQuickQmlGenerator::generateGradient(const QGradient *grad)
stream() << "focalX:" << radGrad->focalPoint().x();
stream() << "focalY:" << radGrad->focalPoint().y();
for (auto &stop : radGrad->stops())
- stream() << "GradientStop { position: " << stop.first << "; color: \"" << stop.second.name(QColor::HexArgb) << "\" }";
+ stream() << "GradientStop { position: " << QString::number(stop.first, 'g', 7)
+ << "; color: \"" << stop.second.name(QColor::HexArgb) << "\" }";
m_indentLevel--;
stream() << "}";
}