Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
repr.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/* Authors:
6 * Lauris Kaplinski <lauris@kaplinski.com>
7 * Jon A. Cruz <jon@joncruz.org>
8 *
9 * Copyright (C) 1999-2002 authors
10 * Copyright (C) 2000-2002 Ximian, Inc.
11 *
12 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
13 */
14
15#ifndef SEEN_SP_REPR_H
16#define SEEN_SP_REPR_H
17
18#include <vector>
19#include <glibmm/quark.h>
20
21#include "xml/node.h"
22#include "xml/document.h"
23
24#define SP_SODIPODI_NS_URI "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
25#define SP_BROKEN_SODIPODI_NS_URI "http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd"
26#define SP_INKSCAPE_NS_URI "http://www.inkscape.org/namespaces/inkscape"
27#define SP_XLINK_NS_URI "http://www.w3.org/1999/xlink"
28#define SP_SVG_NS_URI "http://www.w3.org/2000/svg"
29#define SP_RDF_NS_URI "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
30#define SP_CC_NS_URI "http://creativecommons.org/ns#"
31#define SP_OLD_CC_NS_URI "http://web.resource.org/cc/"
32#define SP_DC_NS_URI "http://purl.org/dc/elements/1.1/"
33
34class SPCSSAttr;
35class SVGLength;
36
37namespace Inkscape {
38namespace IO {
39class Writer;
40} // namespace IO
41} // namespace Inkscape
42
43namespace Geom {
44class Point;
45}
46
47/* SPXMLNs */
48char const *sp_xml_ns_uri_prefix(char const *uri, char const *suggested);
49char const *sp_xml_ns_prefix_uri(char const *prefix);
50
52
53/* IO */
54
55Inkscape::XML::Document *sp_repr_read_file(char const *filename, char const *default_ns, bool xinclude = false);
56Inkscape::XML::Document *sp_repr_read_mem(char const *buffer, int length, char const *default_ns);
58 int indent_level, bool add_whitespace, Glib::QueryQuark elide_prefix,
59 int inlineattrs, int indent,
60 char const *old_href_base = nullptr,
61 char const *new_href_base = nullptr);
62Glib::ustring sp_repr_write_buf(Inkscape::XML::Node *repr, int indent_level, bool add_whitespace,
63 Glib::QueryQuark elide_prefix, int inlineattrs, int indent,
64 char const *old_href_base = nullptr, char const *new_href_base = nullptr);
65Inkscape::XML::Document *sp_repr_read_buf (const Glib::ustring &buf, const char *default_ns);
67
68// TODO convert to std::string
70 char const *default_ns = nullptr, bool compress = false,
71 char const *old_href_base = nullptr,
72 char const *new_href_base = nullptr);
73
74bool sp_repr_save_file(Inkscape::XML::Document *doc, char const *filename, char const *default_ns=nullptr);
75bool sp_repr_save_rebased_file(Inkscape::XML::Document *doc, char const *filename_utf8,
76 char const *default_ns,
77 char const *old_base, char const *new_base_filename);
78
79
80/* CSS stuff */
81
84SPCSSAttr *sp_repr_css_attr(Inkscape::XML::Node const *repr, char const *attr);
87
88char const *sp_repr_css_property(SPCSSAttr *css, char const *name, char const *defval);
89Glib::ustring sp_repr_css_property(SPCSSAttr *css, Glib::ustring const &name, Glib::ustring const &defval);
90void sp_repr_css_set_property(SPCSSAttr *css, char const *name, char const *value);
93double sp_repr_css_double_property(SPCSSAttr *css, char const *name, double defval);
94void sp_repr_css_set_property_double(SPCSSAttr *css, char const *name, double value);
95void sp_repr_css_set_property_string(SPCSSAttr *css, char const *name, std::string const &value);
96
97void sp_repr_css_write_string(SPCSSAttr *css, Glib::ustring &str);
104
105/* Utility finctions */
108 if (repr) {
110 if (parent) {
111 parent->removeChild(repr);
112 }
113 }
114}
115
117
118//c++-style comparison : returns (bool)(a<b)
121
122// Searching
136 char const *name,
137 int maxdepth = -1);
138
140 char const *name,
141 int maxdepth = -1);
142
143Glib::ustring sp_repr_lookup_content(Inkscape::XML::Node const *repr, gchar const *name, Glib::ustring otherwise = {});
144
145std::vector<Inkscape::XML::Node const *> sp_repr_lookup_name_many(Inkscape::XML::Node const *repr,
146 char const *name,
147 int maxdepth = -1);
148
149// Find an element node using an unique attribute.
151 char const *key,
152 char const *value);
153
154// Find an element node using an unique attribute recursively.
156 char const *key,
157 char const *value);
158
160 char const *key,
161 char const *value);
162
163// Find element nodes using a property value.
164std::vector<Inkscape::XML::Node *> sp_repr_lookup_property_many(Inkscape::XML::Node *repr,
165 Glib::ustring const &property,
166 Glib::ustring const &value,
167 int maxdepth = -1);
168
172
174 return node->parent() != nullptr &&
175 node->parent()->name() != nullptr &&
176 strcmp("svg:defs", node->parent()->name()) == 0;
177}
178
180 return node->attribute("inkscape:groupmode") != nullptr &&
181 strcmp("layer", node->attribute("inkscape:groupmode")) == 0;
182}
183
195template <typename Visitor>
197 if (!visitor(node)) {
198 return;
199 }
201 child != nullptr;
202 child = child->next()) {
204 }
205}
206
218template <typename Visitor>
220 if (!visitor(a, b)) {
221 return;
222 }
223 for (Inkscape::XML::Node *ac = a->firstChild(), *bc = b->firstChild();
224 ac != nullptr && bc != nullptr;
225 ac = ac->next(), bc = bc->next()) {
226 sp_repr_visit_descendants(ac, bc, visitor);
227 }
228}
229
230#endif // SEEN_SP_REPR_H
231/*
232 Local Variables:
233 mode:c++
234 c-file-style:"stroustrup"
235 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
236 indent-tabs-mode:nil
237 fill-column:99
238 End:
239*/
240// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
pair< double, double > Point
Definition parser.cpp:7
This interface and its descendants are for unicode character-oriented output.
Interface for refcounted XML nodes.
Definition node.h:80
void sp_repr_visit_descendants(Inkscape::XML::Node *node, Visitor visitor)
Visit all descendants recursively.
Definition repr.h:196
virtual Node * parent()=0
Get the parent of this node.
Inkscape::XML::Node * sp_repr_lookup_name(Inkscape::XML::Node *repr, char const *name, int maxdepth=-1)
Find an element node with the given name.
virtual char const * name() const =0
Get the name of the element node.
void sp_repr_visit_descendants(Inkscape::XML::Node *a, Inkscape::XML::Node *b, Visitor visitor)
Visit descendants of 2 nodes in parallel.
Definition repr.h:219
virtual Node * firstChild()=0
Get the first child of this node.
virtual char const * attribute(char const *key) const =0
Get the string representation of a node's attribute.
virtual void removeChild(Node *child)=0
Remove a child of this node.
SVG length type.
Definition svg-length.h:22
std::shared_ptr< Css const > css
static char const *const parent
Definition dir-util.cpp:70
Inkscape::XML::Node * node
Various utility functions.
Definition affine.h:22
Inkscape::IO::Writer Writer
Definition odf.h:35
Helper class to stream background task notifications as a series of messages.
static cairo_user_data_key_t key
int buf
Ocnode * child[8]
Definition quantize.cpp:33
void sp_repr_visit_descendants(Inkscape::XML::Node *node, Visitor visitor)
Visit all descendants recursively.
Definition repr.h:196
void sp_repr_css_attr_add_from_string(SPCSSAttr *css, const char *data)
Glib::ustring sp_repr_write_buf(Inkscape::XML::Node *repr, int indent_level, bool add_whitespace, Glib::QueryQuark elide_prefix, int inlineattrs, int indent, char const *old_href_base=nullptr, char const *new_href_base=nullptr)
Definition repr-io.cpp:934
SPCSSAttr * sp_repr_css_attr_new()
Creates an empty SPCSSAttr (a class for manipulating CSS style properties).
Definition repr-css.cpp:67
void sp_repr_css_set(Inkscape::XML::Node *repr, SPCSSAttr *css, char const *key)
void sp_repr_css_change(Inkscape::XML::Node *repr, SPCSSAttr *css, char const *key)
char const * sp_xml_ns_uri_prefix(char const *uri, char const *suggested)
void sp_repr_css_write_string(SPCSSAttr *css, Glib::ustring &str)
Write a style attribute string from a list of properties stored in an SPCSAttr object.
Definition repr-css.cpp:242
void sp_repr_css_merge(SPCSSAttr *dst, SPCSSAttr *src)
Merges two SPCSSAttr's.
Definition repr-css.cpp:298
SPCSSAttr * sp_repr_css_attr(Inkscape::XML::Node const *repr, char const *attr)
char const * sp_repr_css_property(SPCSSAttr *css, char const *name, char const *defval)
char const * sp_xml_ns_prefix_uri(char const *prefix)
bool sp_repr_is_meta_element(const Inkscape::XML::Node *node)
Determine if the node is a 'title', 'desc' or 'metadata' element.
std::vector< Inkscape::XML::Node * > sp_repr_lookup_property_many(Inkscape::XML::Node *repr, Glib::ustring const &property, Glib::ustring const &value, int maxdepth=-1)
bool sp_repr_save_rebased_file(Inkscape::XML::Document *doc, char const *filename_utf8, char const *default_ns, char const *old_base, char const *new_base_filename)
Inkscape::XML::Node * sp_repr_lookup_name(Inkscape::XML::Node *repr, char const *name, int maxdepth=-1)
Find an element node with the given name.
Inkscape::XML::Node * sp_repr_lookup_child(Inkscape::XML::Node *repr, char const *key, char const *value)
void sp_repr_css_attr_unref(SPCSSAttr *css)
Unreferences an SPCSSAttr (will be garbage collected if no references remain).
Definition repr-css.cpp:76
void sp_repr_write_stream(Inkscape::XML::Node *repr, Inkscape::IO::Writer &out, int indent_level, bool add_whitespace, Glib::QueryQuark elide_prefix, int inlineattrs, int indent, char const *old_href_base=nullptr, char const *new_href_base=nullptr)
int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second)
Works for different-parent objects, so long as they have a common ancestor.
SPCSSAttr * sp_repr_css_attr_inherited(Inkscape::XML::Node const *repr, char const *attr)
Glib::ustring sp_repr_save_buf(Inkscape::XML::Document *doc)
Definition repr-io.cpp:631
void sp_repr_css_set_property_string(SPCSSAttr *css, char const *name, std::string const &value)
Set a style property to a standard string.
Definition repr-css.cpp:234
void sp_repr_css_print(SPCSSAttr *css)
Loops through a List of style properties, printing key/value pairs.
Definition repr-css.cpp:285
Inkscape::XML::Document * sp_repr_document_new(char const *rootname)
Returns new document having as first child a node named rootname.
Definition repr.cpp:32
bool sp_repr_css_property_is_unset(SPCSSAttr *css, char const *name)
bool sp_repr_is_def(Inkscape::XML::Node const *node)
Definition repr.h:173
SPCSSAttr * sp_repr_css_attr_unset_all(SPCSSAttr *css)
Return a new SPCSSAttr with all the properties found in the input SPCSSAttr unset.
Definition repr-css.cpp:386
void sp_repr_save_stream(Inkscape::XML::Document *doc, FILE *to_file, char const *default_ns=nullptr, bool compress=false, char const *old_href_base=nullptr, char const *new_href_base=nullptr)
void sp_repr_unparent(Inkscape::XML::Node *repr)
Remove repr from children of its parent node.
Definition repr.h:107
Inkscape::XML::Node * sp_repr_document_first_child(Inkscape::XML::Document const *doc)
Definition repr.h:169
Inkscape::XML::Document * sp_repr_read_mem(char const *buffer, int length, char const *default_ns)
void sp_repr_css_unset_property(SPCSSAttr *css, char const *name)
bool sp_repr_compare_position_bool(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second)
Inkscape::XML::Document * sp_repr_read_file(char const *filename, char const *default_ns, bool xinclude=false)
bool sp_repr_is_layer(Inkscape::XML::Node const *node)
Definition repr.h:179
double sp_repr_css_double_property(SPCSSAttr *css, char const *name, double defval)
Inkscape::XML::Node * sp_repr_lookup_descendant(Inkscape::XML::Node *repr, char const *key, char const *value)
Inkscape::XML::Document * sp_repr_read_buf(const Glib::ustring &buf, const char *default_ns)
std::vector< Inkscape::XML::Node const * > sp_repr_lookup_name_many(Inkscape::XML::Node const *repr, char const *name, int maxdepth=-1)
bool sp_repr_save_file(Inkscape::XML::Document *doc, char const *filename, char const *default_ns=nullptr)
Glib::ustring sp_repr_lookup_content(Inkscape::XML::Node const *repr, gchar const *name, Glib::ustring otherwise={})
void sp_repr_css_change_recursive(Inkscape::XML::Node *repr, SPCSSAttr *css, char const *key)
void sp_repr_css_set_property(SPCSSAttr *css, char const *name, char const *value)
void sp_repr_css_set_property_double(SPCSSAttr *css, char const *name, double value)
static unsigned indent_level
Definition sp-object.cpp:70
static const Point data[]
Interface for XML documents.
Definition document.h:43
Glib::ustring name
Definition toolbars.cpp:55
Interface for XML documents.
Interface for XML nodes.