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++
Ensure the text contour is only calculated when related shapes change.
Wolthera van Hövell tot Westerflier823e6ffe534c
diff --git a/libs/flake/svg/SvgParser.cpp b/libs/flake/svg/SvgParser.cppindex ad3a0b778d..1ff114fd3b 100644--- a/libs/flake/svg/SvgParser.cpp+++ b/libs/flake/svg/SvgParser.cpp@@ -1948,7 +1948,6 @@ KoShape *SvgParser::parseTextElement(const QDomElement &e, KoSvgTextShape *mergem_isInsideTextSubtree = false;//rootTextShape->debugParsing();- rootTextShape->relayout();return rootTextShape;diff --git a/libs/flake/text/KoSvgTextLoader.cpp b/libs/flake/text/KoSvgTextLoader.cppindex d087db9871..81702da9e0 100644--- a/libs/flake/text/KoSvgTextLoader.cpp+++ b/libs/flake/text/KoSvgTextLoader.cpp@@ -34,6 +34,7 @@ KoSvgTextLoader::~KoSvgTextLoader()d->shape->d->updateShapeGroup();d->shape->cleanUp();d->shape->d->isLoading = false;+ d->shape->relayout();}void KoSvgTextLoader::enterNodeSubtree()diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cppindex 28c06bca4b..c92d5871e3 100644--- a/libs/flake/text/KoSvgTextShape.cpp+++ b/libs/flake/text/KoSvgTextShape.cpp@@ -151,6 +151,9 @@ KoSvgTextShape::KoSvgTextShape(const KoSvgTextShape &rhs)KoSvgTextShape::~KoSvgTextShape(){+ Q_FOREACH(KoShape *shape, internalShapeManager()->shapes()) {+ shape->removeDependee(this);+ }}const QString &KoSvgTextShape::defaultPlaceholderText()@@ -171,19 +174,37 @@ void KoSvgTextShape::shapeChanged(ChangeType type, KoShape *shape)}KoShape::shapeChanged(type, shape);+ const QVector<ChangeType> transformationTypes = {PositionChanged, RotationChanged, ScaleChanged, ShearChanged, SizeChanged, GenericMatrixChange};+qDebug() << shape << type;if ((d->shapesInside.contains(shape) || d->shapesSubtract.contains(shape) || d->textPaths.contains(shape))- && (type == PositionChanged- || type == RotationChanged- || type == ScaleChanged- || type == ShearChanged- || type == SizeChanged- || type == GenericMatrixChange+ && (transformationTypes.contains(type)|| type == ParameterChanged- || type == ParentChanged)) {- // update shape. relayout.- //TODO: also handle type == Deleted. Need to figure out the order of operations though.- relayout();+ || type == ParentChanged+ || type == Deleted)) {+ if (type == Deleted) {+ if (d->shapesInside.contains(shape)) {+ d->shapesInside.removeAll(shape);+ }+ if (d->shapesSubtract.contains(shape)) {+ d->shapesSubtract.removeAll(shape);+ }+ if (d->textPaths.contains(shape)) {+ d->textPaths.removeAll(shape);+ // TODO: remove ID from relevant text content element.+ }+ if (d->shapeGroup && d->shapeGroup->shapes().contains(shape)) {+ d->shapeGroup->removeShape(shape);+ }+ d->updateInternalShapesList();+ }++ // Updates the contours and calls relayout.+ // Would be great if we could compress the updates here somehow...+ // TODO: when shapeMargin or Padding is changed, this also needs to be called...+ d->updateTextWrappingAreas();++ // NotifyChanged ensures that boundingRect() is called on this shape.this->notifyChanged();qDebug() << "child updated";}@@ -191,7 +212,7 @@ void KoSvgTextShape::shapeChanged(ChangeType type, KoShape *shape)qDebug() << "text updated";if ((type == ContentChanged)) {relayout();- } else {+ } else if (transformationTypes.contains(type)) {qDebug() << "update transform";d->shapeGroup->setTransformation(this->transformation());}@@ -2047,6 +2068,7 @@ void KoSvgTextShape::setShapesInside(QList<KoShape *> shapesInside)d->shapeGroup->addShape(shape);shape->addDependee(this);}+ d->updateTextWrappingAreas();d->updateInternalShapesList();shapeChangedPriv(ContentChanged);update();@@ -2070,6 +2092,7 @@ void KoSvgTextShape::setShapesSubtract(QList<KoShape *> shapesSubtract)d->shapeGroup->addShape(shape);shape->addDependee(this);}+ d->updateTextWrappingAreas();d->updateInternalShapesList();shapeChangedPriv(ContentChanged);update();diff --git a/libs/flake/text/KoSvgTextShape_p.h b/libs/flake/text/KoSvgTextShape_p.hindex 4ce9a80dbc..1ed1378ba1 100644--- a/libs/flake/text/KoSvgTextShape_p.h+++ b/libs/flake/text/KoSvgTextShape_p.h@@ -441,7 +441,10 @@ public:// the shape, though it will be reset locally if the// accessing thread changes- Private(): internalShapesPainter(new KoShapePainter), shapeGroup(new KoShapeGroup) {+ Private()+ : internalShapesPainter(new KoShapePainter)+ , shapeGroup(new KoShapeGroup)+ {shapeGroup->setSelectable(false);}@@ -454,7 +457,8 @@ public:Private(const Private &rhs): internalShapesPainter(new KoShapePainter)- , textData(rhs.textData) {+ , textData(rhs.textData)+ {KoShapeGroup *g = dynamic_cast<KoShapeGroup*>(rhs.shapeGroup.data()->cloneShape());shapeGroup.reset(g);@@ -477,6 +481,8 @@ public:isLoading = rhs.isLoading;disableFontMatching = rhs.disableFontMatching;++ currentTextWrappingAreas = rhs.currentTextWrappingAreas;}void handleShapes(const QList<KoShape*> &sourceShapeList, const QList<KoShape*> referenceList2, const QList<KoShape*> referenceShapeList, QList<KoShape*> &destinationShapeList) {@@ -525,17 +531,29 @@ public:Q_FOREACH(KoShape *shape, textPaths) {shapeGroup->addShape(shape);}+ qDebug() << "updateing contours";+ updateTextWrappingAreas();updateInternalShapesList();}void updateInternalShapesList() {- qDebug() << Q_FUNC_INFO << shapesInside.size() << shapeGroup->shapes().size();- internalShapesPainter->setShapes(shapeGroup->shapes());+ if (shapeGroup) {+ qDebug() << Q_FUNC_INFO << shapesInside.size() << shapeGroup->shapes().size();+ internalShapesPainter->setShapes(shapeGroup->shapes());+ }}QList<KoShape*> shapesInside;QList<KoShape*> shapesSubtract;QList<KoShape*> textPaths;+ QList<QPainterPath> currentTextWrappingAreas;++ /**+ * @brief updateShapeContours+ * The current shape contours can be slow to compute, so this function+ * calls computing them, and then calls relayout();+ */+ void updateTextWrappingAreas();KoShape *textPathByName(QString name) {auto it = std::find_if(textPaths.begin(), textPaths.end(), [&name](const KoShape *s) -> bool {return s->name() == name;});@@ -1164,7 +1182,7 @@ public:if (!isEnd(siblingPrev)&& siblingPrev != siblingCurrent(it)&& (siblingPrev->localTransformations.isEmpty() && it->localTransformations.isEmpty())- && (!siblingPrev->textPath && !it->textPath)+ && (siblingPrev->textPathId.isEmpty() && !it->textPathId.isEmpty())&& (siblingPrev->textLength.isAuto && it->textLength.isAuto)&& (siblingPrev->properties == it->properties)&& (bidi != KoSvgText::BidiIsolate && bidi != KoSvgText::BidiIsolateOverride)) {diff --git a/libs/flake/text/KoSvgTextShape_p_layout.cpp b/libs/flake/text/KoSvgTextShape_p_layout.cppindex 0cd205f38d..d3549e1e17 100644--- a/libs/flake/text/KoSvgTextShape_p_layout.cpp+++ b/libs/flake/text/KoSvgTextShape_p_layout.cpp@@ -109,6 +109,15 @@ QString langToLibUnibreakLang(const QString lang) {return lang;}++void KoSvgTextShape::Private::updateTextWrappingAreas()+{+ KoSvgTextProperties rootProperties = textData.empty()? KoSvgTextProperties::defaultProperties(): textData.childBegin()->properties;+ currentTextWrappingAreas = getShapes(shapesInside, shapesSubtract, rootProperties);+ if (!isLoading) {+ relayout();+ }+}// NOLINTNEXTLINE(readability-function-cognitive-complexity)void KoSvgTextShape::Private::relayout(){@@ -644,9 +653,8 @@ void KoSvgTextShape::Private::relayout()// Handle linebreaking.QPointF startPos = resolvedTransforms.value(0).absolutePos() - result.value(0).dominantBaselineOffset;- if (!this->shapesInside.isEmpty()) {- QList<QPainterPath> shapes = getShapes(this->shapesInside, this->shapesSubtract, rootProperties);- this->lineBoxes = flowTextInShapes(rootProperties, logicalToVisual, result, shapes, startPos, resHandler);+ if (!this->currentTextWrappingAreas.isEmpty()) {+ this->lineBoxes = flowTextInShapes(rootProperties, logicalToVisual, result, this->currentTextWrappingAreas, startPos, resHandler);} else {this->lineBoxes = breakLines(rootProperties, logicalToVisual, result, startPos, resHandler);}