Code

Merge and cleanup of GSoC C++-ification project.
[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  *   Jon A. Cruz <jon@joncruz.org>
7  *
8  * Copyright (C) 1999-2002 authors
9  * Copyright (C) 2000-2002 Ximian, Inc.
10  *
11  * Released under GNU GPL, read the file 'COPYING' for more information
12  */
13  
14 #ifndef SEEN_SP_REPR_H
15 #define SEEN_SP_REPR_H
17 #include <stdio.h>
18 #include <glib/gtypes.h>
19 #include "gc-anchored.h"
21 #include "xml/node.h"
22 #include "xml/document.h"
23 #include "xml/sp-css-attr.h"
24 #include "io/inkscapestream.h"
26 #include <2geom/forward.h>
28 #define SP_SODIPODI_NS_URI "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
29 #define SP_BROKEN_SODIPODI_NS_URI "http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd"
30 #define SP_INKSCAPE_NS_URI "http://www.inkscape.org/namespaces/inkscape"
31 #define SP_XLINK_NS_URI "http://www.w3.org/1999/xlink"
32 #define SP_SVG_NS_URI "http://www.w3.org/2000/svg"
33 #define SP_RDF_NS_URI "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
34 #define SP_CC_NS_URI "http://creativecommons.org/ns#"
35 #define SP_OLD_CC_NS_URI "http://web.resource.org/cc/"
36 #define SP_DC_NS_URI "http://purl.org/dc/elements/1.1/"
38 /* SPXMLNs */
39 char const *sp_xml_ns_uri_prefix(gchar const *uri, gchar const *suggested);
40 char const *sp_xml_ns_prefix_uri(gchar const *prefix);
42 Inkscape::XML::Document *sp_repr_document_new(gchar const *rootname);
44 /* Tree */
45 /// @deprecated Use the equivalent member function Inkscape::XML::Node::parent()
46 inline Inkscape::XML::Node *sp_repr_parent(Inkscape::XML::Node const *repr) {
47     return const_cast<Inkscape::XML::Node *>(repr->parent());
48 }
50 /// @deprecated Use the equivalent member function Inkscape::XML::Node::firstChild()
51 inline Inkscape::XML::Node const *sp_repr_children(Inkscape::XML::Node const *repr) {
52     return ( repr ? repr->firstChild() : NULL );
53 }
55 /// @deprecated Use the equivalent member function Inkscape::XML::Node::firstChild()
56 inline Inkscape::XML::Node *sp_repr_children(Inkscape::XML::Node *repr) {
57     return ( repr ? repr->firstChild() : NULL );
58 }
60 /// @deprecated Use the equivalent member function Inkscape::XML::Node::next()
61 inline Inkscape::XML::Node const *sp_repr_next(Inkscape::XML::Node const *repr) {
62     return ( repr ? repr->next() : NULL );
63 }
65 /// @deprecated Use the equivalent member function Inkscape::XML::Node::next()
66 inline Inkscape::XML::Node *sp_repr_next(Inkscape::XML::Node *repr) {
67     return ( repr ? repr->next() : NULL );
68 }
71 /* IO */
73 Inkscape::XML::Document *sp_repr_read_file(gchar const *filename, gchar const *default_ns);
74 Inkscape::XML::Document *sp_repr_read_mem(gchar const *buffer, int length, gchar const *default_ns);
75 void sp_repr_write_stream(Inkscape::XML::Node *repr, Inkscape::IO::Writer &out,
76                           gint indent_level,  bool add_whitespace, Glib::QueryQuark elide_prefix,
77                           int inlineattrs, int indent,
78                           gchar const *old_href_base = NULL,
79                           gchar const *new_href_base = NULL);
80 Inkscape::XML::Document *sp_repr_read_buf (const Glib::ustring &buf, const gchar *default_ns);
81 Glib::ustring sp_repr_save_buf(Inkscape::XML::Document *doc);
82 void sp_repr_save_stream(Inkscape::XML::Document *doc, FILE *to_file,
83                          gchar const *default_ns = NULL, bool compress = false,
84                          gchar const *old_href_base = NULL,
85                          gchar const *new_href_base = NULL);
86 bool sp_repr_save_file(Inkscape::XML::Document *doc, gchar const *filename, gchar const *default_ns=NULL);
87 bool sp_repr_save_rebased_file(Inkscape::XML::Document *doc, gchar const *filename_utf8,
88                                gchar const *default_ns,
89                                gchar const *old_base, gchar const *new_base_filename);
92 /* CSS stuff */
94 SPCSSAttr *sp_repr_css_attr_new(void);
95 void sp_repr_css_attr_unref(SPCSSAttr *css);
96 SPCSSAttr *sp_repr_css_attr(Inkscape::XML::Node *repr, gchar const *attr);
97 SPCSSAttr *sp_repr_css_attr_inherited(Inkscape::XML::Node *repr, gchar const *attr);
99 gchar const *sp_repr_css_property(SPCSSAttr *css, gchar const *name, gchar const *defval);
100 void sp_repr_css_set_property(SPCSSAttr *css, gchar const *name, gchar const *value);
101 void sp_repr_css_unset_property(SPCSSAttr *css, gchar const *name);
102 bool sp_repr_css_property_is_unset(SPCSSAttr *css, gchar const *name);
103 double sp_repr_css_double_property(SPCSSAttr *css, gchar const *name, double defval);
105 gchar *sp_repr_css_write_string(SPCSSAttr *css);
106 void sp_repr_css_set(Inkscape::XML::Node *repr, SPCSSAttr *css, gchar const *key);
107 void sp_repr_css_merge(SPCSSAttr *dst, SPCSSAttr *src);
108 void sp_repr_css_attr_add_from_string(SPCSSAttr *css, const gchar *data);
109 void sp_repr_css_change(Inkscape::XML::Node *repr, SPCSSAttr *css, gchar const *key);
110 void sp_repr_css_change_recursive(Inkscape::XML::Node *repr, SPCSSAttr *css, gchar const *key);
112 void sp_repr_css_print(SPCSSAttr *css);
114 /* Utility finctions */
115 /// Remove \a repr from children of its parent node.
116 inline void sp_repr_unparent(Inkscape::XML::Node *repr) {
117     Inkscape::XML::Node *parent=repr->parent();
118     if (parent) {
119         parent->removeChild(repr);
120     }
123 bool sp_repr_is_meta_element(const Inkscape::XML::Node *node);
125 /* Convenience */
126 unsigned sp_repr_get_boolean(Inkscape::XML::Node *repr, gchar const *key, unsigned *val);
127 unsigned sp_repr_get_int(Inkscape::XML::Node *repr, gchar const *key, int *val);
128 unsigned sp_repr_get_double(Inkscape::XML::Node *repr, gchar const *key, double *val);
129 unsigned sp_repr_set_boolean(Inkscape::XML::Node *repr, gchar const *key, unsigned val);
130 unsigned sp_repr_set_int(Inkscape::XML::Node *repr, gchar const *key, int val);
131 unsigned sp_repr_set_css_double(Inkscape::XML::Node *repr, gchar const *key, double val);
132 unsigned sp_repr_set_svg_double(Inkscape::XML::Node *repr, gchar const *key, double val);
133 unsigned sp_repr_set_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point const & val);
134 unsigned sp_repr_get_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point *val);
136 /// \deprecated Use sp_repr_get_double to check for success
137 double sp_repr_get_double_attribute(Inkscape::XML::Node *repr, gchar const *key, double def);
138 /// \deprecated Use sp_repr_get_int to check for success
139 long long int sp_repr_get_int_attribute(Inkscape::XML::Node *repr, gchar const *key, long long int def);
141 int sp_repr_compare_position(Inkscape::XML::Node const *first, Inkscape::XML::Node const *second);
143 // Searching
144 /**
145  * @brief Find an element node with the given name
146  *
147  * This function searches the descendants of the specified node depth-first for
148  * the first XML node with the specified name.
149  *
150  * @param repr The node to start from
151  * @param name The name of the element node to find
152  * @param maxdepth Maximum search depth, or -1 for an unlimited depth
153  * @return  A pointer to the matching Inkscape::XML::Node
154  * @relatesalso Inkscape::XML::Node
155  */
156 Inkscape::XML::Node *sp_repr_lookup_name(Inkscape::XML::Node *repr,
157                                          gchar const *name,
158                                          gint maxdepth = -1);
160 Inkscape::XML::Node const *sp_repr_lookup_name(Inkscape::XML::Node const *repr,
161                                                gchar const *name,
162                                                gint maxdepth = -1);
164 Inkscape::XML::Node *sp_repr_lookup_child(Inkscape::XML::Node *repr,
165                                           gchar const *key,
166                                           gchar const *value);
169 inline Inkscape::XML::Node *sp_repr_document_first_child(Inkscape::XML::Document const *doc) {
170     return const_cast<Inkscape::XML::Node *>(doc->firstChild());
173 #endif // SEEN_SP_REPR_H
174 /*
175   Local Variables:
176   mode:c++
177   c-file-style:"stroustrup"
178   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
179   indent-tabs-mode:nil
180   fill-column:99
181   End:
182 */
183 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :