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->cleanUp();
35 d->shape->d->isLoading = false;
36}
37
39{
40 if (KisForestDetail::isEnd(d->currentNode)) {
41 nextNode();
42 }
43 d->currentNode = childEnd(d->currentNode);
44}
45
47{
48 d->currentNode = KisForestDetail::parent(d->currentNode);
49}
50
52{
53 d->currentNode = d->shape->d->textData.insert(KisForestDetail::siblingEnd(d->currentNode), KoSvgTextContentElement());
54}
55
56bool KoSvgTextLoader::loadSvg(const QDomElement &element, SvgLoadingContext &context, bool root)
57{
58 if (KisForestDetail::isEnd(d->currentNode)) {
59 nextNode();
60 }
61 return d->currentNode->loadSvg(element, context, root);
62}
63
64bool KoSvgTextLoader::loadSvgText(const QDomText &text, SvgLoadingContext &context)
65{
66 if (KisForestDetail::isEnd(d->currentNode)) {
67 nextNode();
68 }
69 return d->currentNode->loadSvgTextNode(text, context);
70}
71
73{
74 if (!KisForestDetail::isEnd(d->currentNode)) {
75 // find closest parent stroke and fill so we can check for inheritance.
77 KoShapeStrokeModelSP parentStroke;
78 for (auto it = KisForestDetail::hierarchyBegin(d->currentNode); it != KisForestDetail::hierarchyEnd(d->currentNode); it++) {
79 if (it->properties.hasProperty(KoSvgTextProperties::FillId)) {
80 parentBg = it->properties.background();
81 break;
82 }
83 }
84 for (auto it = KisForestDetail::hierarchyBegin(d->currentNode); it != KisForestDetail::hierarchyEnd(d->currentNode); it++) {
85 if (it->properties.hasProperty(KoSvgTextProperties::StrokeId)) {
86 parentStroke = it->properties.stroke();
87 break;
88 }
89 }
90
91 if (!s->inheritBackground()) {
92 if ((parentBg && !parentBg->compareTo(s->background().data()))
93 || (!parentBg && s->background())) {
94 d->currentNode->properties.setProperty(KoSvgTextProperties::FillId,
95 QVariant::fromValue(KoSvgText::BackgroundProperty(s->background())));
96 }
97 }
98 if (!s->inheritStroke()) {
99 if ((parentStroke && (!parentStroke->compareFillTo(s->stroke().data()) || !parentStroke->compareStyleTo(s->stroke().data())))
100 || (!parentStroke && s->stroke())) {
101 d->currentNode->properties.setProperty(KoSvgTextProperties::StrokeId,
102 QVariant::fromValue(KoSvgText::StrokeProperty(s->stroke())));
103 }
104 }
105 d->currentNode->properties.setProperty(KoSvgTextProperties::Opacity,
106 s->transparency());
107 d->currentNode->properties.setProperty(KoSvgTextProperties::Visiblity,
108 s->isVisible());
109 if (!s->inheritPaintOrder()) {
110 d->currentNode->properties.setProperty(KoSvgTextProperties::PaintOrder,
111 QVariant::fromValue(s->paintOrder()));
112 }
113 }
114}
115
117{
118 if (!KisForestDetail::isEnd(d->currentNode)) {
119 d->currentNode->textPath.reset(s);
120 }
121}
122
virtual QVector< PaintOrder > paintOrder() const
paintOrder
Definition KoShape.cpp:773
virtual KoShapeStrokeModelSP stroke() const
Definition KoShape.cpp:1067
bool inheritStroke() const
inheritStroke shows if the shape inherits the stroke from its parent
Definition KoShape.cpp:1098
bool inheritBackground() const
inheritBackground shows if the shape inherits background from its parent
Definition KoShape.cpp:949
virtual QSharedPointer< KoShapeBackground > background() const
Definition KoShape.cpp:926
bool inheritPaintOrder() const
inheritPaintOrder
Definition KoShape.cpp:795
bool isVisible(bool recursive=true) const
Definition KoShape.cpp:979
qreal transparency(bool recursive=false) const
Definition KoShape.cpp:730
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.
@ Visiblity
Bool, CSS visibility.
@ PaintOrder
QVector<KoShape::PaintOrder>
@ Opacity
Double, SVG shape opacity.
@ StrokeId
KoSvgText::StrokeProperty.
@ FillId
KoSvgText::BackgroundProperty.
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