[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [calligra/calligra/2.5] libs: fix parsing and writing of style:shadow value
From: Friedrich W. H. Kossebau <kossebau () kde ! org>
Date: 2012-07-18 15:33:19
Message-ID: 20120718153319.67919A60A6 () git ! kde ! org
[Download RAW message or body]
Git commit 6d9504c7785eade01593cae5579a811fe34c25ad by Friedrich W. H. Kossebau.
Committed on 18/07/2012 at 17:12.
Pushed by kossebau into branch 'calligra/2.5'.
fix parsing and writing of style:shadow value
* also allow color at end
* do not write invalid color
REVIEW: 105606
thanks boemann and thorsten for review
M +2 -1 libs/kotext/styles/tests/TestOpenDocumentStyle.cpp
M +42 -19 libs/odf/KoShadowStyle.cpp
http://commits.kde.org/calligra/6d9504c7785eade01593cae5579a811fe34c25ad
diff --git a/libs/kotext/styles/tests/TestOpenDocumentStyle.cpp \
b/libs/kotext/styles/tests/TestOpenDocumentStyle.cpp index d67bfc8..69ddc55 100644
--- a/libs/kotext/styles/tests/TestOpenDocumentStyle.cpp
+++ b/libs/kotext/styles/tests/TestOpenDocumentStyle.cpp
@@ -211,7 +211,8 @@ QStringList Attribute::listValuesFromNode(const QDomElement \
&m_node) } else if (reference == "relativeLength") {
result << "42*";
} else if (reference == "shadowType") {
- result << "none" << "red" << "#fff 1px 2pt 3pt" << "4pt 3px" /* is this \
one valid ? */ << "white 42px 23pt, red -3pt -5px 3px" << "red -3pt -5px"; + \
result << "none" << "red" << "#fff 1px 2pt 3pt" << "4pt 3px" << "2pt 4pt blue" + \
<< "white 42px 23pt, red -3pt -5px 3px" << "red -3pt -5px"; } else if (reference == \
"color") { result << "#ABCDEF" << "#0a1234";
} else if (reference == "positiveInteger") {
diff --git a/libs/odf/KoShadowStyle.cpp b/libs/odf/KoShadowStyle.cpp
index c12ee92..801116c 100644
--- a/libs/odf/KoShadowStyle.cpp
+++ b/libs/odf/KoShadowStyle.cpp
@@ -86,36 +86,50 @@ bool KoShadowStyle::operator!=(const KoShadowStyle &other) const
return !operator==(other);
}
+// load value string as specified by CSS2 §7.16.5 "text-shadow"
bool KoShadowStyle::loadOdf (const QString &data)
{
- if (data == "none")
+ if (data == QLatin1String("none"))
return true;
+
QList<KoShadowStyle::ShadowData> shadow_datas;
- QStringList sub_shadows = data.split(',');
- foreach (QString shadow, sub_shadows) {
- QStringList words = shadow.split(' ', QString::SkipEmptyParts);
- if (words.length() == 0)
+ const QStringList sub_shadows = data.split(QLatin1Char(','));
+ foreach (const QString &shadow, sub_shadows) {
+ QStringList words = shadow.split(QLatin1Char(' '), QString::SkipEmptyParts);
+ if (words.isEmpty())
return false;
KoShadowStyle::ShadowData currentData;
- QColor shadowColor(words[0]);
+
+ // look for color at begin
+ QColor shadowColor(words.first());
if (shadowColor.isValid()) {
currentData.color = shadowColor;
words.removeFirst();
- } else {
- // We keep an invalid color.
+ } else if (words.length() > 2) {
+ // look for color at end, if there could be one
+ shadowColor = QColor(words.last());
+ if (shadowColor.isValid()) {
+ currentData.color = shadowColor;
+ words.removeLast();
+ }
}
+ // We keep an invalid color.if none was found
- if (words.length() > 0) {
+ // "Each shadow effect must specify a shadow offset and may optionally
+ // specify a blur radius and a shadow color.", from CSS2 §7.16.5 \
"text-shadow" + // But for some reason also no offset has been accepted \
before. TODO: which? + if (! words.isEmpty()) {
if ((words.length() < 2) || (words.length() > 3))
return false;
- // Parse the 2/3 lengths
- currentData.offset.setX(KoUnit::parseValue(words[0], 0.0));
- currentData.offset.setY(KoUnit::parseValue(words[1], 0.0));
+ // Parse offset
+ currentData.offset.setX(KoUnit::parseValue(words.at(0), 0.0));
+ currentData.offset.setY(KoUnit::parseValue(words.at(1), 0.0));
+ // Parse blur radius if present
if (words.length() == 3)
- currentData.radius = KoUnit::parseValue(words[2], 0.0);
+ currentData.radius = KoUnit::parseValue(words.at(2), 0.0);
}
d->shadows << currentData;
}
@@ -129,13 +143,22 @@ int KoShadowStyle::shadowCount() const
QString KoShadowStyle::saveOdf() const
{
+ if (d->shadows.isEmpty())
+ return QLatin1String("none");
+
QStringList parts;
- foreach (ShadowData data, d->shadows) {
- QString part = QString("%1 %2pt %3pt \
%4pt").arg(data.color.name()).arg(data.offset.x()).arg(data.offset.y()).arg(data.radius);
- parts << part;
+ const QString pt = QLatin1String("%1pt");
+ foreach (const ShadowData &data, d->shadows) {
+ QStringList elements;
+ if (data.color.isValid()) {
+ elements << data.color.name();
+ }
+ elements << pt.arg(data.offset.x()) << pt.arg(data.offset.y());
+ if (data.radius != 0)
+ elements << pt.arg(data.radius);
+
+ parts << elements.join(QLatin1String(" "));
}
- if (parts.isEmpty())
- return "none";
- return parts.join(",");
+ return parts.join(QLatin1String(","));
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic