diff options
author | Kim Motoyoshi Kalland <kim.kalland@nokia.com> | 2009-04-03 08:47:07 (GMT) |
---|---|---|
committer | Kim Motoyoshi Kalland <kim.kalland@nokia.com> | 2009-04-03 09:50:06 (GMT) |
commit | 6c2dd295b2ca2f9125fe072d035a3784ce748718 (patch) | |
tree | 565f5ba97690df7891a598c699e50e741444911e /src | |
parent | d684546573785ce40fb5de2b8b3aad88e9958709 (diff) | |
download | Qt-6c2dd295b2ca2f9125fe072d035a3784ce748718.zip Qt-6c2dd295b2ca2f9125fe072d035a3784ce748718.tar.gz Qt-6c2dd295b2ca2f9125fe072d035a3784ce748718.tar.bz2 |
Removed usage of NaN in SVG gradients.
Since there is no way to find out if gradient stops have been added to a
gradient, a gradient stop at NaN was earlier used in the SVG module to
mark the gradient as empty. This could cause floating point exceptions.
The usage of NaN has now been replaced by a boolean in
QSvgGradientStyle.
Duplicate entry "qxmlpatterns" was removed from auto.pro in the auto
test directory.
Task-number: 250146
Reviewed-by: Samuel
Diffstat (limited to 'src')
-rw-r--r-- | src/svg/qsvghandler.cpp | 12 | ||||
-rw-r--r-- | src/svg/qsvgstyle.cpp | 13 | ||||
-rw-r--r-- | src/svg/qsvgstyle_p.h | 11 |
3 files changed, 21 insertions, 15 deletions
diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index 56dab5f..18ba71c 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -2649,7 +2649,6 @@ static QSvgStyleProperty *createLinearGradientNode(QSvgNode *node, } QLinearGradient *grad = new QLinearGradient(nx1, ny1, nx2, ny2); - grad->setColorAt(qQNaN(), QColor()); grad->setInterpolationMode(QGradient::ComponentInterpolation); QSvgGradientStyle *prop = new QSvgGradientStyle(grad); parseBaseGradient(node, attributes, prop, handler); @@ -2783,7 +2782,6 @@ static QSvgStyleProperty *createRadialGradientNode(QSvgNode *node, nfy = toDouble(fy); QRadialGradient *grad = new QRadialGradient(ncx, ncy, nr, nfx, nfy); - grad->setColorAt(qQNaN(), QColor()); grad->setInterpolationMode(QGradient::ComponentInterpolation); QSvgGradientStyle *prop = new QSvgGradientStyle(grad); @@ -2929,12 +2927,9 @@ static bool parseStopNode(QSvgStyleProperty *parent, QGradient *grad = style->qgradient(); offset = qMin(qreal(1), qMax(qreal(0), offset)); // Clamp to range [0, 1] - QGradientStops stops = grad->stops(); - // Check if the gradient is marked as empty (marked with one single stop at NaN). - if ((stops.size() == 1) && qIsNaN(stops.at(0).first)) { - stops.clear(); - grad->setStops(stops); - } else { + QGradientStops stops; + if (style->gradientStopsSet()) { + stops = grad->stops(); // If the stop offset equals the one previously added, add an epsilon to make it greater. if (offset <= stops.back().first) offset = stops.back().first + FLT_EPSILON; @@ -2950,6 +2945,7 @@ static bool parseStopNode(QSvgStyleProperty *parent, } grad->setColorAt(offset, color); + style->setGradientStopsSet(true); if (!colorOK) style->addResolve(offset); return true; diff --git a/src/svg/qsvgstyle.cpp b/src/svg/qsvgstyle.cpp index 389f68f..4a40bed 100644 --- a/src/svg/qsvgstyle.cpp +++ b/src/svg/qsvgstyle.cpp @@ -231,7 +231,7 @@ void QSvgSolidColorStyle::revert(QPainter *p, QSvgExtraStates &) } QSvgGradientStyle::QSvgGradientStyle(QGradient *grad) - : m_gradient(grad) + : m_gradient(grad), m_gradientStopsSet(false) { } @@ -256,14 +256,13 @@ void QSvgGradientStyle::apply(QPainter *p, const QRectF &/*rect*/, QSvgNode *, Q } // If the gradient is marked as empty, insert transparent black - QGradientStops stops = m_gradient->stops(); - if (stops.size() == 1 && qIsNaN(stops.at(0).first)) - m_gradient->setStops(QGradientStops() << QGradientStop(0.0, QColor(0, 0, 0, 0))); - - QGradient gradient = *m_gradient; + if (!m_gradientStopsSet) { + m_gradient->setColorAt(0.0, QColor(0, 0, 0, 0)); + m_gradientStopsSet = true; + } QBrush brush; - brush = QBrush(gradient); + brush = QBrush(*m_gradient); if (!m_matrix.isIdentity()) brush.setMatrix(m_matrix); diff --git a/src/svg/qsvgstyle_p.h b/src/svg/qsvgstyle_p.h index ff4058b..058ba35 100644 --- a/src/svg/qsvgstyle_p.h +++ b/src/svg/qsvgstyle_p.h @@ -376,6 +376,16 @@ public: } void addResolve(qreal offset); + + bool gradientStopsSet() const + { + return m_gradientStopsSet; + } + + void setGradientStopsSet(bool set) + { + m_gradientStopsSet = set; + } private: QGradient *m_gradient; QList<qreal> m_resolvePoints; @@ -386,6 +396,7 @@ private: QSvgTinyDocument *m_doc; QString m_link; + bool m_gradientStopsSet; }; class QSvgTransformStyle : public QSvgStyleProperty |