diff options
author | Suneel BS <suneel.b-s@nokia.com> | 2009-05-08 07:02:52 (GMT) |
---|---|---|
committer | Kim Motoyoshi Kalland <kim.kalland@nokia.com> | 2009-06-22 13:26:15 (GMT) |
commit | 6e057c7fce3718bcefc8ccae645aa3c377c7c587 (patch) | |
tree | 2bd717568ed35d19dc8459a34e13c923b9c86950 /src/svg/qsvghandler.cpp | |
parent | 2dcb97ff789dd7a9b7534348ca49c96c09783055 (diff) | |
download | Qt-6e057c7fce3718bcefc8ccae645aa3c377c7c587.zip Qt-6e057c7fce3718bcefc8ccae645aa3c377c7c587.tar.gz Qt-6e057c7fce3718bcefc8ccae645aa3c377c7c587.tar.bz2 |
Clamped opacity to the range [0, 1] in the SVG module.
Modified and autotest added by Kim.
Reviewed-by: Kim
Diffstat (limited to 'src/svg/qsvghandler.cpp')
-rw-r--r-- | src/svg/qsvghandler.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index e2c1312..8185fc6 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -497,10 +497,8 @@ static bool constructColor(const QString &colorStr, const QString &opacity, if (!resolveColor(colorStr, color, handler)) return false; if (!opacity.isEmpty()) { - qreal op = toDouble(opacity); - if (op <= 1) - op *= 255; - color.setAlpha(int(op)); + qreal op = qMin(qreal(1.0), qMax(qreal(0.0), toDouble(opacity))); + color.setAlphaF(op); } return true; } @@ -644,8 +642,10 @@ static void parseBrush(QSvgNode *node, QSvgStyleProperty *style = styleFromUrl(node, value); if (style) { QSvgFillStyle *prop = new QSvgFillStyle(style); - if (!opacity.isEmpty()) - prop->setFillOpacity(toDouble(opacity)); + if (!opacity.isEmpty()) { + qreal clampedOpacity = qMin(qreal(1.0), qMax(qreal(0.0), toDouble(opacity))); + prop->setFillOpacity(clampedOpacity); + } node->appendStyleProperty(prop, myId); } else { qWarning("Couldn't resolve property: %s", qPrintable(idFromUrl(value))); @@ -1943,7 +1943,7 @@ static void parseOpacity(QSvgNode *node, qreal op = value.toDouble(&ok); if (ok) { - QSvgOpacityStyle *opacity = new QSvgOpacityStyle(op); + QSvgOpacityStyle *opacity = new QSvgOpacityStyle(qMin(qreal(1.0), qMax(qreal(0.0), op))); node->appendStyleProperty(opacity, someId(attributes)); } } |