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++

Remove text path from text content element properly.

Wolthera van Hövell tot Westerfliercd1e05256ce4
diff --git a/libs/flake/text/KoSvgTextContentElement.h b/libs/flake/text/KoSvgTextContentElement.h
index 6fe1f8bfae..d93c425f8c 100644
--- a/libs/flake/text/KoSvgTextContentElement.h
+++ b/libs/flake/text/KoSvgTextContentElement.h
@@ -40,9 +40,7 @@ public:
, finalResultIndex(rhs.finalResultIndex)
, associatedOutline(rhs.associatedOutline)
{
- if (rhs.textPath) {
- textPath.reset(rhs.textPath.data()->cloneShape());
- }
+
}
~KoSvgTextContentElement() = default;
@@ -56,8 +54,7 @@ public:
/// Text path info for the text-on-path algorithm
KoSvgText::TextOnPathInfo textPathInfo;
- /// The textpath, if any. Defaults to null.
- QScopedPointer<KoShape> textPath{nullptr};
+ /// The textpath's name, if any.
QString textPathId;
/// the value 'textLength' attribute of the associated dom element
diff --git a/libs/flake/text/KoSvgTextLoader.cpp b/libs/flake/text/KoSvgTextLoader.cpp
index 81702da9e0..e302c918ef 100644
--- a/libs/flake/text/KoSvgTextLoader.cpp
+++ b/libs/flake/text/KoSvgTextLoader.cpp
@@ -119,6 +119,7 @@ void KoSvgTextLoader::setTextPathOnCurrentNode(KoShape *s)
{
if (!KisForestDetail::isEnd(d->currentNode) && s) {
d->currentNode->textPathId = s->name();
+ s->addDependee(d->shape);
d->shape->d->textPaths.append(s);
}
}
diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cpp
index 8a61bb2403..9324e497aa 100644
--- a/libs/flake/text/KoSvgTextShape.cpp
+++ b/libs/flake/text/KoSvgTextShape.cpp
@@ -1608,7 +1608,7 @@ bool KoSvgTextShape::saveSvg(SvgSavingContext &context)
if (it.state() == KisForestDetail::Enter) {
bool isTextPath = false;
QMap<QString, QString> shapeSpecificStyles;
- if (it->textPath) {
+ if (!it->textPathId.isEmpty()) {
isTextPath = true;
}
if (it == d->textData.compositionBegin()) {
@@ -1648,7 +1648,7 @@ bool KoSvgTextShape::saveSvg(SvgSavingContext &context)
}
- KoShape *textPath = d->textPathByName(it->textPathId);
+ KoShape *textPath = KoSvgTextShape::Private::textPathByName(it->textPathId, d->textPaths);
success = it->saveSvg(context,
it == d->textData.compositionBegin(),
d->childCount(siblingCurrent(it)) == 0,
@@ -1813,7 +1813,7 @@ void KoSvgTextShape::debugParsing()
qDebug() << QString(spaces + "| Opacity: ") << it->properties.property(KoSvgTextProperties::Opacity);
qDebug() << QString(spaces + "| PaintOrder: ") << it->properties.hasProperty(KoSvgTextProperties::PaintOrder);
qDebug() << QString(spaces + "| Visibility set: ") << it->properties.hasProperty(KoSvgTextProperties::Visibility);
- qDebug() << QString(spaces + "| TextPath set: ") << (!it->textPath.isNull());
+ qDebug() << QString(spaces + "| TextPath set: ") << it->textPathId;
qDebug() << QString(spaces + "| Transforms set: ") << it->localTransformations;
spaces.append(" ");
}
diff --git a/libs/flake/text/KoSvgTextShape_p.h b/libs/flake/text/KoSvgTextShape_p.h
index 1ed1378ba1..bc5eec6fce 100644
--- a/libs/flake/text/KoSvgTextShape_p.h
+++ b/libs/flake/text/KoSvgTextShape_p.h
@@ -555,7 +555,7 @@ public:
*/
void updateTextWrappingAreas();
- KoShape *textPathByName(QString name) {
+ static KoShape *textPathByName(QString name, QList<KoShape*> textPaths) {
auto it = std::find_if(textPaths.begin(), textPaths.end(), [&name](const KoShape *s) -> bool {return s->name() == name;});
return it != textPaths.end()? *it: nullptr;
}
@@ -609,7 +609,7 @@ public:
bool isHorizontal,
qreal offset,
bool isClosed);
- static void applyTextPath(KisForest<KoSvgTextContentElement>::child_iterator parent, QVector<CharacterResult> &result, bool isHorizontal, QPointF &startPos, const KoSvgTextProperties resolvedProps, Private *d);
+ static void applyTextPath(KisForest<KoSvgTextContentElement>::child_iterator parent, QVector<CharacterResult> &result, bool isHorizontal, QPointF &startPos, const KoSvgTextProperties resolvedProps, QList<KoShape*> textPaths);
static void computeFontMetrics(KisForest<KoSvgTextContentElement>::child_iterator parent, const KoSvgTextProperties &parentProps,
const KoSvgText::FontMetrics &parentBaselineTable, const KoSvgText::Baseline parentBaseline,
const QPointF superScript,
@@ -634,7 +634,7 @@ public:
bool isHorizontal,
bool ltr,
bool wrapping,
- const KoSvgTextProperties resolvedProps, Private *d);
+ const KoSvgTextProperties resolvedProps, QList<KoShape*> textPaths);
QMap<KoSvgText::TextDecoration, QPainterPath> generateDecorationPaths(const int &start, const int &end,
const KoSvgText::ResolutionHandler resHandler,
const QVector<CharacterResult> &result,
@@ -756,7 +756,7 @@ public:
// TODO: handle localtransforms better; annoyingly, this requires whitespace handling
if (siblingCurrent(contentElement) != tree.childBegin()
- && !contentElement->textPath
+ && contentElement->textPathId.isEmpty()
&& contentElement->textLength.isAuto
&& contentElement->localTransformations.isEmpty()) {
contentElement->removeText(zero, start);
@@ -1049,7 +1049,7 @@ public:
QVector<KoSvgText::CharTransformation> &resolvedTransforms,
bool &inTextPath) {
- inTextPath = (!current->textPath.isNull());
+ inTextPath = (!current->textPathId.isEmpty());
auto base = current.base();
base--;
if(base != siblingEnd(base)) {
@@ -1113,7 +1113,7 @@ public:
int &globalIndex, bool isHorizontal) {
KoSvgTextProperties props = current->properties;
props.inheritFrom(parentProps);
- if (current->textPath) return; // When we're doing text-on-path, we're already in preformatted mode.
+ if (!current->textPathId.isEmpty()) return; // When we're doing text-on-path, we're already in preformatted mode.
for (auto it = childBegin(current); it!= childEnd(current); it++) {
setTransformsFromLayoutImpl(it, props, layout, globalIndex, isHorizontal);
}
@@ -1171,7 +1171,7 @@ public:
// Remove empty leafs that are not the root or text paths.
const int length = it->numChars(false);
- if (length == 0 && siblingCurrent(it) != tree.childBegin() && !it->textPath) {
+ if (length == 0 && siblingCurrent(it) != tree.childBegin() && it->textPathId.isEmpty()) {
tree.erase(siblingCurrent(it));
} else {
// check if siblings are similar.
@@ -1182,7 +1182,7 @@ public:
if (!isEnd(siblingPrev)
&& siblingPrev != siblingCurrent(it)
&& (siblingPrev->localTransformations.isEmpty() && it->localTransformations.isEmpty())
- && (siblingPrev->textPathId.isEmpty() && !it->textPathId.isEmpty())
+ && (siblingPrev->textPathId.isEmpty() && it->textPathId.isEmpty())
&& (siblingPrev->textLength.isAuto && it->textLength.isAuto)
&& (siblingPrev->properties == it->properties)
&& (bidi != KoSvgText::BidiIsolate && bidi != KoSvgText::BidiIsolateOverride)) {
@@ -1195,7 +1195,7 @@ public:
// merge single children into parents if possible.
auto child = childBegin(siblingCurrent(it));
if ((child->localTransformations.isEmpty() && it->localTransformations.isEmpty())
- && (!child->textPath && !it->textPath)
+ && (child->textPathId.isEmpty() && it->textPathId.isEmpty())
&& (child->textLength.isAuto && it->textLength.isAuto)
&& (!child->properties.hasNonInheritableProperties() || !it->properties.hasNonInheritableProperties())) {
if (it->properties.hasNonInheritableProperties()) {
diff --git a/libs/flake/text/KoSvgTextShape_p_layout.cpp b/libs/flake/text/KoSvgTextShape_p_layout.cpp
index d3549e1e17..20d5cc6c76 100644
--- a/libs/flake/text/KoSvgTextShape_p_layout.cpp
+++ b/libs/flake/text/KoSvgTextShape_p_layout.cpp
@@ -747,12 +747,12 @@ void KoSvgTextShape::Private::relayout()
globalIndex,
isHorizontal,
direction == KoSvgText::DirectionLeftToRight,
- false, KoSvgTextProperties::defaultProperties(), this);
+ false, KoSvgTextProperties::defaultProperties(), this->textPaths);
// 8. Position on path
debugFlake << "8. Position on path";
- this->applyTextPath(textData.childBegin(), result, isHorizontal, startPos, KoSvgTextProperties::defaultProperties(), this);
+ this->applyTextPath(textData.childBegin(), result, isHorizontal, startPos, KoSvgTextProperties::defaultProperties(), this->textPaths);
} else {
globalIndex = 0;
debugFlake << "Computing text-decorationsfor inline-size";
@@ -766,7 +766,7 @@ void KoSvgTextShape::Private::relayout()
globalIndex,
isHorizontal,
direction == KoSvgText::DirectionLeftToRight,
- true, KoSvgTextProperties::defaultProperties(), this);
+ true, KoSvgTextProperties::defaultProperties(), this->textPaths);
}
// 9. return result.
@@ -1260,7 +1260,7 @@ void KoSvgTextShape::Private::computeTextDecorations(// NOLINT(readability-funct
bool ltr,
bool wrapping,
const KoSvgTextProperties resolvedProps,
- Private *d)
+ QList<KoShape *> textPaths)
{
const int i = currentIndex;
@@ -1271,7 +1271,7 @@ void KoSvgTextShape::Private::computeTextDecorations(// NOLINT(readability-funct
qreal currentTextPathOffset = textPathoffset;
bool textPathSide = side;
if (!wrapping) {
- KoShape *cTextPath = d->textPathByName(currentTextElement->textPathId);
+ KoShape *cTextPath = KoSvgTextShape::Private::textPathByName(currentTextElement->textPathId, textPaths);
currentTextPath = textPath ? textPath : dynamic_cast<KoPathShape *>(cTextPath);
if (cTextPath) {
@@ -1303,7 +1303,7 @@ void KoSvgTextShape::Private::computeTextDecorations(// NOLINT(readability-funct
isHorizontal,
ltr,
wrapping,
- properties, d
+ properties, textPaths
);
}
@@ -1834,7 +1834,7 @@ void KoSvgTextShape::Private::applyTextPath(KisForest<KoSvgTextContentElement>::
QVector<CharacterResult> &result,
bool isHorizontal,
QPointF &startPos,
- const KoSvgTextProperties resolvedProps, Private *d)
+ const KoSvgTextProperties resolvedProps, QList<KoShape *> textPaths)
{
// Unlike all the other applying functions, this one only iterates over the
// top-level. SVG is not designed to have nested textPaths. Source:
@@ -1846,7 +1846,7 @@ void KoSvgTextShape::Private::applyTextPath(KisForest<KoSvgTextContentElement>::
for (auto textShapeElement = KisForestDetail::childBegin(root); textShapeElement != KisForestDetail::childEnd(root); textShapeElement++) {
int endIndex = currentIndex + numChars(textShapeElement, true, resolvedProps);
- KoShape *cTextPath = d->textPathByName(textShapeElement->textPathId);
+ KoShape *cTextPath = KoSvgTextShape::Private::textPathByName(textShapeElement->textPathId, textPaths);
KoPathShape *shape = dynamic_cast<KoPathShape *>(cTextPath);
if (shape) {
QPainterPath path = shape->outline();