Skip to content

armgit / krita

Public Imported from GitHub
0

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 all text contour shapes part of an internal shape group.

Wolthera van Hövell tot Westerflier85f095fe827a
diff --git a/libs/flake/KoSelection.cpp b/libs/flake/KoSelection.cpp
index 560ca79206..c6ea15ff34 100644
--- a/libs/flake/KoSelection.cpp
+++ b/libs/flake/KoSelection.cpp
@@ -92,7 +92,11 @@ void KoSelection::select(KoShape *shape)
// find the topmost parent to select
while (KoShapeGroup *parentGroup = dynamic_cast<KoShapeGroup*>(shape->parent())) {
- shape = parentGroup;
+ if (parentGroup && parentGroup->isSelectable()) {
+ shape = parentGroup;
+ } else {
+ break;
+ }
}
d->selectedShapes << shape;
diff --git a/libs/flake/text/KoSvgTextLoader.cpp b/libs/flake/text/KoSvgTextLoader.cpp
index 2c31219c94..d087db9871 100644
--- a/libs/flake/text/KoSvgTextLoader.cpp
+++ b/libs/flake/text/KoSvgTextLoader.cpp
@@ -31,7 +31,7 @@ KoSvgTextLoader::KoSvgTextLoader(KoSvgTextShape *shape)
KoSvgTextLoader::~KoSvgTextLoader()
{
// run clean-up after parsing to remove empty spans and the like.
- d->shape->d->updateInternalShapesList();
+ d->shape->d->updateShapeGroup();
d->shape->cleanUp();
d->shape->d->isLoading = false;
}
diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cpp
index 7008eaefaf..02ddc80f11 100644
--- a/libs/flake/text/KoSvgTextShape.cpp
+++ b/libs/flake/text/KoSvgTextShape.cpp
@@ -139,6 +139,9 @@ KoSvgTextShape::KoSvgTextShape(const KoSvgTextShape &rhs)
, d(new Private(*rhs.d))
{
setShapeId(KoSvgTextShape_SHAPEID);
+ Q_FOREACH(KoShape *shape, d->shapeGroup->shapes()) {
+ shape->addDependee(this);
+ }
}
KoSvgTextShape::~KoSvgTextShape()
@@ -163,6 +166,7 @@ void KoSvgTextShape::shapeChanged(ChangeType type, KoShape *shape)
}
KoShape::shapeChanged(type, shape);
+ qDebug() << shape << type;
if ((d->shapesInside.contains(shape) || d->shapesSubtract.contains(shape) || d->textPaths.contains(shape))
&& (type == PositionChanged
|| type == RotationChanged
@@ -175,10 +179,15 @@ void KoSvgTextShape::shapeChanged(ChangeType type, KoShape *shape)
//TODO: also handle type == Deleted. Need to figure out the order of operations though.
relayout();
this->updateAbsolute(boundingRect());
+ qDebug() << "child updated";
}
- if ((!shape || shape == this) && (type == ContentChanged || type == ChildChanged)) {
- relayout();
- d->updateInternalShapesList();
+ if ((!shape || shape == this)) {
+ qDebug() << "text updated";
+ if ((type == ContentChanged)) {
+ relayout();
+ } else {
+ d->shapeGroup->setTransformation(this->transformation());
+ }
}
}
@@ -1810,7 +1819,12 @@ bool KoSvgTextShape::fontMatchingDisabled() const
void KoSvgTextShape::paint(QPainter &painter) const
{
painter.save();
+
+ painter.setTransform(this->absoluteTransformation().inverted()*painter.transform());
d->internalShapesPainter->paint(painter);
+ painter.restore();
+
+ painter.save();
KoSvgText::TextRendering textRendering = KoSvgText::TextRendering(textProperties().propertyOrDefault(KoSvgTextProperties::TextRenderingId).toInt());
if (textRendering == KoSvgText::RenderingOptimizeSpeed || !painter.testRenderHint(QPainter::Antialiasing)) {
// also apply antialiasing only if antialiasing is active on provided target QPainter
@@ -1865,7 +1879,7 @@ QRectF KoSvgTextShape::outlineRect() const
QRectF KoSvgTextShape::boundingRect() const
{
- QRectF result = d->internalShapesPainter->contentRect();
+ QRectF result;
QList<KoShapeStrokeModelSP> parentStrokes;
for (auto it = d->textData.compositionBegin(); it != d->textData.compositionEnd(); it++) {
@@ -1896,7 +1910,7 @@ QRectF KoSvgTextShape::boundingRect() const
}
}
- return this->absoluteTransformation().mapRect(result);
+ return d->internalShapesPainter->contentRect().united(this->absoluteTransformation().mapRect(result));
}
QSizeF KoSvgTextShape::size() const
@@ -2020,10 +2034,11 @@ void KoSvgTextShape::setShapesInside(QList<KoShape *> shapesInside)
delete shape;
}
d->shapesInside = shapesInside;
- Q_FOREACH(KoShape *shape, d->shapesInside) {
+ d->updateShapeGroup();
+ Q_FOREACH(KoShape *shape, d->shapeGroup->shapes()) {
shape->addDependee(this);
}
- shapeChangedPriv(ChildChanged);
+ shapeChangedPriv(ContentChanged);
}
QList<KoShape *> KoSvgTextShape::shapesInside() const
@@ -2038,10 +2053,11 @@ void KoSvgTextShape::setShapesSubtract(QList<KoShape *> shapesSubtract)
delete shape;
}
d->shapesSubtract = shapesSubtract;
- Q_FOREACH(KoShape *shape, d->shapesSubtract) {
+ d->updateShapeGroup();
+ Q_FOREACH(KoShape *shape, d->shapeGroup->shapes()) {
shape->addDependee(this);
}
- shapeChangedPriv(ChildChanged);
+ shapeChangedPriv(ContentChanged);
}
QList<KoShape *> KoSvgTextShape::shapesSubtract() const
diff --git a/libs/flake/text/KoSvgTextShape.h b/libs/flake/text/KoSvgTextShape.h
index 1a3fbf8394..90d2be2159 100644
--- a/libs/flake/text/KoSvgTextShape.h
+++ b/libs/flake/text/KoSvgTextShape.h
@@ -550,7 +550,6 @@ public:
protected:
void shapeChanged(ChangeType type, KoShape *shape) override;
-
private:
friend class TestSvgText;
friend class KoSvgTextLoader;
diff --git a/libs/flake/text/KoSvgTextShape_p.h b/libs/flake/text/KoSvgTextShape_p.h
index 074a1f0274..4b60ab430a 100644
--- a/libs/flake/text/KoSvgTextShape_p.h
+++ b/libs/flake/text/KoSvgTextShape_p.h
@@ -16,6 +16,9 @@
#include <KoShapeManager.h>
#include "KoCssTextUtils.h"
+#include <KoShapeGroup.h>
+#include <commands/KoShapeGroupCommand.h>
+#include <commands/KoShapeUngroupCommand.h>
#include <kis_assert.h>
#include <KisForest.h>
@@ -440,8 +443,8 @@ public:
// the shape, though it will be reset locally if the
// accessing thread changes
- Private(): internalShapesPainter(new KoShapePainter) {
-
+ Private(): internalShapesPainter(new KoShapePainter), shapeGroup(new KoShapeGroup) {
+ shapeGroup->setSelectable(false);
}
enum InternalShapeState {
@@ -455,9 +458,12 @@ public:
: internalShapesPainter(new KoShapePainter)
, textData(rhs.textData) {
- cloneShapes(rhs.shapesInside, shapesInside);
- cloneShapes(rhs.shapesSubtract, shapesSubtract);
- cloneShapes(rhs.textPaths, textPaths);
+ KoShapeGroup *g = dynamic_cast<KoShapeGroup*>(rhs.shapeGroup.data()->cloneShape());
+ shapeGroup.reset(g);
+ shapeGroup->setSelectable(false);
+ handleShapes(shapeGroup->shapes(), rhs.shapeGroup->shapes(), rhs.shapesInside, shapesInside);
+ handleShapes(shapeGroup->shapes(), rhs.shapeGroup->shapes(), rhs.shapesSubtract, shapesSubtract);
+ handleShapes(shapeGroup->shapes(), rhs.shapeGroup->shapes(), rhs.textPaths, textPaths);
updateInternalShapesList();
yRes = rhs.yRes;
@@ -475,16 +481,21 @@ public:
disableFontMatching = rhs.disableFontMatching;
}
- void cloneShapes(const QList<KoShape*> &sourceShapeList, QList<KoShape*> &destinationShapeList) {
- Q_FOREACH (KoShape *shape, sourceShapeList) {
- KoShape *clonedShape = shape->cloneShape();
- KIS_ASSERT_RECOVER(clonedShape) { continue; }
- destinationShapeList.append(clonedShape);
+ void handleShapes(const QList<KoShape*> &sourceShapeList, const QList<KoShape*> referenceList2, const QList<KoShape*> referenceShapeList, QList<KoShape*> &destinationShapeList) {
+ for (int i = 0; i<sourceShapeList.size(); i++) {
+ if (referenceShapeList.contains(referenceList2.at(i))) {
+ destinationShapeList.append(sourceShapeList.at(i));
+ }
}
}
~Private() {
+
internalShapesPainter.reset();
+ Q_FOREACH(KoShape *shape, shapeGroup->shapes()) {
+ shapeGroup->removeShape(shape);
+ }
+ shapeGroup.reset();
qDeleteAll(shapesInside);
shapesInside.clear();
qDeleteAll(shapesSubtract);
@@ -497,16 +508,28 @@ public:
int yRes = 72;
QScopedPointer<KoShapePainter> internalShapesPainter;
+ QScopedPointer<KoShapeGroup> shapeGroup;
QList<KoShape*> internalShapes() const {
return internalShapesPainter->internalShapeManager()->shapes();
}
- void updateInternalShapesList() {
+ void updateShapeGroup() {
QList<KoShape*> total = shapesInside;
total.append(shapesSubtract);
total.append(textPaths);
- internalShapesPainter->setShapes(total);
+ KUndo2Command *parentCmd = new KUndo2Command();
+ if (!shapeGroup->shapes().isEmpty()) {
+ qWarning() << "shapes are not empty, might leak!";
+ new KoShapeUngroupCommand(shapeGroup.data(), shapeGroup->shapes(), QList<KoShape*>(), parentCmd);
+ }
+ new KoShapeGroupCommand(shapeGroup.data(), total, false, parentCmd);
+ parentCmd->redo();
+ updateInternalShapesList();
+ }
+ void updateInternalShapesList() {
+ qDebug() << Q_FUNC_INFO << shapesInside.size() << shapeGroup->shapes().size();
+ internalShapesPainter->setShapes(shapeGroup->shapes());
}
QList<KoShape*> shapesInside;