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++
Implement unittests for new text in shape commands.
Wolthera van Hövell tot Westerflier372801ac7918
diff --git a/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.cpp b/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.cppindex 041cab3d78..ecd6527274 100644--- a/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.cpp+++ b/libs/flake/commands/KoSvgTextAddRemoveShapeCommands.cpp@@ -18,8 +18,9 @@ struct KoSvgTextAddRemoveShapeCommandImpl::Private {}~Private() {}- KoSvgTextShape *textShape;- KoShape* shape;+ KoSvgTextShape *textShape = nullptr;+ KoShape* shape = nullptr;+ KoShapeContainer *originalShapeParent = nullptr;KoSvgTextShapeMementoSP memento;KoSvgTextAddRemoveShapeCommandImpl::ContourType type;bool removeCommand;@@ -29,6 +30,7 @@ KoSvgTextAddRemoveShapeCommandImpl::KoSvgTextAddRemoveShapeCommandImpl(KoSvgText: KisCommandUtils::FlipFlopCommand(state, parent), d(new Private(textShape, shape)){+ d->removeCommand = state == FINALIZING;if (type == Unknown) {if (d->textShape->shapesInside().contains(shape)) {d->type = Inside;@@ -49,36 +51,53 @@ KoSvgTextAddRemoveShapeCommandImpl::~KoSvgTextAddRemoveShapeCommandImpl()}+// Remove shape from text.void KoSvgTextAddRemoveShapeCommandImpl::partB(){- QRectF updateRect = d->textShape->boundingRect();- updateRect |= d->shape->boundingRect();+ QRectF updateRectText = d->textShape->boundingRect();+ QRectF updateRectShape = d->shape->boundingRect();++ // Because "applyAbsoluteTransformation" applies ontop of the local transform, we want to get the minimal transfor difference.+ QTransform removeFromAbsolute = d->originalShapeParent? d->originalShapeParent->absoluteTransformation() * d->shape->transformation(): d->shape->transformation();+ QTransform absoluteTf = (d->shape->absoluteTransformation()*removeFromAbsolute.inverted());+d->textShape->removeShapesFromContours({d->shape}, true);+if (!d->removeCommand) {d->textShape->setMemento(d->memento);+ d->shape->setParent(d->originalShapeParent);} else {d->textShape->relayout();}- updateRect |= d->textShape->boundingRect();- updateRect |= d->shape->boundingRect();- d->textShape->updateAbsolute(updateRect);- d->shape->updateAbsolute(updateRect);+ d->shape->applyAbsoluteTransformation(absoluteTf);+ updateRectText |= d->textShape->boundingRect();+ updateRectShape |= d->shape->boundingRect();+ d->textShape->updateAbsolute(updateRectText);+ d->shape->updateAbsolute(updateRectShape);}+// Add shape to text.void KoSvgTextAddRemoveShapeCommandImpl::partA(){QRectF updateRect = d->textShape->boundingRect();updateRect |= d->shape->boundingRect();+ if (!d->removeCommand) {+ d->originalShapeParent = d->shape->parent();+ }+ QTransform absoluteTf = (d->shape->absoluteTransformation()*d->shape->transformation().inverted()) * d->textShape->absoluteTransformation().inverted();+if (d->type == Inside) {d->textShape->addShapeContours({d->shape}, true);} else if (d->type == Subtract) {d->textShape->addShapeContours({d->shape}, false);- }+ } // TextPath is handled by setMemento.+if (d->removeCommand) {d->textShape->setMemento(d->memento);} else {d->textShape->relayout();}+ d->shape->applyAbsoluteTransformation(absoluteTf);updateRect |= d->textShape->boundingRect();updateRect |= d->shape->boundingRect();d->shape->updateAbsolute(updateRect);diff --git a/libs/flake/commands/KoSvgTextReorderShapeInsideCommand.cpp b/libs/flake/commands/KoSvgTextReorderShapeInsideCommand.cppindex 54d84b4bca..d9d3a9252d 100644--- a/libs/flake/commands/KoSvgTextReorderShapeInsideCommand.cpp+++ b/libs/flake/commands/KoSvgTextReorderShapeInsideCommand.cpp@@ -6,25 +6,33 @@#include "KoSvgTextReorderShapeInsideCommand.h"#include <KoSvgTextShape.h>+struct KoSvgTextReorderShapeInsideCommand::Private {- Private(KoSvgTextShape *_text, KoShape *_shape, KoSvgTextReorderShapeInsideCommand::MoveShapeType _type)+ Private(KoSvgTextShape *_text, QList<KoShape *> _shapes, KoSvgTextReorderShapeInsideCommand::MoveShapeType _type): textShape(_text), memento(textShape->getMemento())- , shape(_shape)+ , shapes(_shapes), type(_type){+ std::sort(shapes.begin(), shapes.end(), [this](KoShape *a, KoShape *b)+ {+ return this->textShape->shapesInside().indexOf(a) < this->textShape->shapesInside().indexOf(b);+ });+ Q_FOREACH(KoShape *shape, shapes) {+ oldIndices.append(textShape->shapesInside().indexOf(shape));+ }}KoSvgTextShape *textShape;KoSvgTextShapeMementoSP memento;- KoShape *shape;- int oldIndex = 0;+ QList<KoShape *> shapes;+ QList<int> oldIndices;KoSvgTextReorderShapeInsideCommand::MoveShapeType type;};-KoSvgTextReorderShapeInsideCommand::KoSvgTextReorderShapeInsideCommand(KoSvgTextShape *textShape, KoShape *shape, MoveShapeType type, KUndo2Command *parent)+KoSvgTextReorderShapeInsideCommand::KoSvgTextReorderShapeInsideCommand(KoSvgTextShape *textShape, QList<KoShape *> shapes, MoveShapeType type, KUndo2Command *parent): KUndo2Command(parent)- , d(new Private(textShape, shape, type))+ , d(new Private(textShape, shapes, type)){}@@ -38,19 +46,41 @@ void KoSvgTextReorderShapeInsideCommand::redo(){QRectF updateRect = d->textShape->boundingRect();- d->oldIndex = d->textShape->shapesInside().indexOf(d->shape);- int newIndex = d->oldIndex;- const int max = d->textShape->shapesInside().size();- if (d->type == MoveEarlier) {- newIndex = qMax(0, d->oldIndex - 1);- } else if (d->type == MoveLater) {- newIndex = qMin(max, d->oldIndex + 1);- } else if (d->type == BringToFront) {- newIndex = 0;- } else /*if (type == SendToBack)*/ {- newIndex = max;+ int newIndex = d->textShape->shapesInside().indexOf(d->shapes.first());+ const int max = (d->textShape->shapesInside().size() -1);+ if (d->type == MoveEarlier || d->type == BringToFront) {+ if (d->type == MoveEarlier) {+ newIndex = qMax(0, newIndex - 1);+ } else {+ newIndex = 0;+ }+ Q_FOREACH(KoShape *shape, d->shapes) {+ const int index = d->textShape->shapesInside().indexOf(shape);+ if (index == newIndex) continue;++ d->textShape->moveShapeInsideToIndex(shape, newIndex);+ newIndex += 1;+ }+ } else {+ if (d->type == MoveLater) {+ newIndex = qMin(max, newIndex + d->shapes.size());+ } else {+ newIndex = max;+ }+ auto end = std::make_reverse_iterator(d->shapes.begin());+ auto begin = std::make_reverse_iterator(d->shapes.end());+ for (auto it = begin; it != end; it++) {+ KoShape *shape = *it;++ const int index = d->textShape->shapesInside().indexOf(shape);+ if (index == newIndex) continue;+ if (newIndex < 0) continue;++ d->textShape->moveShapeInsideToIndex(shape, newIndex);+ newIndex -= 1;+ }}- d->textShape->moveShapeInsideToIndex(d->shape, newIndex);+updateRect |= d->textShape->boundingRect();d->textShape->updateAbsolute(updateRect);}@@ -58,7 +88,15 @@ void KoSvgTextReorderShapeInsideCommand::redo()void KoSvgTextReorderShapeInsideCommand::undo(){QRectF updateRect = d->textShape->boundingRect();- d->textShape->moveShapeInsideToIndex(d->shape, d->oldIndex);+ if (d->type == MoveEarlier || d->type == BringToFront) {+ for (int i = d->oldIndices.size() -1 ; i>= 0; i--) {+ d->textShape->moveShapeInsideToIndex(d->shapes.at(i), d->oldIndices.at(i));+ }+ } else {+ for (int i = 0; i< d->oldIndices.size(); i++) {+ d->textShape->moveShapeInsideToIndex(d->shapes.at(i), d->oldIndices.at(i));+ }+ }d->textShape->setMemento(d->memento);updateRect |= d->textShape->boundingRect();d->textShape->updateAbsolute(updateRect);diff --git a/libs/flake/commands/KoSvgTextReorderShapeInsideCommand.h b/libs/flake/commands/KoSvgTextReorderShapeInsideCommand.hindex 5dd5ac414c..87be6da8b2 100644--- a/libs/flake/commands/KoSvgTextReorderShapeInsideCommand.h+++ b/libs/flake/commands/KoSvgTextReorderShapeInsideCommand.h@@ -28,7 +28,7 @@ public:SendToBack};- KoSvgTextReorderShapeInsideCommand(KoSvgTextShape* textShape, KoShape *shape, MoveShapeType type, KUndo2Command *parent = nullptr);+ KoSvgTextReorderShapeInsideCommand(KoSvgTextShape* textShape, QList<KoShape*> shape, MoveShapeType type, KUndo2Command *parent = nullptr);~KoSvgTextReorderShapeInsideCommand();void redo() override;diff --git a/libs/flake/tests/CMakeLists.txt b/libs/flake/tests/CMakeLists.txtindex ed8317b464..f4b74bbb52 100644--- a/libs/flake/tests/CMakeLists.txt+++ b/libs/flake/tests/CMakeLists.txt@@ -29,6 +29,7 @@ kis_add_tests(TestSvgSavingContext.cppTestXsimdPainting.cppTestFontLibraryResourceUtils.cpp+ TestSvgTextShape.cppLINK_LIBRARIES kritaflake kritatestsdkNAME_PREFIX "libs-flake-"diff --git a/libs/flake/tests/TestSvgTextShape.cpp b/libs/flake/tests/TestSvgTextShape.cppnew file mode 100644index 0000000000..504e1366d6--- /dev/null+++ b/libs/flake/tests/TestSvgTextShape.cpp@@ -0,0 +1,316 @@+/*+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */++#include "TestSvgTextShape.h"++#include <kistest.h>+#include <KoSvgTextShape.h>+#include <KoShape.h>+#include <KoPathShape.h>+#include <KoShapeGroup.h>+#include <KoShapeManager.h>++#include <KoShapeRegistry.h>++#include <commands/KoSvgChangeTextContoursCommand.h>+#include <commands/KoSvgTextAddRemoveShapeCommands.h>+#include <commands/KoSvgTextFlipShapeContourTypeCommand.h>+#include <commands/KoSvgTextReorderShapeInsideCommand.h>+#include <commands/KoShapeSizeCommand.h>++// Quick function to get a rectangle.+KoShape *createRectangles() {+ KoShapeFactoryBase *base = KoShapeRegistry::instance()->get("RectangleShape");+ return base->createDefaultShape();+}++KoPathShape *createPolygon() {+ KoPathShape *p = new KoPathShape;+ p->moveTo(QPointF(0,0));+ p->lineTo(QPointF(0,100));+ p->lineTo(QPointF(100,100));+ p->lineTo(QPointF(100, 0));+ p->lineTo(QPointF(0,0));+ p->close();+ return p;+}++void TestSvgTextShape::testSetTextOnShape_data()+{+ QTest::addColumn<QTransform>("textTransform");+ QTest::addColumn<bool>("textHasParent");+ QTest::addColumn<int>("contourCount");+ QTest::addColumn<QTransform>("contourTransform");+ QTest::addColumn<bool>("contourHasParent");++ QTest::addRow("text and 1 contour") << QTransform() << false << 1 << QTransform() << false;+ QTest::addRow("text and 2 contours") << QTransform() << false << 2 << QTransform() << false;+ QTest::addRow("text and 1 contour + local transform") << QTransform() << false << 1 << QTransform::fromTranslate(20, 20) << false;+ QTest::addRow("text + local transform and 1 contour") << QTransform::fromTranslate(20, 20) << false << 1 << QTransform() << false;+ QTest::addRow("text + absolute transform and 1 contour") << QTransform() << true << 1 << QTransform() << false;+ QTest::addRow("text and 1 contour + absolute transform") << QTransform() << false << 1 << QTransform() << true;+}++void TestSvgTextShape::testSetTextOnShape()+{+ KoSvgTextShape *textShape = new KoSvgTextShape();+ textShape->insertText(0, "The quick brown fox jumps over the lazy dog.");+ QList<KoShape*> shapes;++ QFETCH(QTransform, textTransform);+ QFETCH(bool, textHasParent);+ QFETCH(int, contourCount);+ QFETCH(QTransform, contourTransform);+ QFETCH(bool, contourHasParent);++ KoShapeGroup *contourParentGroup = nullptr;+ if (contourHasParent) {+ contourParentGroup = new KoShapeGroup();+ contourParentGroup->setTransformation(QTransform::fromTranslate(10, 10));+ }++ textShape->setTransformation(textTransform);++ for (int i = 0; i < contourCount; i++) {+ KoPathShape *p = createPolygon();+ p->setTransformation(contourTransform);+ if (contourParentGroup) {+ p->setParent(contourParentGroup);+ }+ shapes.append(p);+ }++ bool inside = true;++ if (textHasParent) {+ KoShapeGroup *parentGroup = new KoShapeGroup();+ parentGroup->setTransformation(QTransform::fromTranslate(10, 10));+ textShape->setParent(parentGroup);+ }++ KUndo2Command *parentCommand = new KUndo2Command();++ QRectF textOutlineRect = textShape->outlineRect();+ QRectF textBoundingRect = textShape->boundingRect();++ QRectF shapeBoundingRect;+ QList<KoShape*> clonedShapes;+ Q_FOREACH(KoShape *shape, shapes) {+ shapeBoundingRect |= shape->boundingRect();+ KoShape *clone = shape->cloneShape();+ if (contourParentGroup) {+ clone->setParent(contourParentGroup);+ }+ clonedShapes.append(clone);+ new KoSvgTextAddShapeCommand(textShape, clone, inside, parentCommand);+ }++ parentCommand->redo();++ QVERIFY(textShape->boundingRect() == shapeBoundingRect);+ QVERIFY(textShape->boundingRect() != textBoundingRect);+ QVERIFY(textShape->outlineRect() != textOutlineRect);+ for (int i = 0; i< clonedShapes.size(); i++) {+ KoShape *contour = clonedShapes.at(i);+ KoShape *original = shapes.at(i);+ QVERIFY(contour->absoluteTransformation() == original->absoluteTransformation());+ }++ parentCommand->undo();+ QVERIFY(textShape->boundingRect() != shapeBoundingRect);+ QVERIFY(textShape->boundingRect() == textBoundingRect);+ QVERIFY(textShape->outlineRect() == textOutlineRect);++ for (int i = 0; i< clonedShapes.size(); i++) {+ KoShape *contour = clonedShapes.at(i);+ KoShape *original = shapes.at(i);+ QVERIFY(contour->parent() == original->parent());+ QVERIFY(contour->transformation() == original->transformation());+ QVERIFY(contour->absoluteTransformation() == original->absoluteTransformation());++ }++ // Don't understand how to test textAfter transform with contour transform???+}++void TestSvgTextShape::testRemoveShapeFromText()+{+ KoSvgTextShape *textShape = new KoSvgTextShape();+ textShape->insertText(0, "The quick brown fox jumps over the lazy dog.");+ QList<KoShape*> shapes;++ QTransform rotate;+ rotate.rotate(45);+ for (int i = 0; i < 3; i++) {+ KoShape *p = createPolygon();+ p->setTransformation(rotate*QTransform::fromTranslate(i*10, i*10));+ shapes.append(p);+ }+ textShape->setShapesInside(shapes);++ KUndo2Command *cmd = new KoSvgTextRemoveShapeCommand(textShape, shapes.last());++ cmd->redo();++ QVERIFY(!textShape->shapeInContours(shapes.last()));++ cmd->undo();++ QVERIFY(textShape->shapeInContours(shapes.last()));+}++void TestSvgTextShape::testSetSize_data()+{+ QTest::addColumn<QSizeF>("newSize");+ QTest::addColumn<int>("contourCount");+ QTest::addColumn<bool>("useParametric");++ QTest::addRow("smaller, 1 contour") << QSizeF(50, 50) << 1 << false;+ QTest::addRow("smaller, 2 contours") << QSizeF(50, 50) << 2 << false;+ QTest::addRow("bigger, 1 contour") << QSizeF(200, 200) << 1 << false;+ QTest::addRow("bigger, 2 contours") << QSizeF(200, 200) << 2 << false;+ QTest::addRow("smaller, 1 contour, parametric") << QSizeF(50, 50) << 1 << true;+ QTest::addRow("smaller, 2 contours, parametric") << QSizeF(50, 50) << 2 << true;+ QTest::addRow("bigger, 1 contour, parametric") << QSizeF(200, 200) << 1 << true;+ QTest::addRow("bigger, 2 contours, parametric") << QSizeF(200, 200) << 2 << true;+}++void TestSvgTextShape::testSetSize()+{+ QFETCH(QSizeF, newSize);+ QFETCH(int, contourCount);+ QFETCH(bool, useParametric);++ KoSvgTextShape *textShape = new KoSvgTextShape();+ textShape->insertText(0, "The quick brown fox jumps over the lazy dog.");+ QList<KoShape*> shapes;++ QTransform rotate;+ rotate.rotate(45);+ for (int i = 0; i < contourCount; i++) {+ KoShape *p = useParametric? createRectangles(): createPolygon();+ p->setTransformation(rotate*QTransform::fromTranslate(i*10, i*10));+ shapes.append(p);+ }++ textShape->setShapesInside(shapes);+ QList<KoShape*> tShapes = {textShape};++ QSizeF originalSize = textShape->size();+ KoShapeSizeCommand *cmd = new KoShapeSizeCommand(tShapes, {originalSize}, {newSize});++ cmd->redo();+ QVERIFY2(textShape->size() == newSize, QString("Sizes don't match, %1 x %2, expected %3 x %4")+ .arg(textShape->size().width()).arg(textShape->size().height())+ .arg(newSize.width()).arg(newSize.height()).toLatin1());++ cmd->undo();+ QVERIFY2(textShape->size() == originalSize, QString("Sizes don't match, %1 x %2, expected %3 x %4")+ .arg(textShape->size().width()).arg(textShape->size().height())+ .arg(originalSize.width()).arg(originalSize.height()).toLatin1());++}++void TestSvgTextShape::testToggleShapeType()+{+ KoSvgTextShape *textShape = new KoSvgTextShape();+ textShape->insertText(0, "The quick brown fox jumps over the lazy dog.");++ KoPathShape *shapeInside = createPolygon();+ KoPathShape *shapeSubtract = createPolygon();+ shapeSubtract->setTransformation(QTransform::fromTranslate(50, 50));+ textShape->addShapeContours({shapeInside}, true);+ textShape->addShapeContours({shapeSubtract}, false);+ KUndo2Command *parentCommand = new KUndo2Command();++ new KoSvgTextFlipShapeContourTypeCommand(textShape, shapeSubtract, parentCommand);+ new KoSvgTextFlipShapeContourTypeCommand(textShape, shapeInside, parentCommand);++ parentCommand->redo();++ QVERIFY(textShape->shapesInside().contains(shapeSubtract));+ QVERIFY(textShape->shapesSubtract().contains(shapeInside));++ parentCommand->undo();++ QVERIFY(textShape->shapesInside().contains(shapeInside));+ QVERIFY(textShape->shapesSubtract().contains(shapeSubtract));+}++void TestSvgTextShape::testReorderShapesInside_data()+{+ QTest::addColumn<int>("type");+ QTest::addColumn<int>("amount");++ QTest::addRow("BringToFront, 1 shape") << int(KoSvgTextReorderShapeInsideCommand::BringToFront) << 1;+ QTest::addRow("BringToFront, 2 shapes") << int(KoSvgTextReorderShapeInsideCommand::BringToFront) << 2;+ QTest::addRow("MoveEarlier, 1 shape") << int(KoSvgTextReorderShapeInsideCommand::MoveEarlier) << 1;+ QTest::addRow("MoveEarlier, 2 shapes") << int(KoSvgTextReorderShapeInsideCommand::MoveEarlier) << 2;+ QTest::addRow("MoveLater, 1 shape") << int(KoSvgTextReorderShapeInsideCommand::MoveLater) << 1;+ QTest::addRow("MoveLater, 2 shapes") << int(KoSvgTextReorderShapeInsideCommand::MoveLater) << 2;+ QTest::addRow("SendToBack, 1 shape") << int(KoSvgTextReorderShapeInsideCommand::SendToBack) << 1;+ QTest::addRow("SendToBack, 2 shapes") << int(KoSvgTextReorderShapeInsideCommand::SendToBack) << 2;+}++void TestSvgTextShape::testReorderShapesInside()+{+ QFETCH(int, type);+ QFETCH(int, amount);+ KoSvgTextShape *textShape = new KoSvgTextShape();+ textShape->insertText(0, "The quick brown fox jumps over the lazy dog.");+ QList<KoShape*> shapes;+ for (int i = 0; i < 5; i++) {+ KoPathShape *p = createPolygon();+ p->setTransformation(QTransform::fromTranslate(i*10, i*10));+ shapes.append(p);+ }++ textShape->setShapesInside(shapes);++ KoSvgTextReorderShapeInsideCommand::MoveShapeType moveShapeType = KoSvgTextReorderShapeInsideCommand::MoveShapeType (type);++ QList<KoShape*> targets;+ KUndo2Command *parentCommand = new KUndo2Command();+ for (int i = 2; i < qMin(2+amount, shapes.size()); i++) {+ KoShape *target = shapes.at(i);+ targets.append(target);+ }++ new KoSvgTextReorderShapeInsideCommand(textShape, targets, moveShapeType, parentCommand);+ parentCommand->redo();++ int start = 0;+ switch(moveShapeType) {+ case KoSvgTextReorderShapeInsideCommand::BringToFront:+ start = 0;+ break;+ case KoSvgTextReorderShapeInsideCommand::MoveEarlier:+ start = 1;+ break;+ case KoSvgTextReorderShapeInsideCommand::MoveLater:+ start = 3;+ break;+ case KoSvgTextReorderShapeInsideCommand::SendToBack:+ start = (shapes.size()-(amount));+ break;+ }+ Q_FOREACH(KoShape *target, targets) {+ const int final = textShape->shapesInside().indexOf(target);+ QVERIFY2(final == start, QString("Expected: %1, got: %2").arg(start).arg(final).toLatin1());+ start +=1;+ }++ parentCommand->undo();++ int startOld = 2;+ Q_FOREACH(KoShape *target, targets) {+ const int final = textShape->shapesInside().indexOf(target);+ QVERIFY2(final == startOld, QString("Expected: %1, got: %2").arg(startOld).arg(final).toLatin1());+ startOld+=1;+ }+}++KISTEST_MAIN(TestSvgTextShape)diff --git a/libs/flake/tests/TestSvgTextShape.h b/libs/flake/tests/TestSvgTextShape.hnew file mode 100644index 0000000000..218b00a350--- /dev/null+++ b/libs/flake/tests/TestSvgTextShape.h@@ -0,0 +1,34 @@+/*+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */++#ifndef TESTSVGTEXTSHAPE_H+#define TESTSVGTEXTSHAPE_H+++#include <simpletest.h>+#include <QObject>++class TestSvgTextShape : public QObject+{+ Q_OBJECT+private Q_SLOTS:++ void testSetTextOnShape_data();+ void testSetTextOnShape();++ void testRemoveShapeFromText();++ void testSetSize_data();+ void testSetSize();++ void testToggleShapeType();++ void testReorderShapesInside_data();+ void testReorderShapesInside();++};++#endif // TESTSVGTEXTSHAPE_Hdiff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cppindex bbdde20247..a5cec840df 100644--- a/libs/flake/text/KoSvgTextShape.cpp+++ b/libs/flake/text/KoSvgTextShape.cpp@@ -221,9 +221,9 @@ void KoSvgTextShape::shapeChanged(ChangeType type, KoShape *shape)qDebug() << "text updated";if ((type == ContentChanged)) {relayout();- } else if (transformationTypes.contains(type)) {- qDebug() << "update transform";- d->shapeGroup->setTransformation(this->transformation());+ } else if (transformationTypes.contains(type) || type == ParentChanged) {+ qDebug() << "update transform" << this->absoluteTransformation();+ d->shapeGroup->setTransformation(this->absoluteTransformation());} else if (type == TextRunAroundChanged) {// Hack: we don't use runaround else where, so we're using it for padding and margin.qDebug() << "update wrapping areas";@@ -1926,11 +1926,12 @@ QPainterPath KoSvgTextShape::outline() const {Q_FOREACH(KoShape *shape, d->internalShapes()) {result.addPath(shape->transformation().map(shape->outline()));}- }- for (auto it = d->textData.depthFirstTailBegin(); it != d->textData.depthFirstTailEnd(); it++) {- result.addPath(it->associatedOutline);- for (int i = 0; i < it->textDecorations.values().size(); ++i) {- result.addPath(it->textDecorations.values().at(i));+ } else {+ for (auto it = d->textData.depthFirstTailBegin(); it != d->textData.depthFirstTailEnd(); it++) {+ result.addPath(it->associatedOutline);+ for (int i = 0; i < it->textDecorations.values().size(); ++i) {+ result.addPath(it->textDecorations.values().at(i));+ }}}@@ -1943,6 +1944,9 @@ QRectF KoSvgTextShape::outlineRect() constQRectF KoSvgTextShape::boundingRect() const{+ if (d->internalShapesPainter->contentRect().isValid()) {+ return d->internalShapesPainter->contentRect();+ }QRectF result;QList<KoShapeStrokeModelSP> parentStrokes;@@ -1974,7 +1978,7 @@ QRectF KoSvgTextShape::boundingRect() const}}- return d->internalShapesPainter->contentRect().united(this->absoluteTransformation().mapRect(result));+ return this->absoluteTransformation().mapRect(result);}QSizeF KoSvgTextShape::size() const@@ -1993,13 +1997,14 @@ void KoSvgTextShape::setSize(const QSizeF &size)const qreal scaleY = size.height() / oldSize.height();if (!d->internalShapes().isEmpty()) {+ const bool usePostScaling = (d->internalShapes().size() > 1);Q_FOREACH(KoShape *shape, d->internalShapes()) {- KoFlake::resizeShapeCommon(shape, scaleX, scaleY, shape->boundingRect().topLeft() - oRect.topLeft(), false, false, this->transformation());+ QPointF topLeft = shape->transformation().map(shape->outlineRect().topLeft());+ KoFlake::resizeShapeCommon(shape, scaleX, scaleY, topLeft - oRect.topLeft(), false, usePostScaling, this->transformation());}} else {this->scale(scaleX, scaleY);//TODO: use scaling function for kosvgtextproperties when styles presets are merged.- //TODO: Support text-on-pathnotifyChanged();shapeChangedPriv(ScaleChanged);}diff --git a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp b/plugins/tools/defaulttool/defaulttool/DefaultTool.cppindex 89495fbc53..212c3a2eeb 100644--- a/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp+++ b/plugins/tools/defaulttool/defaulttool/DefaultTool.cpp@@ -583,16 +583,10 @@ void DefaultTool::slotAddShapesToFlow()new KoKeepShapesSelectedCommand(selectedShapes, {}, canvas()->selectedShapesProxy(), false, parentCommand);Q_FOREACH(KoShape *shape, shapes) {- QPointF pos = shape->absolutePosition(KoFlake::TopLeft);- QList<KoShape*> shapes{shape};-if(shape->parent()) {canvas()->shapeController()->removeShape(shape, parentCommand);}new KoSvgTextAddShapeCommand(textShape, shape, true, parentCommand);-- pos = shape->absolutePosition(KoFlake::TopLeft) - pos;- new KoShapeMoveCommand(shapes, pos, parentCommand);}new KoKeepShapesSelectedCommand({}, {textShape}, canvas()->selectedShapesProxy(), true, parentCommand);@@ -627,16 +621,10 @@ void DefaultTool::slotSubtractShapesFromFlow()new KoKeepShapesSelectedCommand(selectedShapes, {}, canvas()->selectedShapesProxy(), false, parentCommand);Q_FOREACH(KoShape *shape, shapes) {- QPointF pos = shape->absolutePosition(KoFlake::TopLeft);- QList<KoShape*> shapes{shape};-if (shape->parent()) {canvas()->shapeController()->removeShape(shape, parentCommand);}new KoSvgTextAddShapeCommand(textShape, shape, false, parentCommand);-- pos = shape->absolutePosition(KoFlake::TopLeft) - pos;- new KoShapeMoveCommand(shapes, pos, parentCommand);}new KoKeepShapesSelectedCommand({}, {textShape}, canvas()->selectedShapesProxy(), true, parentCommand);@@ -660,12 +648,8 @@ void DefaultTool::slotRemoveShapesFromFlow()new KoKeepShapesSelectedCommand(selectedShapes, {}, canvas()->selectedShapesProxy(), false, parentCommand);Q_FOREACH(KoShape *shape, selectedShapes) {if (!textShape->shapeInContours(shape)) continue;- QPointF pos = shape->absolutePosition(KoFlake::TopLeft);new KoSvgTextRemoveShapeCommand(textShape, shape, parentCommand);canvas()->shapeController()->addShape(shape, textShape->parent(), parentCommand);- pos = shape->absolutePosition(KoFlake::TopLeft) - pos;- QList<KoShape*> shapes{shape};- new KoShapeMoveCommand(shapes, pos, parentCommand);}canvas()->addCommand(parentCommand);}@@ -714,14 +698,14 @@ void DefaultTool::slotReorderFlowShapes(int type)parentCommand->setText(kundo2_i18n("Set Flow Shape as Last"));}- bool addToCanvas = false;+ QList<KoShape *> shapesInside;Q_FOREACH(KoShape *shape, selectedShapes) {if (!textShape->shapesInside().contains(shape)) continue;- new KoSvgTextReorderShapeInsideCommand(textShape, shape, KoSvgTextReorderShapeInsideCommand::MoveShapeType(type), parentCommand);- addToCanvas = true;+ shapesInside.append(shape);}- if (addToCanvas) {+ if (!shapesInside.isEmpty()) {+ new KoSvgTextReorderShapeInsideCommand(textShape, shapesInside, KoSvgTextReorderShapeInsideCommand::MoveShapeType(type), parentCommand);canvas()->addCommand(parentCommand);}}