Krita Source Code Documentation
Loading...
Searching...
No Matches
KoSvgTextLoader Class Reference

#include <KoSvgTextLoader.h>

Classes

struct  Private
 

Public Member Functions

void enterNodeSubtree ()
 Set the current node to its first child, entering the subtree.
 
 KoSvgTextLoader (KoSvgTextShape *shape)
 
void leaveNodeSubtree ()
 Set the current node to its parent, leaving the subtree.
 
bool loadSvg (const QDomElement &element, SvgLoadingContext &context, bool root=false)
 Create a new text node.
 
bool loadSvgText (const QDomText &text, SvgLoadingContext &context)
 Loads the textt into the current node.
 
void nextNode ()
 Switch to next node.
 
void setStyleInfo (KoShape *s)
 Set the style info from the shape. This is necessary because SVGParser only understands loading the basic style into a KoShape.
 
void setTextPathOnCurrentNode (KoShape *s)
 Set the textPath on the current node.
 
 ~KoSvgTextLoader ()
 

Private Attributes

QScopedPointer< Privated
 

Detailed Description

Loading an SVG text is somewhat intricate, so we use a KoSvgTextLoader to keep track of where we are in the tree.

Definition at line 15 of file KoSvgTextLoader.h.

Constructor & Destructor Documentation

◆ KoSvgTextLoader()

KoSvgTextLoader::KoSvgTextLoader ( KoSvgTextShape * shape)

Definition at line 25 of file KoSvgTextLoader.cpp.

26 : d(new Private(shape))
27{
28
29}
QScopedPointer< Private > d

◆ ~KoSvgTextLoader()

KoSvgTextLoader::~KoSvgTextLoader ( )

Definition at line 31 of file KoSvgTextLoader.cpp.

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}

References d.

Member Function Documentation

◆ enterNodeSubtree()

void KoSvgTextLoader::enterNodeSubtree ( )

Set the current node to its first child, entering the subtree.

Definition at line 44 of file KoSvgTextLoader.cpp.

45{
46 if (KisForestDetail::isEnd(d->currentNode)) {
47 nextNode();
48 }
49 d->currentNode = childEnd(d->currentNode);
50}
void nextNode()
Switch to next node.
bool isEnd(const ChildIterator< T, is_const > &it)
Definition KisForest.h:341
ChildIterator< value_type, is_const > childEnd(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:300

References d, KisForestDetail::isEnd(), and nextNode().

◆ leaveNodeSubtree()

void KoSvgTextLoader::leaveNodeSubtree ( )

Set the current node to its parent, leaving the subtree.

Definition at line 52 of file KoSvgTextLoader.cpp.

53{
54 d->currentNode = KisForestDetail::parent(d->currentNode);
55}
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

References d, and KisForestDetail::parent().

◆ loadSvg()

bool KoSvgTextLoader::loadSvg ( const QDomElement & element,
SvgLoadingContext & context,
bool root = false )

Create a new text node.

Definition at line 62 of file KoSvgTextLoader.cpp.

63{
64 if (KisForestDetail::isEnd(d->currentNode)) {
65 nextNode();
66 }
67 return d->currentNode->loadSvg(element, context, root);
68}

References d, KisForestDetail::isEnd(), and nextNode().

◆ loadSvgText()

bool KoSvgTextLoader::loadSvgText ( const QDomText & text,
SvgLoadingContext & context )

Loads the textt into the current node.

Definition at line 70 of file KoSvgTextLoader.cpp.

71{
72 if (KisForestDetail::isEnd(d->currentNode)) {
73 nextNode();
74 }
75 return d->currentNode->loadSvgTextNode(text, context);
76}

References d, KisForestDetail::isEnd(), and nextNode().

◆ nextNode()

void KoSvgTextLoader::nextNode ( )

Switch to next node.

Definition at line 57 of file KoSvgTextLoader.cpp.

58{
59 d->currentNode = d->shape->d->textData.insert(KisForestDetail::siblingEnd(d->currentNode), KoSvgTextContentElement());
60}
ChildIterator< value_type, is_const > siblingEnd(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:255
The KoSvgTextContentElement struct.

References d, and KisForestDetail::siblingEnd().

◆ setStyleInfo()

void KoSvgTextLoader::setStyleInfo ( KoShape * s)

Set the style info from the shape. This is necessary because SVGParser only understands loading the basic style into a KoShape.

Definition at line 78 of file KoSvgTextLoader.cpp.

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}
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 isVisible(bool recursive=true) const
Definition KoShape.cpp:802
qreal transparency(bool recursive=false) const
Definition KoShape.cpp:650
@ PaintOrder
QVector<KoShape::PaintOrder>
@ Opacity
Double, SVG shape opacity.
@ StrokeId
KoSvgText::StrokeProperty.
@ FillId
KoSvgText::BackgroundProperty.
@ Visibility
Bool, CSS visibility.
ResultIterator hierarchyBegin(Iterator it)
Definition KisForest.h:419
ResultIterator hierarchyEnd(Iterator it)
Definition KisForest.h:427
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

References KoShape::background(), d, KoSvgTextProperties::FillId, KisForestDetail::hierarchyBegin(), KisForestDetail::hierarchyEnd(), KoShape::inheritBackground(), KoShape::inheritPaintOrder(), KoShape::inheritStroke(), KisForestDetail::isEnd(), KoShape::isVisible(), KoSvgTextProperties::Opacity, KoShape::paintOrder(), KoSvgTextProperties::PaintOrder, KoShape::stroke(), KoSvgTextProperties::StrokeId, KoShape::transparency(), and KoSvgTextProperties::Visibility.

◆ setTextPathOnCurrentNode()

void KoSvgTextLoader::setTextPathOnCurrentNode ( KoShape * s)

Set the textPath on the current node.

Definition at line 122 of file KoSvgTextLoader.cpp.

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}
bool addDependee(KoShape *shape)
Definition KoShape.cpp:1026
QString name() const
Definition KoShape.cpp:955

References KoShape::addDependee(), d, KisForestDetail::isEnd(), and KoShape::name().

Member Data Documentation

◆ d

QScopedPointer<Private> KoSvgTextLoader::d
private

Definition at line 40 of file KoSvgTextLoader.h.


The documentation for this class was generated from the following files: