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 put-text-on-path command to work properly with rtl and end-anchors.
Wolthera van Hövell tot Westerflier0b374289b8d1
diff --git a/libs/flake/CMakeLists.txt b/libs/flake/CMakeLists.txtindex f607626df0..c15deee716 100644--- a/libs/flake/CMakeLists.txt+++ b/libs/flake/CMakeLists.txt@@ -162,6 +162,7 @@ set(kritaflake_SRCScommands/KoSvgTextAddRemoveShapeCommands.cppcommands/KoSvgTextReorderShapeInsideCommand.cppcommands/KoSvgTextFlipShapeContourTypeCommand.cpp+ commands/KoSvgTextPathInfoChangeCommand.cpphtml/HtmlSavingContext.cpphtml/HtmlWriter.cppdiff --git a/plugins/tools/svgtexttool/SvgTextPathInfoChangeCommand.cpp b/libs/flake/commands/KoSvgTextPathInfoChangeCommand.cppsimilarity index 78%rename from plugins/tools/svgtexttool/SvgTextPathInfoChangeCommand.cpprename to libs/flake/commands/KoSvgTextPathInfoChangeCommand.cppindex f21312eb49..a2eb769e1e 100644--- a/plugins/tools/svgtexttool/SvgTextPathInfoChangeCommand.cpp+++ b/libs/flake/commands/KoSvgTextPathInfoChangeCommand.cpp@@ -3,11 +3,11 @@** SPDX-License-Identifier: GPL-3.0-or-later*/-#include "SvgTextPathInfoChangeCommand.h"+#include "KoSvgTextPathInfoChangeCommand.h"#include "kis_command_ids.h"#include <KoShapeBulkActionLock.h>-SvgTextPathInfoChangeCommand::SvgTextPathInfoChangeCommand(KoSvgTextShape *shape, int pos, KoSvgText::TextOnPathInfo textPathInfo, KUndo2Command *parent)+KoSvgTextPathInfoChangeCommand::KoSvgTextPathInfoChangeCommand(KoSvgTextShape *shape, int pos, KoSvgText::TextOnPathInfo textPathInfo, KUndo2Command *parent): KUndo2Command(parent), m_shape(shape), m_textData(shape->getMemento())@@ -17,7 +17,7 @@ SvgTextPathInfoChangeCommand::SvgTextPathInfoChangeCommand(KoSvgTextShape *shapesetText(kundo2_i18n("Change Text On Path Properties"));}-void SvgTextPathInfoChangeCommand::redo()+void KoSvgTextPathInfoChangeCommand::redo(){KoShapeBulkActionLock lock(m_shape);KoSvgTextNodeIndex index = m_shape->topLevelNodeForPos(m_pos);@@ -42,21 +42,21 @@ void SvgTextPathInfoChangeCommand::redo()m_shape->notifyCursorPosChanged(m_pos, m_pos);}-void SvgTextPathInfoChangeCommand::undo()+void KoSvgTextPathInfoChangeCommand::undo(){KoShapeBulkActionLock lock(m_shape);m_shape->setMemento(m_textData, m_pos, m_pos);KoShapeBulkActionLock::bulkShapesUpdate(lock.unlock());}-int SvgTextPathInfoChangeCommand::id() const+int KoSvgTextPathInfoChangeCommand::id() const{return KisCommandUtils::SvgTextPathInfoChangeCommandId;}-bool SvgTextPathInfoChangeCommand::mergeWith(const KUndo2Command *other)+bool KoSvgTextPathInfoChangeCommand::mergeWith(const KUndo2Command *other){- const SvgTextPathInfoChangeCommand *command = dynamic_cast<const SvgTextPathInfoChangeCommand*>(other);+ const KoSvgTextPathInfoChangeCommand *command = dynamic_cast<const KoSvgTextPathInfoChangeCommand*>(other);if (!command || command->m_shape != m_shape || m_pos != command->m_pos) {return false;diff --git a/plugins/tools/svgtexttool/SvgTextPathInfoChangeCommand.h b/libs/flake/commands/KoSvgTextPathInfoChangeCommand.hsimilarity index 71%rename from plugins/tools/svgtexttool/SvgTextPathInfoChangeCommand.hrename to libs/flake/commands/KoSvgTextPathInfoChangeCommand.hindex f7aba3cf9d..404bf93de0 100644--- a/plugins/tools/svgtexttool/SvgTextPathInfoChangeCommand.h+++ b/libs/flake/commands/KoSvgTextPathInfoChangeCommand.h@@ -7,15 +7,15 @@#define SVGTEXTPATHINFOCHANGECOMMAND_H#include <kundo2command.h>-#include "kritatoolsvgtext_export.h"+#include "kritaflake_export.h"#include <KoSvgTextShape.h>#include <KoSvgText.h>-class KRITATOOLSVGTEXT_EXPORT SvgTextPathInfoChangeCommand : public KUndo2Command+class KRITAFLAKE_EXPORT KoSvgTextPathInfoChangeCommand : public KUndo2Command{public:- SvgTextPathInfoChangeCommand(KoSvgTextShape *shape, int pos, KoSvgText::TextOnPathInfo textPathInfo, KUndo2Command *parent = nullptr);+ KoSvgTextPathInfoChangeCommand(KoSvgTextShape *shape, int pos, KoSvgText::TextOnPathInfo textPathInfo, KUndo2Command *parent = nullptr);void redo() override;void undo() override;diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cppindex 8fe018ad07..6235e641c0 100644--- a/libs/flake/text/KoSvgTextShape.cpp+++ b/libs/flake/text/KoSvgTextShape.cpp@@ -1623,6 +1623,11 @@ KoSvgText::WritingMode KoSvgTextShape::writingMode() constreturn KoSvgText::WritingMode(this->textProperties().propertyOrDefault(KoSvgTextProperties::WritingModeId).toInt());}+KoSvgText::Direction KoSvgTextShape::direction() const+{+ return KoSvgText::Direction(this->textProperties().propertyOrDefault(KoSvgTextProperties::DirectionId).toInt());+}+bool KoSvgTextShape::singleNode() const{if (d->textData.empty()) return false;diff --git a/libs/flake/text/KoSvgTextShape.h b/libs/flake/text/KoSvgTextShape.hindex 93dc575cf9..901ff69744 100644--- a/libs/flake/text/KoSvgTextShape.h+++ b/libs/flake/text/KoSvgTextShape.h@@ -564,6 +564,13 @@ public:*/KoSvgText::WritingMode writingMode() const;+ /**+ * @brief direction+ * Whether the text is left to right or right to left.+ * @return the paragraph-direction of this text.+ */+ KoSvgText::Direction direction() const;+/*** @brief singleNode* Sometimes it is useful to know whether there's only a single text nodediff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cppindex eee278aa17..a9f6f36e2a 100644--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp@@ -45,6 +45,7 @@#include <commands/KoSvgTextAddRemoveShapeCommands.h>#include <commands/KoSvgTextFlipShapeContourTypeCommand.h>#include <commands/KoSvgTextReorderShapeInsideCommand.h>+#include <commands/KoSvgTextPathInfoChangeCommand.h>#include <KoSnapGuide.h>#include <KoStrokeConfigWidget.h>@@ -626,7 +627,7 @@ void DefaultTool::slotPutTextOnPath()KUndo2Command *parentCommand = new KUndo2Command(kundo2_i18n("Put Text On Path"));new KoKeepShapesSelectedCommand(selectedShapes, {}, canvas()->selectedShapesProxy(), false, parentCommand);- if (textShape->textType() != KoSvgTextShape::InlineWrap) {+ if (textShape->textType() != KoSvgTextShape::PreformattedText && textShape->textType() != KoSvgTextShape::PrePositionedText) {new KoSvgConvertTextTypeCommand(textShape, KoSvgTextShape::PreformattedText, 0, parentCommand);}@@ -637,6 +638,22 @@ void DefaultTool::slotPutTextOnPath()KoSvgTextRemoveShapeCommand::removeContourShapesFromFlow(textShape, parentCommand, true, true);new KoSvgTextSetTextPathOnRangeCommand(textShape, textPath, 0, textShape->posForIndex(textShape->plainText().size()), parentCommand);+ /// We need to adjust the startOffset by the anchor/direction, because otherwise the text might be largely off the path.+ /// This isn't a problem when using cursor to set it, as the cursor-pos can be the startOffset position.+ KoSvgText::TextAnchor anchor = KoSvgText::TextAnchor(textShape->textProperties().propertyOrDefault(KoSvgTextProperties::TextAnchorId).toInt());+ if ((textShape->direction() == KoSvgText::DirectionRightToLeft && anchor == KoSvgText::AnchorStart)+ || (textShape->direction() == KoSvgText::DirectionLeftToRight && anchor == KoSvgText::AnchorEnd)) {+ KoSvgText::TextOnPathInfo info;+ info.startOffset = 100.0;+ info.startOffsetIsPercentage = true;+ new KoSvgTextPathInfoChangeCommand(textShape, 0, info, parentCommand);+ } else if (anchor == KoSvgText::AnchorMiddle) {+ KoSvgText::TextOnPathInfo info;+ info.startOffset = 50.0;+ info.startOffsetIsPercentage = true;+ new KoSvgTextPathInfoChangeCommand(textShape, 0, info, parentCommand);+ }+new KoKeepShapesSelectedCommand({}, {textShape}, canvas()->selectedShapesProxy(), true, parentCommand);canvas()->addCommand(parentCommand);diff --git a/plugins/tools/svgtexttool/CMakeLists.txt b/plugins/tools/svgtexttool/CMakeLists.txtindex 223c5979db..1a74341924 100644--- a/plugins/tools/svgtexttool/CMakeLists.txt+++ b/plugins/tools/svgtexttool/CMakeLists.txt@@ -28,7 +28,6 @@ set (SvgTextTool_SRCSSvgTextChangeTransformsOnRange.cppSvgTextTypeSettingStrategy.cppSvgTextRemoveTransformsFromRange.cpp- SvgTextPathInfoChangeCommand.cppSvgChangeTextPathInfoStrategy.cppSvgTextOnPathDecorationHelper.cppSvgChangeTextPaddingMarginStrategy.cppdiff --git a/plugins/tools/svgtexttool/SvgChangeTextPathInfoStrategy.cpp b/plugins/tools/svgtexttool/SvgChangeTextPathInfoStrategy.cppindex 13ced9c52f..80af9ba8fe 100644--- a/plugins/tools/svgtexttool/SvgChangeTextPathInfoStrategy.cpp+++ b/plugins/tools/svgtexttool/SvgChangeTextPathInfoStrategy.cpp@@ -5,7 +5,7 @@*/#include "SvgChangeTextPathInfoStrategy.h"-#include "SvgTextPathInfoChangeCommand.h"+#include "KoSvgTextPathInfoChangeCommand.h"#include <KoPathSegment.h>#include <KoPathShape.h>#include <KoToolBase.h>@@ -84,14 +84,14 @@ KUndo2Command *SvgChangeTextPathInfoStrategy::createCommand()info.startOffset = length - info.startOffset;}- KUndo2Command *cmd = new SvgTextPathInfoChangeCommand(m_shape, m_textCursorPos, info);+ KUndo2Command *cmd = new KoSvgTextPathInfoChangeCommand(m_shape, m_textCursorPos, info);cmd->setText(kundo2_i18n("Change Text On Path Position"));return cmd;}void SvgChangeTextPathInfoStrategy::cancelInteraction(){- KUndo2Command *cmd = new SvgTextPathInfoChangeCommand(m_shape, m_textCursorPos, m_oldInfo);+ KUndo2Command *cmd = new KoSvgTextPathInfoChangeCommand(m_shape, m_textCursorPos, m_oldInfo);if (cmd) {cmd->undo();}diff --git a/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp b/plugins/tools/svgtexttool/SvgCreateTextStrategy.cppindex 4b72fc53ca..817497daff 100644--- a/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp+++ b/plugins/tools/svgtexttool/SvgCreateTextStrategy.cpp@@ -22,7 +22,7 @@#include "commands/KoKeepShapesSelectedCommand.h"#include "commands/KoShapeMoveCommand.h"#include "commands/KoSvgTextAddRemoveShapeCommands.h"-#include "SvgTextPathInfoChangeCommand.h"+#include "KoSvgTextPathInfoChangeCommand.h"#include "kis_global.h"#include "kundo2command.h"@@ -178,8 +178,7 @@ KUndo2Command *SvgCreateTextStrategy::createCommand()info.startOffset += s.length();qDebug() << info.startOffset << s.length();}- qDebug() << "setting path at..." << info.startOffset << segments.size();- new SvgTextPathInfoChangeCommand(textShape, 2, info, parentCommand);+ new KoSvgTextPathInfoChangeCommand(textShape, 2, info, parentCommand);} else {new KoSvgTextAddShapeCommand(textShape, m_flowShape, true, parentCommand);}