32 unsigned int uri, prefix;
48# define MAX(a,b) (((a) < (b)) ? (b) : (a))
74 static SPXMLNs defaults[11];
76 defaults[0].uri = g_quark_from_static_string(SP_SODIPODI_NS_URI);
77 defaults[0].prefix = g_quark_from_static_string(
"sodipodi");
78 defaults[0].next = &defaults[1];
80 defaults[1].uri = g_quark_from_static_string(SP_XLINK_NS_URI);
81 defaults[1].prefix = g_quark_from_static_string(
"xlink");
82 defaults[1].next = &defaults[2];
84 defaults[2].uri = g_quark_from_static_string(SP_SVG_NS_URI);
85 defaults[2].prefix = g_quark_from_static_string(
"svg");
86 defaults[2].next = &defaults[3];
88 defaults[3].uri = g_quark_from_static_string(SP_INKSCAPE_NS_URI);
89 defaults[3].prefix = g_quark_from_static_string(
"inkscape");
90 defaults[3].next = &defaults[4];
92 defaults[4].uri = g_quark_from_static_string(SP_RDF_NS_URI);
93 defaults[4].prefix = g_quark_from_static_string(
"rdf");
94 defaults[4].next = &defaults[5];
96 defaults[5].uri = g_quark_from_static_string(SP_CC_NS_URI);
97 defaults[5].prefix = g_quark_from_static_string(
"cc");
98 defaults[5].next = &defaults[6];
100 defaults[6].uri = g_quark_from_static_string(SP_DC_NS_URI);
101 defaults[6].prefix = g_quark_from_static_string(
"dc");
102 defaults[6].next = &defaults[8];
114 defaults[8].uri = g_quark_from_static_string(SP_BROKEN_SODIPODI_NS_URI);
115 defaults[8].prefix = g_quark_from_static_string(
"sodipodi");
116 defaults[8].next = &defaults[9];
121 defaults[9].uri = g_quark_from_static_string(
"http://inkscape.sourceforge.net/DTD/s odipodi-0.dtd");
122 defaults[9].prefix = g_quark_from_static_string(
"sodipodi");
123 defaults[9].next = &defaults[10];
127 defaults[10].uri = g_quark_from_static_string(SP_OLD_CC_NS_URI);
128 defaults[10].prefix = g_quark_from_static_string(
"cc");
129 defaults[10].next =
nullptr;
139 while ((
end = strpbrk(
start,
":/"))) {
152 temp = g_strdup_printf(
"%s%d", new_prefix,
counter++);
164 if (!uri)
return nullptr;
170 GQuark const key = g_quark_from_string(uri);
172 for ( SPXMLNs *iter=
namespaces ; iter ; iter = iter->next ) {
173 if ( iter->uri ==
key ) {
174 prefix = g_quark_to_string(iter->prefix);
183 GQuark const prefix_key=g_quark_from_string(suggested);
187 if (found->prefix != prefix_key) {
198 new_prefix = g_strdup(suggested);
204 ns = g_new(SPXMLNs, 1);
205 g_assert( ns !=
nullptr );
206 ns->uri = g_quark_from_string(uri);
207 ns->prefix = g_quark_from_string(new_prefix);
214 prefix = g_quark_to_string(ns->prefix);
225 if (!prefix)
return nullptr;
231 GQuark const key = g_quark_from_string(prefix);
233 for ( iter =
namespaces ; iter ; iter = iter->next ) {
234 if ( iter->prefix ==
key ) {
235 uri = g_quark_to_string(iter->uri);
263 g_assert(ancestor !=
nullptr);
265 if (ancestor == first) {
267 }
else if (ancestor == second) {
278 if (p1 > p2)
return 1;
279 if (p1 < p2)
return -1;
319 g_return_val_if_fail(repr !=
nullptr, NULL);
321 gchar
const *child_value =
child->attribute(
key);
322 if ( (child_value == value) ||
323 (value && child_value && !strcmp(child_value, value)) )
339 g_return_val_if_fail(repr !=
nullptr, NULL);
341 if ( (repr_value == value) ||
342 (repr_value && value && strcmp(repr_value, value) == 0) ) {
364 g_return_val_if_fail(repr !=
nullptr, NULL);
365 g_return_val_if_fail(
name !=
nullptr, NULL);
367 GQuark const quark = g_quark_from_string(
name);
371 }
else if ( maxdepth != 0 ) {
373 if ( maxdepth == -1 ) {
402 std::vector<Inkscape::XML::Node const *> nodes;
403 std::vector<Inkscape::XML::Node const *> found;
404 g_return_val_if_fail(repr !=
nullptr, nodes);
405 g_return_val_if_fail(
name !=
nullptr, nodes);
407 GQuark const quark = g_quark_from_string(
name);
410 nodes.push_back(repr);
413 if ( maxdepth != 0 ) {
415 if ( maxdepth == -1 ) {
421 nodes.insert(nodes.end(), found.begin(), found.end());
428std::vector<Inkscape::XML::Node *>
430 Glib::ustring
const &value,
int maxdepth )
432 std::vector<Inkscape::XML::Node *> nodes;
433 std::vector<Inkscape::XML::Node *> found;
434 g_return_val_if_fail(repr !=
nullptr, nodes);
438 nodes.push_back(repr);
441 if ( maxdepth != 0 ) {
443 if ( maxdepth == -1 ) {
449 nodes.insert(nodes.end(), found.begin(), found.end());
461 if (
node ==
nullptr)
return false;
464 if (
name ==
nullptr)
return false;
465 if (!std::strcmp(
name,
"svg:title"))
return true;
466 if (!std::strcmp(
name,
"svg:desc"))
return true;
467 if (!std::strcmp(
name,
"svg:metadata"))
return true;
Interface for refcounted XML nodes.
virtual Node * parent()=0
Get the parent of this node.
virtual Node * next()=0
Get the next sibling of this node.
virtual int code() const =0
Get the integer code corresponding to the node's name.
Inkscape::XML::Node * sp_repr_lookup_child(Inkscape::XML::Node *repr, gchar const *key, gchar const *value)
Find an element node using an unique attribute.
virtual char const * name() const =0
Get the name of the element node.
virtual Node * firstChild()=0
Get the first child of this node.
virtual unsigned position() const =0
Get the index of this node in parent's child order.
virtual char const * attribute(char const *key) const =0
Get the string representation of a node's attribute.
virtual char const * content() const =0
Get the content of a text or comment node.
virtual NodeType type() const =0
Get the type of the node.
std::shared_ptr< Css const > css
Inkscape::XML::Node * node
@ ELEMENT_NODE
Regular element node, e.g. <group />.
static cairo_user_data_key_t key
SPCSSAttr * sp_repr_css_attr(Node const *repr, gchar const *attr)
Creates a new SPCSSAttr with one attribute (i.e.
char const * sp_repr_css_property(SPCSSAttr *css, gchar const *name, gchar const *defval)
Returns a character string of the value of a given style property or a default value if the attribute...
Inkscape::XML::Node const * lowest_common_ancestor(Inkscape::XML::Node const *a, Inkscape::XML::Node const *b)
Inkscape::XML::Node const * find_containing_child(Inkscape::XML::Node const *descendant, Inkscape::XML::Node const *ancestor)
TODO: insert short description here.
Inkscape::XML::Node const * sp_repr_lookup_descendant(Inkscape::XML::Node const *repr, gchar const *key, gchar const *value)
Recursive version of sp_repr_lookup_child().
bool sp_repr_is_meta_element(const Inkscape::XML::Node *node)
Determine if the node is a 'title', 'desc' or 'metadata' element.
gchar const * sp_xml_ns_uri_prefix(gchar const *uri, gchar const *suggested)
gchar const * sp_xml_ns_prefix_uri(gchar const *prefix)
static void sp_xml_ns_register_defaults()
static SPXMLNs * namespaces
SPXMLNs.
std::vector< Inkscape::XML::Node const * > sp_repr_lookup_name_many(Inkscape::XML::Node const *repr, gchar const *name, gint maxdepth)
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.
Glib::ustring sp_repr_lookup_content(Inkscape::XML::Node const *repr, gchar const *name, Glib::ustring otherwise)
static char * sp_xml_ns_auto_prefix(char const *uri)
Inkscape::XML::Node const * sp_repr_lookup_name(Inkscape::XML::Node const *repr, gchar const *name, gint maxdepth)
bool sp_repr_compare_position_bool(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second)
std::vector< Inkscape::XML::Node * > sp_repr_lookup_property_many(Inkscape::XML::Node *repr, Glib::ustring const &property, Glib::ustring const &value, int maxdepth)
C facade to Inkscape::XML::Node.