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 */
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 }
70 /* IO */
72 Inkscape::XML::Document *sp_repr_read_file(gchar const *filename, gchar const *default_ns);
73 Inkscape::XML::Document *sp_repr_read_mem(gchar const *buffer, int length, gchar const *default_ns);
74 void sp_repr_write_stream(Inkscape::XML::Node *repr, Inkscape::IO::Writer &out,
75 gint indent_level, bool add_whitespace, Glib::QueryQuark elide_prefix,
76 int inlineattrs, int indent,
77 gchar const *old_href_base = NULL,
78 gchar const *new_href_base = NULL);
79 Inkscape::XML::Document *sp_repr_read_buf (const Glib::ustring &buf, const gchar *default_ns);
80 Glib::ustring sp_repr_save_buf(Inkscape::XML::Document *doc);
81 void sp_repr_save_stream(Inkscape::XML::Document *doc, FILE *to_file,
82 gchar const *default_ns = NULL, bool compress = false,
83 gchar const *old_href_base = NULL,
84 gchar const *new_href_base = NULL);
85 bool sp_repr_save_file(Inkscape::XML::Document *doc, gchar const *filename, gchar const *default_ns=NULL);
86 bool sp_repr_save_rebased_file(Inkscape::XML::Document *doc, gchar const *filename_utf8,
87 gchar const *default_ns,
88 gchar const *old_base, gchar const *new_base_filename);
91 /* CSS stuff */
93 SPCSSAttr *sp_repr_css_attr_new(void);
94 void sp_repr_css_attr_unref(SPCSSAttr *css);
95 SPCSSAttr *sp_repr_css_attr(Inkscape::XML::Node *repr, gchar const *attr);
96 SPCSSAttr *sp_repr_css_attr_inherited(Inkscape::XML::Node *repr, gchar const *attr);
98 gchar const *sp_repr_css_property(SPCSSAttr *css, gchar const *name, gchar const *defval);
99 void sp_repr_css_set_property(SPCSSAttr *css, gchar const *name, gchar const *value);
100 void sp_repr_css_unset_property(SPCSSAttr *css, gchar const *name);
101 bool sp_repr_css_property_is_unset(SPCSSAttr *css, gchar const *name);
102 double sp_repr_css_double_property(SPCSSAttr *css, gchar const *name, double defval);
104 gchar *sp_repr_css_write_string(SPCSSAttr *css);
105 void sp_repr_css_set(Inkscape::XML::Node *repr, SPCSSAttr *css, gchar const *key);
106 void sp_repr_css_merge(SPCSSAttr *dst, SPCSSAttr *src);
107 void sp_repr_css_attr_add_from_string(SPCSSAttr *css, const gchar *data);
108 void sp_repr_css_change(Inkscape::XML::Node *repr, SPCSSAttr *css, gchar const *key);
109 void sp_repr_css_change_recursive(Inkscape::XML::Node *repr, SPCSSAttr *css, gchar const *key);
111 void sp_repr_css_print(SPCSSAttr *css);
113 /* Utility finctions */
114 /// Remove \a repr from children of its parent node.
115 inline void sp_repr_unparent(Inkscape::XML::Node *repr) {
116 Inkscape::XML::Node *parent=repr->parent();
117 if (parent) {
118 parent->removeChild(repr);
119 }
120 }
122 bool sp_repr_is_meta_element(const Inkscape::XML::Node *node);
124 /* Convenience */
125 unsigned sp_repr_get_boolean(Inkscape::XML::Node *repr, gchar const *key, unsigned *val);
126 unsigned sp_repr_get_int(Inkscape::XML::Node *repr, gchar const *key, int *val);
127 unsigned sp_repr_get_double(Inkscape::XML::Node *repr, gchar const *key, double *val);
128 unsigned sp_repr_set_boolean(Inkscape::XML::Node *repr, gchar const *key, unsigned val);
129 unsigned sp_repr_set_int(Inkscape::XML::Node *repr, gchar const *key, int val);
130 unsigned sp_repr_set_css_double(Inkscape::XML::Node *repr, gchar const *key, double val);
131 unsigned sp_repr_set_svg_double(Inkscape::XML::Node *repr, gchar const *key, double val);
132 unsigned sp_repr_set_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point const & val);
133 unsigned sp_repr_get_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point *val);
135 /// \deprecated Use sp_repr_get_double to check for success
136 double sp_repr_get_double_attribute(Inkscape::XML::Node *repr, gchar const *key, double def);
137 /// \deprecated Use sp_repr_get_int to check for success
138 long long int sp_repr_get_int_attribute(Inkscape::XML::Node *repr, gchar const *key, long long int def);
140 int sp_repr_compare_position(Inkscape::XML::Node *first, Inkscape::XML::Node *second);
142 /* Searching */
143 Inkscape::XML::Node *sp_repr_lookup_name(Inkscape::XML::Node *repr,
144 gchar const *name,
145 gint maxdepth = -1);
146 Inkscape::XML::Node *sp_repr_lookup_child(Inkscape::XML::Node *repr,
147 gchar const *key,
148 gchar const *value);
151 inline Inkscape::XML::Node *sp_repr_document_first_child(Inkscape::XML::Document const *doc) {
152 return const_cast<Inkscape::XML::Node *>(doc->firstChild());
153 }
155 #endif
156 /*
157 Local Variables:
158 mode:c++
159 c-file-style:"stroustrup"
160 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
161 indent-tabs-mode:nil
162 fill-column:99
163 End:
164 */
165 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :