Code

* Lots of documentation for the Inkscape::XML namespace
[inkscape.git] / src / xml / repr.h
1 /** @file
2  * @brief C facade to Inkscape::XML::Node
3  */
4 /* Authors:
5  *   Lauris Kaplinski <lauris@kaplinski.com>
6  *
7  * Copyright (C) 1999-2002 authors
8  * Copyright (C) 2000-2002 Ximian, Inc.
9  *
10  * Released under GNU GPL, read the file 'COPYING' for more information
11  */
12  
13 #ifndef __SP_REPR_H__
14 #define __SP_REPR_H__
16 #include <stdio.h>
17 #include <glib/gtypes.h>
18 #include "gc-anchored.h"
20 #include "xml/node.h"
21 #include "xml/document.h"
22 #include "xml/sp-css-attr.h"
23 #include "io/inkscapestream.h"
25 #include <2geom/forward.h>
27 #define SP_SODIPODI_NS_URI "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
28 #define SP_BROKEN_SODIPODI_NS_URI "http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd"
29 #define SP_INKSCAPE_NS_URI "http://www.inkscape.org/namespaces/inkscape"
30 #define SP_XLINK_NS_URI "http://www.w3.org/1999/xlink"
31 #define SP_SVG_NS_URI "http://www.w3.org/2000/svg"
32 #define SP_RDF_NS_URI "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
33 #define SP_CC_NS_URI "http://creativecommons.org/ns#"
34 #define SP_OLD_CC_NS_URI "http://web.resource.org/cc/"
35 #define SP_DC_NS_URI "http://purl.org/dc/elements/1.1/"
37 /* SPXMLNs */
38 char const *sp_xml_ns_uri_prefix(gchar const *uri, gchar const *suggested);
39 char const *sp_xml_ns_prefix_uri(gchar const *prefix);
41 Inkscape::XML::Document *sp_repr_document_new(gchar const *rootname);
43 /* Tree */
44 /// @deprecated Use the equivalent member function Inkscape::XML::Node::parent()
45 inline Inkscape::XML::Node *sp_repr_parent(Inkscape::XML::Node const *repr) {
46     return const_cast<Inkscape::XML::Node *>(repr->parent());
47 }
49 /// @deprecated Use the equivalent member function Inkscape::XML::Node::firstChild()
50 inline Inkscape::XML::Node const *sp_repr_children(Inkscape::XML::Node const *repr) {
51     return ( repr ? repr->firstChild() : NULL );
52 }
54 /// @deprecated Use the equivalent member function Inkscape::XML::Node::firstChild()
55 inline Inkscape::XML::Node *sp_repr_children(Inkscape::XML::Node *repr) {
56     return ( repr ? repr->firstChild() : NULL );
57 }
59 /// @deprecated Use the equivalent member function Inkscape::XML::Node::next()
60 inline Inkscape::XML::Node const *sp_repr_next(Inkscape::XML::Node const *repr) {
61     return ( repr ? repr->next() : NULL );
62 }
64 /// @deprecated Use the equivalent member function Inkscape::XML::Node::next()
65 inline Inkscape::XML::Node *sp_repr_next(Inkscape::XML::Node *repr) {
66     return ( repr ? repr->next() : NULL );
67 }
69 /* IO */
71 Inkscape::XML::Document *sp_repr_read_file(gchar const *filename, gchar const *default_ns);
72 Inkscape::XML::Document *sp_repr_read_mem(gchar const *buffer, int length, gchar const *default_ns);
73 void sp_repr_write_stream (Inkscape::XML::Node *repr, Inkscape::IO::Writer &out,
74                  gint indent_level,  bool add_whitespace, Glib::QueryQuark elide_prefix,
75                                  int inlineattrs, int indent);
76 Inkscape::XML::Document *sp_repr_read_buf (const Glib::ustring &buf, const gchar *default_ns);
77 Glib::ustring sp_repr_save_buf(Inkscape::XML::Document *doc);
78 void sp_repr_save_stream(Inkscape::XML::Document *doc, FILE *to_file, gchar const *default_ns=NULL, bool compress = false);
79 bool sp_repr_save_file(Inkscape::XML::Document *doc, gchar const *filename, gchar const *default_ns=NULL);
81 void sp_repr_print(Inkscape::XML::Node *repr);
83 /* CSS stuff */
85 SPCSSAttr *sp_repr_css_attr_new(void);
86 void sp_repr_css_attr_unref(SPCSSAttr *css);
87 SPCSSAttr *sp_repr_css_attr(Inkscape::XML::Node *repr, gchar const *attr);
88 SPCSSAttr *sp_repr_css_attr_inherited(Inkscape::XML::Node *repr, gchar const *attr);
90 gchar const *sp_repr_css_property(SPCSSAttr *css, gchar const *name, gchar const *defval);
91 void sp_repr_css_set_property(SPCSSAttr *css, gchar const *name, gchar const *value);
92 void sp_repr_css_unset_property(SPCSSAttr *css, gchar const *name);
93 bool sp_repr_css_property_is_unset(SPCSSAttr *css, gchar const *name);
94 double sp_repr_css_double_property(SPCSSAttr *css, gchar const *name, double defval);
96 gchar *sp_repr_css_write_string(SPCSSAttr *css);
97 void sp_repr_css_set(Inkscape::XML::Node *repr, SPCSSAttr *css, gchar const *key);
98 void sp_repr_css_merge(SPCSSAttr *dst, SPCSSAttr *src);
99 void sp_repr_css_attr_add_from_string(SPCSSAttr *css, const gchar *data);
100 void sp_repr_css_change(Inkscape::XML::Node *repr, SPCSSAttr *css, gchar const *key);
101 void sp_repr_css_change_recursive(Inkscape::XML::Node *repr, SPCSSAttr *css, gchar const *key);
103 void sp_repr_css_print(SPCSSAttr *css);
105 /* Utility finctions */
106 /// Remove \a repr from children of its parent node.
107 inline void sp_repr_unparent(Inkscape::XML::Node *repr) {
108     Inkscape::XML::Node *parent=repr->parent();
109     if (parent) {
110         parent->removeChild(repr);
111     }
114 bool sp_repr_is_meta_element(const Inkscape::XML::Node *node);
116 /* Convenience */
117 unsigned sp_repr_get_boolean(Inkscape::XML::Node *repr, gchar const *key, unsigned *val);
118 unsigned sp_repr_get_int(Inkscape::XML::Node *repr, gchar const *key, int *val);
119 unsigned sp_repr_get_double(Inkscape::XML::Node *repr, gchar const *key, double *val);
120 unsigned sp_repr_set_boolean(Inkscape::XML::Node *repr, gchar const *key, unsigned val);
121 unsigned sp_repr_set_int(Inkscape::XML::Node *repr, gchar const *key, int val);
122 unsigned sp_repr_set_css_double(Inkscape::XML::Node *repr, gchar const *key, double val);
123 unsigned sp_repr_set_svg_double(Inkscape::XML::Node *repr, gchar const *key, double val);
124 unsigned sp_repr_set_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point const & val);
125 unsigned sp_repr_get_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point *val);
127 /// \deprecated Use sp_repr_get_double to check for success
128 double sp_repr_get_double_attribute(Inkscape::XML::Node *repr, gchar const *key, double def);
129 /// \deprecated Use sp_repr_get_int to check for success
130 long long int sp_repr_get_int_attribute(Inkscape::XML::Node *repr, gchar const *key, long long int def);
132 int sp_repr_compare_position(Inkscape::XML::Node *first, Inkscape::XML::Node *second);
134 /* Searching */
135 Inkscape::XML::Node *sp_repr_lookup_name(Inkscape::XML::Node *repr,
136                                          gchar const *name,
137                                          gint maxdepth = -1);
138 Inkscape::XML::Node *sp_repr_lookup_child(Inkscape::XML::Node *repr,
139                                           gchar const *key,
140                                           gchar const *value);
143 inline Inkscape::XML::Node *sp_repr_document_first_child(Inkscape::XML::Document const *doc) {
144     return const_cast<Inkscape::XML::Node *>(doc->firstChild());
147 #endif
148 /*
149   Local Variables:
150   mode:c++
151   c-file-style:"stroustrup"
152   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
153   indent-tabs-mode:nil
154   fill-column:99
155   End:
156 */
157 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :