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++
Rework KoTextShape::outline so it returns a single shape.
Wolthera van Hövell tot Westerflier1b484e7c0f76
diff --git a/libs/flake/tests/TestSvgText.cpp b/libs/flake/tests/TestSvgText.cppindex fb1530d119..ef377d9aa2 100644--- a/libs/flake/tests/TestSvgText.cpp+++ b/libs/flake/tests/TestSvgText.cpp@@ -1262,9 +1262,18 @@ void TestSvgText::testTextOutline()gc.setPen(Qt::NoPen);gc.setBrush(Qt::black);gc.setRenderHint(QPainter::Antialiasing, true);- for (KoShape *shape : textShape->textOutline()) {- KoPathShape *outline = dynamic_cast<KoPathShape *>(shape);- if (shape) {+ KoShape *textOutline = textShape->textOutline();+ KoShapeGroup *group = dynamic_cast<KoShapeGroup *>(textOutline);+ if (group) {+ Q_FOREACH (KoShape *child, group->shapes()) {+ KoPathShape *outline = dynamic_cast<KoPathShape *>(child);+ if (outline) {+ gc.drawPath(outline->outline());+ }+ }+ } else {+ KoPathShape *outline = dynamic_cast<KoPathShape *>(textOutline);+ if (outline) {gc.drawPath(outline->outline());}}diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cppindex 31c881e568..d93a148715 100644--- a/libs/flake/text/KoSvgTextShape.cpp+++ b/libs/flake/text/KoSvgTextShape.cpp@@ -1551,15 +1551,15 @@ void KoSvgTextShape::paintDebug(QPainter &painter, const DebugElements elements)}}-QList<KoShape *> KoSvgTextShape::textOutline() const+KoShape * KoSvgTextShape::textOutline() const{- QList<KoShape *> shapes;+ KoShape *shape;int currentIndex = 0;if (!d->result.empty()) {- shapes = d->collectPaths(this, d->result, currentIndex);+ shape = d->collectPaths(this, d->result, currentIndex);}- return shapes;+ return shape;}void KoSvgTextShape::setShapesInside(QList<KoShape *> shapesInside)diff --git a/libs/flake/text/KoSvgTextShape.h b/libs/flake/text/KoSvgTextShape.hindex b0758bfff8..5196847694 100644--- a/libs/flake/text/KoSvgTextShape.h+++ b/libs/flake/text/KoSvgTextShape.h@@ -56,7 +56,14 @@ public:*/void relayout() const;- QList<KoShape *> textOutline() const;+ /**+ * @brief textOutline+ * This turns the text object into non-text KoShape(s) to the best of its abilities.+ * @return a single KoPathShape if only a single path is necessary,+ * or multiple KoShapes (Paths, Images, and Rectangles with Masks are all possible)+ * inside a KoShapeGroup.+ */+ KoShape * textOutline() const;/*** @brief setShapesInsidediff --git a/libs/flake/text/KoSvgTextShape_p.h b/libs/flake/text/KoSvgTextShape_p.hindex 2586f2fbd4..970ce1fc92 100644--- a/libs/flake/text/KoSvgTextShape_p.h+++ b/libs/flake/text/KoSvgTextShape_p.h@@ -580,7 +580,7 @@ public:const KoSvgText::TextRendering rendering,QPainterPath &chunk,int ¤tIndex);- QList<KoShape *> collectPaths(const KoShape *rootShape, QVector<CharacterResult> &result, int ¤tIndex);+ KoShape* collectPaths(const KoShape *rootShape, QVector<CharacterResult> &result, int ¤tIndex);void paintDebug(QPainter &painter,const QVector<CharacterResult> &result,int ¤tIndex);diff --git a/libs/flake/text/KoSvgTextShape_p_output.cpp b/libs/flake/text/KoSvgTextShape_p_output.cppindex 4a20ad03b1..c6369be412 100644--- a/libs/flake/text/KoSvgTextShape_p_output.cpp+++ b/libs/flake/text/KoSvgTextShape_p_output.cpp@@ -20,6 +20,8 @@#include <KoProperties.h>#include <KoClipMask.h>#include <KoInsets.h>+#include <KoShapeGroup.h>+#include <KoShapeGroupCommand.h>#include <kis_algebra_2d.h>@@ -28,7 +30,7 @@#include <variant>-void inheritPaintProperties(KisForest<KoSvgTextContentElement>::composition_iterator it,+static void inheritPaintProperties(const KisForest<KoSvgTextContentElement>::composition_iterator it,KoShapeStrokeModelSP &stroke,QSharedPointer<KoShapeBackground> &background,QVector<KoShape::PaintOrder> &paintOrder) {@@ -359,7 +361,7 @@ KoShapeStrokeModelSP transformStrokeBgToNewBounds(KoShapeStrokeModelSP stroke, c}// NOLINTNEXTLINE(readability-function-cognitive-complexity)-QList<KoShape *>+KoShape *KoSvgTextShape::Private::collectPaths(const KoShape *rootShape, QVector<CharacterResult> &result, int ¤tIndex){@@ -521,7 +523,35 @@ KoSvgTextShape::Private::collectPaths(const KoShape *rootShape, QVector<Characte}}}- return shapes;++ KoShape *parentShape = new KoPathShape();+ if (shapes.size() == 1) {+ parentShape = shapes.first();+ } else if (shapes.size() > 1) {+ KoShapeGroup *group = new KoShapeGroup();+ KoShapeGroupCommand cmd(group, shapes, false);+ cmd.redo();++ group->setBackground(rootShape->background());+ group->setStroke(rootShape->stroke());+ group->setPaintOrder(rootShape->paintOrder().first(), rootShape->paintOrder().at(1));+ group->setInheritPaintOrder(rootShape->inheritPaintOrder());+ for(int i = 0; i < group->shapes().size(); i++) {+ if (group->shapes().at(i)->background() == group->background()) {+ group->shapes().at(i)->setInheritBackground(true);+ }+ if (group->shapes().at(i)->stroke() == group->stroke()) {+ group->shapes().at(i)->setInheritStroke(true);+ }+ }++ parentShape = group;+ }+ parentShape->setZIndex(rootShape->zIndex());+ parentShape->setTransformation(rootShape->absoluteTransformation());+ parentShape->setName(rootShape->name());++ return parentShape;}// NOLINTNEXTLINE(readability-function-cognitive-complexity)diff --git a/libs/flake/tools/KoPathTool.cpp b/libs/flake/tools/KoPathTool.cppindex cb367b88b1..57a8b07804 100644--- a/libs/flake/tools/KoPathTool.cpp+++ b/libs/flake/tools/KoPathTool.cpp@@ -317,17 +317,12 @@ void KoPathTool::convertToPath()QList<KoShape*> newSelectedShapes;Q_FOREACH (KoSvgTextShape *shape, textShapes) {- KoShapeGroup *groupShape = new KoShapeGroup();- KoShapeGroupCommand groupCmd(groupShape, shape->textOutline(), false);- groupCmd.redo();-- groupShape->setZIndex(shape->zIndex());- groupShape->setTransformation(shape->absoluteTransformation());+ KoShape *outlineShape = shape->textOutline();KoShapeContainer *parent = shape->parent();- canvas()->shapeController()->addShapeDirect(groupShape, parent, cmd);+ canvas()->shapeController()->addShapeDirect(outlineShape, parent, cmd);- newSelectedShapes << groupShape;+ newSelectedShapes << outlineShape;}canvas()->shapeController()->removeShapes(oldSelectedShapes, cmd);