[calligra] libs/kotext/styles: Don't remove to much on removeDuplicates.

Thorsten Zachmann t.zachmann at zagge.de
Sat Mar 24 06:12:11 GMT 2012


Git commit a5ee384ae82995461d89fe623c714405f8948e00 by Thorsten Zachmann.
Committed on 24/03/2012 at 07:01.
Pushed by zachmann into branch 'master'.

Don't remove to much on removeDuplicates.

When the font-familiy is set after the removing of duplicates also keep the
properties font-pitch, font-family-generic and font-charset as these are only
evaluated if there is a font-family on the same style level.

BUG: 296667

Please review so I can backport to 2.4 branch.

Roundtrip tested with my odp and odt test set.

CCMAIL: calligra-devel at kde.org

M  +22   -5    libs/kotext/styles/KoCharacterStyle.cpp

http://commits.kde.org/calligra/a5ee384ae82995461d89fe623c714405f8948e00

diff --git a/libs/kotext/styles/KoCharacterStyle.cpp b/libs/kotext/styles/KoCharacterStyle.cpp
index 115d6b4..6021dde 100644
--- a/libs/kotext/styles/KoCharacterStyle.cpp
+++ b/libs/kotext/styles/KoCharacterStyle.cpp
@@ -485,7 +485,6 @@ void KoCharacterStyle::applyStyle(QTextCharFormat &format) const
             else if (it.key() == KoCharacterStyle::UseWindowFontColor) {
                 clearProperty.append(QTextFormat::ForegroundBrush);
             }
-
         }
         ++it;
     }
@@ -1915,16 +1914,34 @@ void KoCharacterStyle::removeDuplicates(const KoCharacterStyle &other)
     if (other.d->propertyBoolean(KoCharacterStyle::UseWindowFontColor) && !d->propertyBoolean(KoCharacterStyle::UseWindowFontColor)) {
         brush = foreground();
     }
+
+    // this properties should need to be kept if there is a font family defined as these are only evaluated if there is also a font family
+    int keepProperties[] = { QTextFormat::FontStyleHint, QTextFormat::FontFixedPitch, KoCharacterStyle::FontCharset };
+
+    QMap<int, QVariant> keep;
+    for (unsigned int i = 0; i < sizeof(keepProperties); ++i) {
+        if (hasProperty(keepProperties[i])) {
+            keep.insert(keepProperties[i], value(keepProperties[i]));
+        }
+    }
     this->d->stylesPrivate.removeDuplicates(other.d->stylesPrivate);
     if (brush.style() != Qt::NoBrush) {
         setForeground(brush);
     }
+
     // in case the char style has any of the following properties it also needs to have the fontFamily as otherwise 
     // these values will be ignored when loading according to the odf spec
-    if (!hasProperty(QTextFormat::FontFamily) && (hasProperty(QTextFormat::FontStyleHint) || hasProperty(QTextFormat::FontFixedPitch) || hasProperty(KoCharacterStyle::FontCharset))) {
-        QString fontFamily = other.fontFamily();
-        if (!fontFamily.isEmpty()) {
-            setFontFamily(fontFamily);
+    if (!hasProperty(QTextFormat::FontFamily)) {
+        if (hasProperty(QTextFormat::FontStyleHint) || hasProperty(QTextFormat::FontFixedPitch) || hasProperty(KoCharacterStyle::FontCharset)) {
+            QString fontFamily = other.fontFamily();
+            if (!fontFamily.isEmpty()) {
+                setFontFamily(fontFamily);
+            }
+        }
+    }
+    else {
+        for (QMap<int, QVariant>::const_iterator it(keep.constBegin()); it != keep.constEnd(); ++it) {
+            this->d->stylesPrivate.add(it.key(), it.value());
         }
     }
 }



More information about the calligra-devel mailing list