diff options
Diffstat (limited to 'src/svg/qsvghandler.cpp')
-rw-r--r-- | src/svg/qsvghandler.cpp | 215 |
1 files changed, 107 insertions, 108 deletions
diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index e730eed..677dc97 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -195,112 +195,6 @@ struct QSvgAttributes QSvgAttributes::QSvgAttributes(const QXmlStreamAttributes &xmlAttributes, QSvgHandler *handler) { -#ifndef QT_NO_CSSPARSER - QStringView style = xmlAttributes.value(QLatin1String("style")); - if (!style.isEmpty()) { - handler->parseCSStoXMLAttrs(style.toString(), &m_cssAttributes); - for (int j = 0; j < m_cssAttributes.count(); ++j) { - const QSvgCssAttribute &attribute = m_cssAttributes.at(j); - QStringView name = attribute.name; - QStringView value = attribute.value; - if (name.isEmpty()) - continue; - - switch (name.at(0).unicode()) { - - case 'c': - if (name == QLatin1String("color")) - color = value; - else if (name == QLatin1String("color-opacity")) - colorOpacity = value; - else if (name == QLatin1String("comp-op")) - compOp = value; - break; - - case 'd': - if (name == QLatin1String("display")) - display = value; - break; - - case 'f': - if (name == QLatin1String("fill")) - fill = value; - else if (name == QLatin1String("fill-rule")) - fillRule = value; - else if (name == QLatin1String("fill-opacity")) - fillOpacity = value; - else if (name == QLatin1String("font-family")) - fontFamily = value; - else if (name == QLatin1String("font-size")) - fontSize = value; - else if (name == QLatin1String("font-style")) - fontStyle = value; - else if (name == QLatin1String("font-weight")) - fontWeight = value; - else if (name == QLatin1String("font-variant")) - fontVariant = value; - break; - case 'i': - if (name == QLatin1String("image-rendering")) - imageRendering = value; - break; - - case 'o': - if (name == QLatin1String("opacity")) - opacity = value; - else if (name == QLatin1String("offset")) - offset = value; - break; - - case 's': - if (name.length() > 5 && name.mid(1, 5) == QLatin1String("troke")) { - QStringView strokeRef = name.mid(6, name.length() - 6); - if (strokeRef.isEmpty()) - stroke = value; - else if (strokeRef == QLatin1String("-dasharray")) - strokeDashArray = value; - else if (strokeRef == QLatin1String("-dashoffset")) - strokeDashOffset = value; - else if (strokeRef == QLatin1String("-linecap")) - strokeLineCap = value; - else if (strokeRef == QLatin1String("-linejoin")) - strokeLineJoin = value; - else if (strokeRef == QLatin1String("-miterlimit")) - strokeMiterLimit = value; - else if (strokeRef == QLatin1String("-opacity")) - strokeOpacity = value; - else if (strokeRef == QLatin1String("-width")) - strokeWidth = value; - } - else if (name == QLatin1String("stop-color")) - stopColor = value; - else if (name == QLatin1String("stop-opacity")) - stopOpacity = value; - break; - - case 't': - if (name == QLatin1String("text-anchor")) - textAnchor = value; - else if (name == QLatin1String("transform")) - transform = value; - break; - - case 'v': - if (name == QLatin1String("vector-effect")) - vectorEffect = value; - else if (name == QLatin1String("visibility")) - visibility = value; - break; - - default: - break; - } - } - } -#else - Q_UNUSED(handler); -#endif // QT_NO_CSSPARSER - for (int i = 0; i < xmlAttributes.count(); ++i) { const QXmlStreamAttribute &attribute = xmlAttributes.at(i); QStringView name = attribute.qualifiedName(); @@ -376,8 +270,7 @@ QSvgAttributes::QSvgAttributes(const QXmlStreamAttributes &xmlAttributes, QSvgHa strokeOpacity = value; else if (strokeRef == QLatin1String("-width")) strokeWidth = value; - } - else if (name == QLatin1String("stop-color")) + } else if (name == QLatin1String("stop-color")) stopColor = value; else if (name == QLatin1String("stop-opacity")) stopOpacity = value; @@ -407,6 +300,112 @@ QSvgAttributes::QSvgAttributes(const QXmlStreamAttributes &xmlAttributes, QSvgHa } } + // If a style attribute is present, let its attribute settings override the plain attribute + // values. The spec seems to indicate that, and it is common behavior in svg renderers. +#ifndef QT_NO_CSSPARSER + QStringView style = xmlAttributes.value(QLatin1String("style")); + if (!style.isEmpty()) { + handler->parseCSStoXMLAttrs(style.toString(), &m_cssAttributes); + for (int j = 0; j < m_cssAttributes.count(); ++j) { + const QSvgCssAttribute &attribute = m_cssAttributes.at(j); + QStringView name = attribute.name; + QStringView value = attribute.value; + if (name.isEmpty()) + continue; + + switch (name.at(0).unicode()) { + + case 'c': + if (name == QLatin1String("color")) + color = value; + else if (name == QLatin1String("color-opacity")) + colorOpacity = value; + else if (name == QLatin1String("comp-op")) + compOp = value; + break; + + case 'd': + if (name == QLatin1String("display")) + display = value; + break; + + case 'f': + if (name == QLatin1String("fill")) + fill = value; + else if (name == QLatin1String("fill-rule")) + fillRule = value; + else if (name == QLatin1String("fill-opacity")) + fillOpacity = value; + else if (name == QLatin1String("font-family")) + fontFamily = value; + else if (name == QLatin1String("font-size")) + fontSize = value; + else if (name == QLatin1String("font-style")) + fontStyle = value; + else if (name == QLatin1String("font-weight")) + fontWeight = value; + else if (name == QLatin1String("font-variant")) + fontVariant = value; + break; + case 'i': + if (name == QLatin1String("image-rendering")) + imageRendering = value; + break; + + case 'o': + if (name == QLatin1String("opacity")) + opacity = value; + else if (name == QLatin1String("offset")) + offset = value; + break; + + case 's': + if (name.length() > 5 && name.mid(1, 5) == QLatin1String("troke")) { + QStringView strokeRef = name.mid(6, name.length() - 6); + if (strokeRef.isEmpty()) + stroke = value; + else if (strokeRef == QLatin1String("-dasharray")) + strokeDashArray = value; + else if (strokeRef == QLatin1String("-dashoffset")) + strokeDashOffset = value; + else if (strokeRef == QLatin1String("-linecap")) + strokeLineCap = value; + else if (strokeRef == QLatin1String("-linejoin")) + strokeLineJoin = value; + else if (strokeRef == QLatin1String("-miterlimit")) + strokeMiterLimit = value; + else if (strokeRef == QLatin1String("-opacity")) + strokeOpacity = value; + else if (strokeRef == QLatin1String("-width")) + strokeWidth = value; + } else if (name == QLatin1String("stop-color")) + stopColor = value; + else if (name == QLatin1String("stop-opacity")) + stopOpacity = value; + break; + + case 't': + if (name == QLatin1String("text-anchor")) + textAnchor = value; + else if (name == QLatin1String("transform")) + transform = value; + break; + + case 'v': + if (name == QLatin1String("vector-effect")) + vectorEffect = value; + else if (name == QLatin1String("visibility")) + visibility = value; + break; + + default: + break; + } + } + } +#else + Q_UNUSED(handler); +#endif // QT_NO_CSSPARSER } #ifndef QT_NO_CSSPARSER |