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++
Make text conversion commands also remove any text contours if they are unecessary.
Wolthera van Hövell tot Westerflierb980709824d2
diff --git a/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.cpp b/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.cppindex b693861c17..ca32c3df45 100644--- a/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.cpp+++ b/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.cpp@@ -15,7 +15,6 @@ struct KoSvgTextAddRemoveShapeCommandImpl::Private {Private(KoSvgTextShape *_text, KoShape *_shape, int _startPos, int _endPos): textShape(_text), shape(_shape)- , memento(textShape->getMemento()), startPos(_startPos), endPos(_endPos){@@ -40,10 +39,6 @@ KoSvgTextAddRemoveShapeCommandImpl::KoSvgTextAddRemoveShapeCommandImpl(KoSvgText{d->removeCommand = state == FINALIZING;- if (!d->removeCommand) {- d->originalShapeParent = shape->parent();- }-if (type == Unknown) {if (d->textShape->shapesInside().contains(shape)) {d->type = Inside;@@ -53,15 +48,14 @@ KoSvgTextAddRemoveShapeCommandImpl::KoSvgTextAddRemoveShapeCommandImpl(KoSvgTextd->type = TextPath;KoSvgTextNodeIndex idx = textShape->nodeForTextPath(shape);QPair<int, int> range = textShape->findRangeForNodeIndex(idx);- startPos = range.first;- endPos = range.second;+ d->startPos = range.first;+ d->endPos = range.second;} else {d->type = Unknown;}} else {d->type = type;}- d->oldTextPaths = d->textShape->textPathsAtRange(startPos, endPos);}KoSvgTextAddRemoveShapeCommandImpl::~KoSvgTextAddRemoveShapeCommandImpl()@@ -72,6 +66,10 @@ KoSvgTextAddRemoveShapeCommandImpl::~KoSvgTextAddRemoveShapeCommandImpl()// Remove shape from text.void KoSvgTextAddRemoveShapeCommandImpl::partB(){+ if (d->removeCommand) {+ d->memento = d->textShape->getMemento();+ d->oldTextPaths = d->textShape->textPathsAtRange(d->startPos, d->endPos);+ }QRectF updateRectText = d->textShape->boundingRect();QRectF updateRectShape = d->shape->boundingRect();@@ -107,6 +105,11 @@ void KoSvgTextAddRemoveShapeCommandImpl::partB()// Add shape to text.void KoSvgTextAddRemoveShapeCommandImpl::partA(){+ if (!d->removeCommand) {+ d->memento = d->textShape->getMemento();+ d->oldTextPaths = d->textShape->textPathsAtRange(d->startPos, d->endPos);+ d->originalShapeParent = d->shape->parent();+ }QRectF updateRect = d->textShape->boundingRect();updateRect |= d->shape->boundingRect();@@ -168,6 +171,21 @@ KoSvgTextRemoveShapeCommand::~KoSvgTextRemoveShapeCommand()}+void KoSvgTextRemoveShapeCommand::removeContourShapesFromFlow(KoSvgTextShape *textShape, KUndo2Command *parent, bool textInShape, bool textPaths)+{+ QList<KoShape*> shapes;+ if (textInShape) {+ shapes.append(textShape->shapesInside());+ shapes.append(textShape->shapesSubtract());+ }+ if (textPaths) {+ shapes.append(textShape->textPathsAtRange(0, textShape->posForIndex(textShape->plainText().size())));+ }+ Q_FOREACH(KoShape *shape, shapes) {+ new KoSvgTextRemoveShapeCommand(textShape, shape, parent);+ }+}+KoSvgTextSetTextPathOnRangeCommand::KoSvgTextSetTextPathOnRangeCommand(KoSvgTextShape *textShape, KoShape *shape, int startPos, int endPos, KUndo2Command *parentCommand): KoSvgTextAddRemoveShapeCommandImpl(textShape, shape, TextPath, INITIALIZING, startPos, endPos, parentCommand){diff --git a/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.h b/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.hindex 44a6e52b45..46bc77398a 100644--- a/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.h+++ b/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.h@@ -42,6 +42,17 @@ class KRITAFLAKE_EXPORT KoSvgTextRemoveShapeCommand : public KoSvgTextAddRemoveSpublic:KoSvgTextRemoveShapeCommand(KoSvgTextShape *textShape, KoShape *shape, KUndo2Command *parentCommand = 0);~KoSvgTextRemoveShapeCommand();++ /**+ * @brief removeContourShapesFromFlow+ * Create a command to remove all contour shapes of a certain type from the flow+ * and add the command to the parent.+ * @param textShape -- textShape to work on.+ * @param parent -- parentCommand to add remove commands to.+ * @param textInShape -- remove all text-in-shape shapeInside and ShapeSubtract shapes.+ * @param textPaths -- remove all text paths.+ */+ static void removeContourShapesFromFlow(KoSvgTextShape *textShape, KUndo2Command *parent, bool textInShape, bool textPaths);};class KRITAFLAKE_EXPORT KoSvgTextSetTextPathOnRangeCommand : public KoSvgTextAddRemoveShapeCommandImpl {diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cppindex af5c3d7d26..4c0157c009 100644--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp@@ -548,6 +548,7 @@ void DefaultTool::slotChangeTextType(int index)convertableShape = true;parentCommand->setText(cmd->text());}+ KoSvgTextRemoveShapeCommand::removeContourShapesFromFlow(textShape, parentCommand, textShape->textType() == KoSvgTextShape::TextInShape, type == KoSvgTextShape::InlineWrap);}}@@ -581,6 +582,11 @@ void DefaultTool::slotAddShapesToFlow()KUndo2Command *parentCommand = new KUndo2Command(kundo2_i18n("Add shapes to text flow."));+ if (textShape->textType() != KoSvgTextShape::InlineWrap) {+ new KoSvgConvertTextTypeCommand(textShape, KoSvgTextShape::PreformattedText, 0, parentCommand);+ }+ KoSvgTextRemoveShapeCommand::removeContourShapesFromFlow(textShape, parentCommand, false, true);+new KoKeepShapesSelectedCommand(selectedShapes, {}, canvas()->selectedShapesProxy(), false, parentCommand);Q_FOREACH(KoShape *shape, shapes) {new KoSvgTextAddShapeCommand(textShape, shape, true, parentCommand);@@ -616,6 +622,11 @@ void DefaultTool::slotSubtractShapesFromFlow()KUndo2Command *parentCommand = new KUndo2Command(kundo2_i18n("Subtract shapes from text flow."));+ if (textShape->textType() == KoSvgTextShape::InlineWrap) {+ new KoSvgConvertTextTypeCommand(textShape, KoSvgTextShape::PreformattedText, 0, parentCommand);+ }+ KoSvgTextRemoveShapeCommand::removeContourShapesFromFlow(textShape, parentCommand, false, true);+new KoKeepShapesSelectedCommand(selectedShapes, {}, canvas()->selectedShapesProxy(), false, parentCommand);Q_FOREACH(KoShape *shape, shapes) {new KoSvgTextAddShapeCommand(textShape, shape, false, parentCommand);diff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cppindex 7e88d192a4..803c2712e2 100644--- a/plugins/tools/svgtexttool/SvgTextTool.cpp+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp@@ -26,6 +26,7 @@#include "SvgTextChangeTransformsOnRange.h"#include "SvgChangeTextPathInfoStrategy.h"#include "SvgChangeTextPaddingMarginStrategy.h"+#include <commands/KoSvgTextAddRemoveShapeCommands.h>#include <QPainterPath>#include <QDesktopServices>@@ -545,14 +546,18 @@ void SvgTextTool::slotUpdateCursorDecoration(QRectF updateRect)}void SvgTextTool::slotConvertType(int index) {- if (selectedShape()) {- if (index == selectedShape()->textType()) return;+ KoSvgTextShape *shape = selectedShape();+ if (shape) {+ if (index == shape->textType()) return;KoSvgTextShape::TextType type = KoSvgTextShape::TextType(index);KUndo2Command *parentCommand = new KUndo2Command();- new KoKeepShapesSelectedCommand({selectedShape()}, {}, canvas()->selectedShapesProxy(), KisCommandUtils::FlipFlopCommand::State::INITIALIZING, parentCommand);- KoSvgConvertTextTypeCommand *cmd = new KoSvgConvertTextTypeCommand(selectedShape(), type, m_textCursor.getPos(), parentCommand);+ new KoKeepShapesSelectedCommand({shape}, {}, canvas()->selectedShapesProxy(),+ KisCommandUtils::FlipFlopCommand::State::INITIALIZING, parentCommand);+ KoSvgConvertTextTypeCommand *cmd = new KoSvgConvertTextTypeCommand(shape, type, m_textCursor.getPos(), parentCommand);parentCommand->setText(cmd->text());- new KoKeepShapesSelectedCommand({}, {selectedShape()}, canvas()->selectedShapesProxy(), KisCommandUtils::FlipFlopCommand::State::FINALIZING, parentCommand);+ KoSvgTextRemoveShapeCommand::removeContourShapesFromFlow(shape, parentCommand, shape->textType() == KoSvgTextShape::TextInShape, type == KoSvgTextShape::InlineWrap);+ new KoKeepShapesSelectedCommand({}, {shape}, canvas()->selectedShapesProxy(),+ KisCommandUtils::FlipFlopCommand::State::FINALIZING, parentCommand);canvas()->addCommand(parentCommand);slotTextTypeUpdated();}