Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
sp-flowdiv.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
5 * Authors: see git history
6 *
7 * Copyright (C) 2018 Authors
8 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
9 */
10/*
11 */
12
13#include "sp-flowdiv.h"
14
15#include "sp-string.h"
16#include "xml/document.h"
17
20
21SPFlowdiv::~SPFlowdiv() = default;
22
26
27void SPFlowdiv::update(SPCtx *ctx, unsigned int flags) {
28 SPItemCtx *ictx = reinterpret_cast<SPItemCtx *>(ctx);
29 SPItemCtx cctx = *ictx;
30
31 unsigned childflags = flags;
32 if (flags & SP_OBJECT_MODIFIED_FLAG) {
33 childflags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
34 }
35 childflags &= SP_OBJECT_MODIFIED_CASCADE;
36
37 std::vector<SPObject *> l;
38 for (auto& child: children) {
40 l.push_back(&child);
41 }
42
43 for(auto child:l) {
44 if (childflags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
45 if (is<SPItem>(child)) {
46 SPItem const &chi = *cast<SPItem>(child);
47 cctx.i2doc = chi.transform * ictx->i2doc;
48 cctx.i2vp = chi.transform * ictx->i2vp;
49 child->updateDisplay((SPCtx *)&cctx, childflags);
50 } else {
51 child->updateDisplay(ctx, childflags);
52 }
53 }
54
56 }
57
58 SPItem::update(ctx, flags);
59}
60
61void SPFlowdiv::modified(unsigned int flags) {
62 SPItem::modified(flags);
63
64 if (flags & SP_OBJECT_MODIFIED_FLAG) {
65 flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
66 }
67
68 flags &= SP_OBJECT_MODIFIED_CASCADE;
69
70 std::vector<SPObject *> l;
71 for (auto& child: children) {
73 l.push_back(&child);
74 }
75
76 for(auto child:l) {
77 if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
78 child->emitModified(flags);
79 }
81 }
82}
83
84
90
91void SPFlowdiv::set(SPAttr key, const gchar* value) {
92 SPItem::set(key, value);
93}
94
95
97 if ( flags & SP_OBJECT_WRITE_BUILD ) {
98 if ( repr == nullptr ) {
99 repr = xml_doc->createElement("svg:flowDiv");
100 }
101
102 std::vector<Inkscape::XML::Node *> l;
103
104 for (auto& child: children) {
105 Inkscape::XML::Node* c_repr = nullptr;
106
107 if ( is<SPFlowtspan>(&child) ) {
108 c_repr = child.updateRepr(xml_doc, nullptr, flags);
109 } else if ( is<SPFlowpara>(&child) ) {
110 c_repr = child.updateRepr(xml_doc, nullptr, flags);
111 } else if ( is<SPString>(&child) ) {
112 c_repr = xml_doc->createTextNode(cast<SPString>(&child)->string.c_str());
113 }
114
115 if ( c_repr ) {
116 l.push_back(c_repr);
117 }
118 }
119 for (auto i=l.rbegin();i!=l.rend();++i) {
120 repr->addChild(*i, nullptr);
122 }
123 } else {
124 for (auto& child: children) {
125 if ( is<SPFlowtspan>(&child) ) {
126 child.updateRepr(flags);
127 } else if ( is<SPFlowpara>(&child) ) {
128 child.updateRepr(flags);
129 } else if ( is<SPString>(&child) ) {
130 child.getRepr()->setContent(cast<SPString>(&child)->string.c_str());
131 }
132 }
133 }
134
135 SPItem::write(xml_doc, repr, flags);
136
137 return repr;
138}
139
140
141/*
142 *
143 */
144
147
148SPFlowtspan::~SPFlowtspan() = default;
149
153
154void SPFlowtspan::update(SPCtx *ctx, unsigned int flags) {
155 SPItemCtx *ictx = reinterpret_cast<SPItemCtx *>(ctx);
156 SPItemCtx cctx = *ictx;
157
158 unsigned childflags = flags;
159 if (flags & SP_OBJECT_MODIFIED_FLAG) {
160 childflags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
161 }
162 childflags &= SP_OBJECT_MODIFIED_CASCADE;
163 std::vector<SPObject *> l;
164 for (auto& child: children) {
166 l.push_back(&child);
167 }
168
169 for(auto child:l) {
170 if (childflags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
171 if (is<SPItem>(child)) {
172 SPItem const &chi = *cast<SPItem>(child);
173 cctx.i2doc = chi.transform * ictx->i2doc;
174 cctx.i2vp = chi.transform * ictx->i2vp;
175 child->updateDisplay((SPCtx *)&cctx, childflags);
176 } else {
177 child->updateDisplay(ctx, childflags);
178 }
179 }
180
182 }
183
184 SPItem::update(ctx, flags);
185}
186
187void SPFlowtspan::modified(unsigned int flags) {
188 SPItem::modified(flags);
189
190 if (flags & SP_OBJECT_MODIFIED_FLAG) {
191 flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
192 }
193
194 flags &= SP_OBJECT_MODIFIED_CASCADE;
195 std::vector<SPObject *> l;
196 for (auto& child: children) {
198 l.push_back(&child);
199 }
200
201 for(auto child:l) {
202 if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
203 child->emitModified(flags);
204 }
206 }
207}
208
209
213
214void SPFlowtspan::set(SPAttr key, const gchar* value) {
215 SPItem::set(key, value);
216}
217
219 if ( flags&SP_OBJECT_WRITE_BUILD ) {
220 if ( repr == nullptr ) {
221 repr = xml_doc->createElement("svg:flowSpan");
222 }
223
224 std::vector<Inkscape::XML::Node *> l;
225
226 for (auto& child: children) {
227 Inkscape::XML::Node* c_repr = nullptr;
228
229 if ( is<SPFlowtspan>(&child) ) {
230 c_repr = child.updateRepr(xml_doc, nullptr, flags);
231 } else if ( is<SPFlowpara>(&child) ) {
232 c_repr = child.updateRepr(xml_doc, nullptr, flags);
233 } else if ( is<SPString>(&child) ) {
234 c_repr = xml_doc->createTextNode(cast<SPString>(&child)->string.c_str());
235 }
236
237 if ( c_repr ) {
238 l.push_back(c_repr);
239 }
240 }
241 for (auto i=l.rbegin();i!=l.rend();++i) {
242 repr->addChild(*i, nullptr);
244 }
245 } else {
246 for (auto& child: children) {
247 if ( is<SPFlowtspan>(&child) ) {
248 child.updateRepr(flags);
249 } else if ( is<SPFlowpara>(&child) ) {
250 child.updateRepr(flags);
251 } else if ( is<SPString>(&child) ) {
252 child.getRepr()->setContent(cast<SPString>(&child)->string.c_str());
253 }
254 }
255 }
256
257 SPItem::write(xml_doc, repr, flags);
258
259 return repr;
260}
261
262
263/*
264 *
265 */
268
269SPFlowpara::~SPFlowpara() = default;
270
274
275void SPFlowpara::update(SPCtx *ctx, unsigned int flags) {
276 SPItemCtx *ictx = reinterpret_cast<SPItemCtx *>(ctx);
277 SPItemCtx cctx = *ictx;
278
279 SPItem::update(ctx, flags);
280
281 if (flags & SP_OBJECT_MODIFIED_FLAG) {
282 flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
283 }
284
285 flags &= SP_OBJECT_MODIFIED_CASCADE;
286
287 std::vector<SPObject *> l;
288 for (auto& child: children) {
290 l.push_back(&child);
291 }
292
293 for(auto child:l) {
294 if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
295 if (is<SPItem>(child)) {
296 SPItem const &chi = *cast<SPItem>(child);
297 cctx.i2doc = chi.transform * ictx->i2doc;
298 cctx.i2vp = chi.transform * ictx->i2vp;
299 child->updateDisplay((SPCtx *)&cctx, flags);
300 } else {
301 child->updateDisplay(ctx, flags);
302 }
303 }
305 }
306}
307
308void SPFlowpara::modified(unsigned int flags) {
309 SPItem::modified(flags);
310
311 if (flags & SP_OBJECT_MODIFIED_FLAG) {
312 flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
313 }
314
315 flags &= SP_OBJECT_MODIFIED_CASCADE;
316
317 std::vector<SPObject *> l;
318 for (auto& child: children) {
320 l.push_back(&child);
321 }
322
323 for(auto child:l) {
324 if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
325 child->emitModified(flags);
326 }
328 }
329}
330
331
335
336void SPFlowpara::set(SPAttr key, const gchar* value) {
337 SPItem::set(key, value);
338}
339
341 if ( flags&SP_OBJECT_WRITE_BUILD ) {
342 if ( repr == nullptr ) {
343 repr = xml_doc->createElement("svg:flowPara");
344 }
345
346 std::vector<Inkscape::XML::Node *> l;
347
348 for (auto& child: children) {
349 Inkscape::XML::Node* c_repr = nullptr;
350
351 if ( is<SPFlowtspan>(&child) ) {
352 c_repr = child.updateRepr(xml_doc, nullptr, flags);
353 } else if ( is<SPFlowpara>(&child) ) {
354 c_repr = child.updateRepr(xml_doc, nullptr, flags);
355 } else if ( is<SPString>(&child) ) {
356 c_repr = xml_doc->createTextNode(cast<SPString>(&child)->string.c_str());
357 }
358
359 if ( c_repr ) {
360 l.push_back(c_repr);
361 }
362 }
363
364 for (auto i=l.rbegin();i!=l.rend();++i) {
365 repr->addChild(*i, nullptr);
367 }
368 } else {
369 for (auto& child: children) {
370 if ( is<SPFlowtspan>(&child) ) {
371 child.updateRepr(flags);
372 } else if ( is<SPFlowpara>(&child) ) {
373 child.updateRepr(flags);
374 } else if ( is<SPString>(&child) ) {
375 child.getRepr()->setContent(cast<SPString>(&child)->string.c_str());
376 }
377 }
378 }
379
380 SPItem::write(xml_doc, repr, flags);
381
382 return repr;
383}
384
385
386/*
387 *
388 */
389
392
393SPFlowline::~SPFlowline() = default;
394
398
399void SPFlowline::modified(unsigned int flags) {
400 SPObject::modified(flags);
401
402 if (flags & SP_OBJECT_MODIFIED_FLAG) {
403 flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
404 }
405
406 flags &= SP_OBJECT_MODIFIED_CASCADE;
407}
408
410 if ( flags & SP_OBJECT_WRITE_BUILD ) {
411 if ( repr == nullptr ) {
412 repr = xml_doc->createElement("svg:flowLine");
413 }
414 }
415
416 SPObject::write(xml_doc, repr, flags);
417
418 return repr;
419}
420
421
422/*
423 *
424 */
425
428
430
434
435void SPFlowregionbreak::modified(unsigned int flags) {
436 SPObject::modified(flags);
437
438 if (flags & SP_OBJECT_MODIFIED_FLAG) {
439 flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
440 }
441
442 flags &= SP_OBJECT_MODIFIED_CASCADE;
443}
444
446 if ( flags & SP_OBJECT_WRITE_BUILD ) {
447 if ( repr == nullptr ) {
448 repr = xml_doc->createElement("svg:flowLine");
449 }
450 }
451
452 SPObject::write(xml_doc, repr, flags);
453
454 return repr;
455}
456
457
458/*
459 Local Variables:
460 mode:c++
461 c-file-style:"stroustrup"
462 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
463 indent-tabs-mode:nil
464 fill-column:99
465 End:
466*/
467// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
SPAttr
Definition attributes.h:27
Interface for refcounted XML nodes.
Definition node.h:80
virtual void addChild(Node *child, Node *after)=0
Insert another node as a child of this node.
Typed SVG document implementation.
Definition document.h:101
void set(SPAttr key, char const *value) override
~SPFlowdiv() override
void release() override
void build(SPDocument *document, Inkscape::XML::Node *repr) override
Inkscape::XML::Node * write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override
void modified(unsigned int flags) override
void update(SPCtx *ctx, unsigned int flags) override
~SPFlowline() override
void modified(unsigned int flags) override
void release() override
Inkscape::XML::Node * write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override
void update(SPCtx *ctx, unsigned int flags) override
void build(SPDocument *document, Inkscape::XML::Node *repr) override
~SPFlowpara() override
void modified(unsigned int flags) override
Inkscape::XML::Node * write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override
void release() override
void set(SPAttr key, char const *value) override
void release() override
void modified(unsigned int flags) override
Inkscape::XML::Node * write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override
~SPFlowregionbreak() override
void modified(unsigned int flags) override
void set(SPAttr key, char const *value) override
void update(SPCtx *ctx, unsigned int flags) override
void release() override
void build(SPDocument *document, Inkscape::XML::Node *repr) override
~SPFlowtspan() override
Inkscape::XML::Node * write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override
Base class for visual SVG elements.
Definition sp-item.h:109
void modified(unsigned int flags) override
Definition sp-item.cpp:842
void update(SPCtx *ctx, unsigned int flags) override
Definition sp-item.cpp:779
Inkscape::XML::Node * write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override
Definition sp-item.cpp:850
void set(SPAttr key, char const *value) override
Definition sp-item.cpp:558
void release() override
Definition sp-item.cpp:534
Geom::Affine transform
Definition sp-item.h:138
void build(SPDocument *document, Inkscape::XML::Node *repr) override
Definition sp-item.cpp:511
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
Inkscape::XML::Node * repr
Definition sp-object.h:193
virtual Inkscape::XML::Node * write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags)
virtual void release()
void _requireSVGVersion(unsigned major, unsigned minor)
Definition sp-object.h:719
virtual void modified(unsigned int flags)
ChildrenList children
Definition sp-object.h:907
static R & release(R &r)
Decrements the reference count of a anchored object.
static cairo_user_data_key_t key
Ocnode * child[8]
Definition quantize.cpp:33
TODO: insert short description here.
SPObject * sp_object_unref(SPObject *object, SPObject *owner)
Decrease reference count of object, with possible debugging and finalization.
SPObject * sp_object_ref(SPObject *object, SPObject *owner)
Increase reference count of object, with possible debugging.
TODO: insert short description here.
Interface for XML documents.
Definition document.h:43
virtual Node * createTextNode(char const *content)=0
virtual Node * createElement(char const *name)=0
Unused.
Definition sp-object.h:94
Contains transformations to document/viewport and the viewport size.
Definition sp-item.h:92
Geom::Affine i2doc
Item to document transformation.
Definition sp-item.h:94
Geom::Affine i2vp
Item to viewport transformation.
Definition sp-item.h:100
Interface for XML documents.