Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
sp-defs.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * SVG <defs> implementation
4 *
5 * Authors:
6 * Lauris Kaplinski <lauris@kaplinski.com>
7 * Jon A. Cruz <jon@joncruz.org>
8 * Abhishek Sharma
9 *
10 * Copyright (C) 2000-2002 authors
11 *
12 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
13 */
14
15/*
16 * fixme: We should really check childrens validity - currently everything
17 * flips in
18 */
19
20#include "sp-defs.h"
21
22#include "attributes.h" // for SPAttr
23#include "object/sp-object.h" // for SPObject, sp_obj...
24#include "xml/document.h" // for Document
25#include "xml/node.h" // for Node
26
27class SPDocument;
28
31
32SPDefs::~SPDefs() = default;
33
38
42
43void SPDefs::update(SPCtx *ctx, guint flags) {
44 if (flags & SP_OBJECT_MODIFIED_FLAG) {
45 flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
46 }
47
48 flags &= SP_OBJECT_MODIFIED_CASCADE;
49 std::vector<SPObject*> l(this->childList(true));
50 for(auto child : l){
51 if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
52 child->updateDisplay(ctx, flags);
53 }
55 }
56}
57
58void SPDefs::modified(unsigned int flags) {
59 if (flags & SP_OBJECT_MODIFIED_FLAG) {
60 flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
61 }
62
63 flags &= SP_OBJECT_MODIFIED_CASCADE;
64 std::vector<SPObject *> l;
65 for (auto& child: children) {
67 l.push_back(&child);
68 }
69
70 for (auto child:l) {
71 if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
72 child->emitModified(flags);
73 }
75 }
76}
77
79 if (flags & SP_OBJECT_WRITE_BUILD) {
80
81 if (!repr) {
82 repr = xml_doc->createElement("svg:defs");
83 }
84
85 std::vector<Inkscape::XML::Node *> l;
86 for (auto& child: children) {
87 Inkscape::XML::Node *crepr = child.updateRepr(xml_doc, nullptr, flags);
88 if (crepr) {
89 l.push_back(crepr);
90 }
91 }
92 for (auto i=l.rbegin();i!=l.rend();++i) {
93 repr->addChild(*i, nullptr);
95 }
96 } else {
97 for (auto& child: children) {
98 child.updateRepr(flags);
99 }
100 }
101
102 SPObject::write(xml_doc, repr, flags);
103
104 return repr;
105}
106
107/*
108 Local Variables:
109 mode:c++
110 c-file-style:"stroustrup"
111 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
112 indent-tabs-mode:nil
113 fill-column:99
114 End:
115*/
116// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Lookup dictionary for attributes/properties.
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.
void release() override
Definition sp-defs.cpp:39
Inkscape::XML::Node * write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override
Definition sp-defs.cpp:78
~SPDefs() override
void modified(unsigned int flags) override
Definition sp-defs.cpp:58
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
Definition sp-defs.cpp:34
SPDefs()
Definition sp-defs.cpp:29
void update(SPCtx *ctx, unsigned int flags) override
Definition sp-defs.cpp:43
Typed SVG document implementation.
Definition document.h:101
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
std::vector< SPObject * > childList(bool add_ref, Action action=ActionGeneral)
Retrieves the children as a std vector object, optionally ref'ing the children in the process,...
virtual Inkscape::XML::Node * write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags)
virtual void release()
void readAttr(char const *key)
Read value of key attribute from XML node into object.
virtual void build(SPDocument *doc, Inkscape::XML::Node *repr)
ChildrenList children
Definition sp-object.h:907
static R & release(R &r)
Decrements the reference count of a anchored object.
Ocnode * child[8]
Definition quantize.cpp:33
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.
Interface for XML documents.
Definition document.h:43
virtual Node * createElement(char const *name)=0
Unused.
Definition sp-object.h:94
Interface for XML documents.
Interface for XML nodes.