Krita Source Code Documentation
Loading...
Searching...
No Matches
KoSvgTextLoader.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#include "KoSvgTextLoader.h"
7#include "KoSvgTextShape_p.h"
8
9
11
13 : shape(shape)
14 , currentNode(shape->d->textData.childEnd())
15 {
16 shape->d->isLoading = true;
17 shape->d->textData.erase(shape->d->textData.childBegin(), shape->d->textData.childEnd());
18 currentNode = shape->d->textData.childEnd();
19 }
20
23};
24
26 : d(new Private(shape))
27{
28
29}
30
32{
33 // run clean-up after parsing to remove empty spans and the like.
34 d->shape->d->updateShapeGroup();
35 d->shape->cleanUp();
36 d->shape->d->isLoading = false;
37
38 // finish loading by synchronizing the internal group
39 d->shape->d->shapeGroup->setTransformation(d->shape->absoluteTransformation());
40 d->shape->d->updateTextWrappingAreas();
41 d->shape->notifyChanged();
42}
43
45{
46 if (KisForestDetail::isEnd(d->currentNode)) {
47 nextNode();
48 }
49 d->currentNode = childEnd(d->currentNode);
50}
51
53{
54 d->currentNode = KisForestDetail::parent(d->currentNode);
55}
56
58{
59 d->currentNode = d->shape->d->textData.insert(KisForestDetail::siblingEnd(d->currentNode), KoSvgTextContentElement());
60}
61
62bool KoSvgTextLoader::loadSvg(const QDomElement &element, SvgLoadingContext &context, bool root)
63{
64 if (KisForestDetail::isEnd(d->currentNode)) {
65 nextNode();
66 }
67 return d->currentNode->loadSvg(element, context, root);
68}
69
70bool KoSvgTextLoader::loadSvgText(const QDomText &text, SvgLoadingContext &context)
71{
72 if (KisForestDetail::isEnd(d->currentNode)) {
73 nextNode();
74 }
75 return d->currentNode->loadSvgTextNode(text, context);
76}
77
79{
80 if (!KisForestDetail::isEnd(d->currentNode)) {
81 // find closest parent stroke and fill so we can check for inheritance.
83 KoShapeStrokeModelSP parentStroke;
84 for (auto it = KisForestDetail::hierarchyBegin(d->currentNode); it != KisForestDetail::hierarchyEnd(d->currentNode); it++) {
85 if (it->properties.hasProperty(KoSvgTextProperties::FillId)) {
86 parentBg = it->properties.background();
87 break;
88 }
89 }
90 for (auto it = KisForestDetail::hierarchyBegin(d->currentNode); it != KisForestDetail::hierarchyEnd(d->currentNode); it++) {
91 if (it->properties.hasProperty(KoSvgTextProperties::StrokeId)) {
92 parentStroke = it->properties.stroke();
93 break;
94 }
95 }
96
97 if (!s->inheritBackground()) {
98 if ((parentBg && !parentBg->compareTo(s->background().data()))
99 || (!parentBg && s->background())) {
100 d->currentNode->properties.setProperty(KoSvgTextProperties::FillId,
101 QVariant::fromValue(KoSvgText::BackgroundProperty(s->background())));
102 }
103 }
104 if (!s->inheritStroke()) {
105 if ((parentStroke && (!parentStroke->compareFillTo(s->stroke().data()) || !parentStroke->compareStyleTo(s->stroke().data())))
106 || (!parentStroke && s->stroke())) {
107 d->currentNode->properties.setProperty(KoSvgTextProperties::StrokeId,
108 QVariant::fromValue(KoSvgText::StrokeProperty(s->stroke())));
109 }
110 }
111 d->currentNode->properties.setProperty(KoSvgTextProperties::Opacity,
112 s->transparency());
113 d->currentNode->properties.setProperty(KoSvgTextProperties::Visibility,
114 s->isVisible());
115 if (!s->inheritPaintOrder()) {
116 d->currentNode->properties.setProperty(KoSvgTextProperties::PaintOrder,
117 QVariant::fromValue(s->paintOrder()));
118 }
119 }
120}
121
123{
124 if (!KisForestDetail::isEnd(d->currentNode) && s) {
125 d->shape->d->makeTextPathNameUnique(d->shape->d->textPaths, s);
126 d->currentNode->textPathId = s->name();
127 s->addDependee(d->shape);
128 d->shape->d->textPaths.append(s);
129 }
130}
131
virtual QVector< PaintOrder > paintOrder() const
paintOrder
Definition KoShape.cpp:693
virtual KoShapeStrokeModelSP stroke() const
Definition KoShape.cpp:890
bool inheritStroke() const
inheritStroke shows if the shape inherits the stroke from its parent
Definition KoShape.cpp:921
bool inheritBackground() const
inheritBackground shows if the shape inherits background from its parent
Definition KoShape.cpp:782
virtual QSharedPointer< KoShapeBackground > background() const
Definition KoShape.cpp:759
bool inheritPaintOrder() const
inheritPaintOrder
Definition KoShape.cpp:715
bool addDependee(KoShape *shape)
Definition KoShape.cpp:1026
QString name() const
Definition KoShape.cpp:955
bool isVisible(bool recursive=true) const
Definition KoShape.cpp:802
qreal transparency(bool recursive=false) const
Definition KoShape.cpp:650
KoSvgTextLoader(KoSvgTextShape *shape)
QScopedPointer< Private > d
void leaveNodeSubtree()
Set the current node to its parent, leaving the subtree.
bool loadSvgText(const QDomText &text, SvgLoadingContext &context)
Loads the textt into the current node.
void setTextPathOnCurrentNode(KoShape *s)
Set the textPath on the current node.
void nextNode()
Switch to next node.
void enterNodeSubtree()
Set the current node to its first child, entering the subtree.
void setStyleInfo(KoShape *s)
Set the style info from the shape. This is necessary because SVGParser only understands loading the b...
bool loadSvg(const QDomElement &element, SvgLoadingContext &context, bool root=false)
Create a new text node.
@ PaintOrder
QVector<KoShape::PaintOrder>
@ Opacity
Double, SVG shape opacity.
@ StrokeId
KoSvgText::StrokeProperty.
@ FillId
KoSvgText::BackgroundProperty.
@ Visibility
Bool, CSS visibility.
QScopedPointer< Private > d
Contains data used for loading svg.
bool isEnd(const ChildIterator< T, is_const > &it)
Definition KisForest.h:341
ResultIterator hierarchyBegin(Iterator it)
Definition KisForest.h:419
ResultIterator hierarchyEnd(Iterator it)
Definition KisForest.h:427
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327
ChildIterator< value_type, is_const > siblingEnd(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:255
The KoSvgTextContentElement struct.
KisForest< KoSvgTextContentElement >::child_iterator currentNode
Private(KoSvgTextShape *shape)
BackgroundProperty is a special wrapper around KoShapeBackground for managing it in KoSvgTextProperti...
Definition KoSvgText.h:714
StrokeProperty is a special wrapper around KoShapeStrokeModel for managing it in KoSvgTextProperties.
Definition KoSvgText.h:733