Commit f2c09bd3 authored by Thorsten Zachmann's avatar Thorsten Zachmann

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@kde.org
parent 54e5d3a2
......@@ -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());
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment