Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Fix ordering issue of application of remove and insert text properties
Dmitry Kazakov48ff40b0248a
diff --git a/libs/flake/commands/KoShapeMergeTextPropertiesCommand.cpp b/libs/flake/commands/KoShapeMergeTextPropertiesCommand.cppindex a88068a181..45f6fef733 100644--- a/libs/flake/commands/KoShapeMergeTextPropertiesCommand.cpp+++ b/libs/flake/commands/KoShapeMergeTextPropertiesCommand.cpp@@ -67,15 +67,22 @@ bool KoShapeMergeTextPropertiesCommand::mergeWith(const KUndo2Command *other)return false;}+ /**+ * The merging algorithm should follow the ordering of+ * KoSvgTextShape::mergePropertiesIntoRange, that is, firstly,+ * the properties in @p removeProperties list are removed,+ * then properties in @p properties are applied. If the property is+ * present in both lists, then the value from @p properties is used.+ */+Q_FOREACH(KoSvgTextProperties::PropertyId p, command->d->removeProperties) {d->newProperties.removeProperty(p);d->removeProperties.insert(p);}+Q_FOREACH(KoSvgTextProperties::PropertyId p, command->d->newProperties.properties()) {- if (!command->d->removeProperties.contains(p)) {- d->newProperties.setProperty(p, command->d->newProperties.property(p));- d->removeProperties.remove(p);- }+ d->newProperties.setProperty(p, command->d->newProperties.property(p));+ d->removeProperties.remove(p);}return true;diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cppindex 5e13059bf2..53d36cc2f2 100644--- a/libs/flake/text/KoSvgTextShape.cpp+++ b/libs/flake/text/KoSvgTextShape.cpp@@ -952,13 +952,6 @@ void KoSvgTextShape::mergePropertiesIntoRange(const int startPos,}if (currentIndex >= startIndex && currentIndex < endIndex) {- Q_FOREACH(KoSvgTextProperties::PropertyId p, properties.properties()) {- if (KoSvgTextProperties::propertyIsBlockOnly(p) || (p == KoSvgTextProperties::TextAnchorId && isWrapping)) {- d->textData.childBegin()->properties.setProperty(p, properties.property(p));- } else {- it->properties.setProperty(p, properties.property(p));- }- }Q_FOREACH(KoSvgTextProperties::PropertyId p, removeProperties) {if (KoSvgTextProperties::propertyIsBlockOnly(p)) {d->textData.childBegin()->properties.removeProperty(p);@@ -966,6 +959,13 @@ void KoSvgTextShape::mergePropertiesIntoRange(const int startPos,it->properties.removeProperty(p);}}+ Q_FOREACH(KoSvgTextProperties::PropertyId p, properties.properties()) {+ if (KoSvgTextProperties::propertyIsBlockOnly(p) || (p == KoSvgTextProperties::TextAnchorId && isWrapping)) {+ d->textData.childBegin()->properties.setProperty(p, properties.property(p));+ } else {+ it->properties.setProperty(p, properties.property(p));+ }+ }changed = true;}diff --git a/libs/flake/text/KoSvgTextShape.h b/libs/flake/text/KoSvgTextShape.hindex a2478ab87b..28499b7c1f 100644--- a/libs/flake/text/KoSvgTextShape.h+++ b/libs/flake/text/KoSvgTextShape.h@@ -338,6 +338,11 @@ public:* Merge given properties into the given range. This will first split* the nodes at the two range ends, and then merge in the properties* into each leaf node. Won't do anything when startPos == endPos+ *+ * First, the properties in @p removeProperties list will be removed,+ * then properties in @p properties will be applied. If the property is+ * present in both lists, then the value from @p properties will be used.+ ** @param startPos -- cursor pos start.* @param endPos -- cursor pos end.* @param properties -- properties to merge in.diff --git a/plugins/tools/svgtexttool/SvgTextMergePropertiesRangeCommand.cpp b/plugins/tools/svgtexttool/SvgTextMergePropertiesRangeCommand.cppindex 3dce2a5c6f..d46825d02d 100644--- a/plugins/tools/svgtexttool/SvgTextMergePropertiesRangeCommand.cpp+++ b/plugins/tools/svgtexttool/SvgTextMergePropertiesRangeCommand.cpp@@ -58,16 +58,22 @@ bool SvgTextMergePropertiesRangeCommand::mergeWith(const KUndo2Command *other)return false;}+ /**+ * The merging algorithm should follow the ordering of+ * KoSvgTextShape::mergePropertiesIntoRange, that is, firstly,+ * the properties in @p removeProperties list are removed,+ * then properties in @p properties are applied. If the property is+ * present in both lists, then the value from @p properties is used.+ */+Q_FOREACH(KoSvgTextProperties::PropertyId p, command->m_removeProperties) {m_props.removeProperty(p);m_removeProperties.insert(p);}Q_FOREACH(KoSvgTextProperties::PropertyId p, command->m_props.properties()) {- if (!command->m_removeProperties.contains(p)) {- m_props.setProperty(p, command->m_props.property(p));- m_removeProperties.remove(p);- }+ m_props.setProperty(p, command->m_props.property(p));+ m_removeProperties.remove(p);}return true;