summaryrefslogtreecommitdiffstats
path: root/src/svg
diff options
context:
space:
mode:
authorKim Motoyoshi Kalland <kim.kalland@nokia.com>2009-07-20 13:49:15 (GMT)
committerKim Motoyoshi Kalland <kim.kalland@nokia.com>2009-07-21 13:54:46 (GMT)
commit40649c420601bcc1f639fc8b337bfd7375d2b37e (patch)
treeb192a98aea146c084fee0a17588702028237d8c6 /src/svg
parent3c2ebb7f209035f85a35dbb05e76dd7e80238ecb (diff)
downloadQt-40649c420601bcc1f639fc8b337bfd7375d2b37e.zip
Qt-40649c420601bcc1f639fc8b337bfd7375d2b37e.tar.gz
Qt-40649c420601bcc1f639fc8b337bfd7375d2b37e.tar.bz2
Fixed inheritence of SVG 'use' element fill attributes.
Inheritence of fill attributes was implemented by copying attributes from the parent node. This approach wouldn't work if the node is referenced by a 'use' element. Now, only the fill attributes which have been explicitly set are applied on the painter while drawing. Reviewed-by: Tor Arne
Diffstat (limited to 'src/svg')
-rw-r--r--src/svg/qsvghandler.cpp25
-rw-r--r--src/svg/qsvgstyle.cpp38
-rw-r--r--src/svg/qsvgstyle_p.h1
3 files changed, 36 insertions, 28 deletions
diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp
index 5f9d1dd..5857e1c 100644
--- a/src/svg/qsvghandler.cpp
+++ b/src/svg/qsvghandler.cpp
@@ -644,26 +644,19 @@ static void parseBrush(QSvgNode *node,
QString opacity = attributes.value(QLatin1String("fill-opacity")).toString();
QString myId = someId(attributes);
- QSvgFillStyle *inherited =
- static_cast<QSvgFillStyle*>(node->parent()->styleProperty(
- QSvgStyleProperty::FILL));
- QSvgFillStyle *prop = new QSvgFillStyle(QColor(Qt::black));
+ QSvgFillStyle *prop = new QSvgFillStyle(0);
//fill-rule attribute handling
- Qt::FillRule f = Qt::WindingFill;
if (!fillRule.isEmpty() && fillRule != QLatin1String("inherit")) {
if (fillRule == QLatin1String("evenodd"))
- f = Qt::OddEvenFill;
- } else if (inherited) {
- f = inherited->fillRule();
+ prop->setFillRule(Qt::OddEvenFill);
+ else if (fillRule == QLatin1String("nonzero"))
+ prop->setFillRule(Qt::WindingFill);
}
//fill-opacity atttribute handling
- qreal fillOpacity = 1.0;
if (!opacity.isEmpty() && opacity != QLatin1String("inherit")) {
- fillOpacity = qMin(qreal(1.0), qMax(qreal(0.0), toDouble(opacity)));
- } else if (inherited) {
- fillOpacity = inherited->fillOpacity();
+ prop->setFillOpacity(qMin(qreal(1.0), qMax(qreal(0.0), toDouble(opacity))));
}
//fill attribute handling
@@ -685,15 +678,7 @@ static void parseBrush(QSvgNode *node,
} else {
prop->setBrush(QBrush(Qt::NoBrush));
}
- } else if (inherited) {
- if (inherited->style()) {
- prop->setFillStyle(inherited->style());
- } else {
- prop->setBrush(inherited->qbrush());
- }
}
- prop->setFillOpacity(fillOpacity);
- prop->setFillRule(f);
node->appendStyleProperty(prop,myId);
}
diff --git a/src/svg/qsvgstyle.cpp b/src/svg/qsvgstyle.cpp
index b693429..c3c0a68 100644
--- a/src/svg/qsvgstyle.cpp
+++ b/src/svg/qsvgstyle.cpp
@@ -81,12 +81,25 @@ void QSvgQualityStyle::revert(QPainter *, QSvgExtraStates &)
}
QSvgFillStyle::QSvgFillStyle(const QBrush &brush)
- : m_fill(brush), m_style(0), m_fillRuleSet(false), m_fillRule(Qt::WindingFill), m_fillOpacitySet(false), m_fillOpacity(1.0), m_gradientResolved (true)
+ : m_fill(brush)
+ , m_style(0)
+ , m_fillRuleSet(false)
+ , m_fillRule(Qt::WindingFill)
+ , m_fillOpacitySet(false)
+ , m_fillOpacity(1.0)
+ , m_gradientResolved(true)
+ , m_fillSet(true)
{
}
QSvgFillStyle::QSvgFillStyle(QSvgStyleProperty *style)
- : m_style(style), m_fillRuleSet(false), m_fillRule(Qt::WindingFill), m_fillOpacitySet(false), m_fillOpacity(1.0), m_gradientResolved (true)
+ : m_style(style)
+ , m_fillRuleSet(false)
+ , m_fillRule(Qt::WindingFill)
+ , m_fillOpacitySet(false)
+ , m_fillOpacity(1.0)
+ , m_gradientResolved(true)
+ , m_fillSet(style != 0)
{
}
@@ -105,11 +118,14 @@ void QSvgFillStyle::setFillOpacity(qreal opacity)
void QSvgFillStyle::setFillStyle(QSvgStyleProperty* style)
{
m_style = style;
+ m_fillSet = true;
}
void QSvgFillStyle::setBrush(QBrush brush)
{
m_fill = brush;
+ m_style = 0;
+ m_fillSet = true;
}
static void recursivelySetFill(QSvgNode *node, Qt::FillRule f)
@@ -136,20 +152,26 @@ void QSvgFillStyle::apply(QPainter *p, const QRectF &rect, QSvgNode *node, QSvgE
recursivelySetFill(node, m_fillRule);
m_fillRuleSet = false;//set it only on the first run
}
- p->setBrush(m_fill);
+ if (m_fillSet) {
+ if (m_style)
+ m_style->apply(p, rect, node, states);
+ else
+ p->setBrush(m_fill);
+ }
if (m_fillOpacitySet)
states.fillOpacity = m_fillOpacity;
- if (m_style)
- m_style->apply(p, rect, node, states);
}
void QSvgFillStyle::revert(QPainter *p, QSvgExtraStates &states)
{
- if (m_style)
- m_style->revert(p, states);
- p->setBrush(m_oldFill);
if (m_fillOpacitySet)
states.fillOpacity = m_oldOpacity;
+ if (m_fillSet) {
+ if (m_style)
+ m_style->revert(p, states);
+ else
+ p->setBrush(m_oldFill);
+ }
}
QSvgViewportFillStyle::QSvgViewportFillStyle(const QBrush &brush)
diff --git a/src/svg/qsvgstyle_p.h b/src/svg/qsvgstyle_p.h
index ac5e109..70ecf5b 100644
--- a/src/svg/qsvgstyle_p.h
+++ b/src/svg/qsvgstyle_p.h
@@ -281,6 +281,7 @@ private:
qreal m_oldOpacity;
QString m_gradientId;
bool m_gradientResolved;
+ bool m_fillSet;
};
class QSvgViewportFillStyle : public QSvgStyleProperty