Code

Remove some old snap code.
[inkscape.git] / src / xml / repr.cpp
1 #define __SP_REPR_C__
3 /** \file
4  * A few non-inline functions of the C facade to Inkscape::XML::Node.
5  */
7 /*
8  * Authors:
9  *   Lauris Kaplinski <lauris@kaplinski.com>
10  *   MenTaLguY <mental@rydia.net>
11  *
12  * Copyright (C) 1999-2003 authors
13  * Copyright (C) 2000-2002 Ximian, Inc.
14  * g++ port Copyright (C) 2003 Nathan Hurst
15  *
16  * Released under GNU GPL, read the file 'COPYING' for more information
17  */
19 #define noREPR_VERBOSE
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include "xml/repr.h"
26 #include "xml/text-node.h"
27 #include "xml/element-node.h"
28 #include "xml/comment-node.h"
29 #include "xml/simple-document.h"
31 using Inkscape::Util::share_string;
33 /// Returns new node.
34 Inkscape::XML::Node *
35 sp_repr_new(gchar const *name)
36 {
37     g_return_val_if_fail(name != NULL, NULL);
38     g_return_val_if_fail(*name != '\0', NULL);
40     return new Inkscape::XML::ElementNode(g_quark_from_string(name));
41 }
43 /// Returns new textnode with content. See Inkscape::XML::TextNode.
44 Inkscape::XML::Node *
45 sp_repr_new_text(gchar const *content)
46 {
47     g_return_val_if_fail(content != NULL, NULL);
48     return new Inkscape::XML::TextNode(share_string(content));
49 }
51 /// Returns new commentnode with comment. See Inkscape::XML::CommentNode.
52 Inkscape::XML::Node *
53 sp_repr_new_comment(gchar const *comment)
54 {
55     g_return_val_if_fail(comment != NULL, NULL);
56     return new Inkscape::XML::CommentNode(share_string(comment));
57 }
59 /// Returns new document having as first child a node named rootname.
60 Inkscape::XML::Document *
61 sp_repr_document_new(char const *rootname)
62 {
63     Inkscape::XML::Document *doc = new Inkscape::XML::SimpleDocument(g_quark_from_static_string("xml"));
64     if (!strcmp(rootname, "svg:svg")) {
65         doc->setAttribute("version", "1.0");
66         doc->setAttribute("standalone", "no");
67         Inkscape::XML::Node *comment = sp_repr_new_comment(" Created with Inkscape (http://www.inkscape.org/) ");
68         doc->appendChild(comment);
69         Inkscape::GC::release(comment);
70     }
72     Inkscape::XML::Node *root = sp_repr_new(rootname);
73     doc->appendChild(root);
74     Inkscape::GC::release(root);
76     return doc;
77 }
79 /// Returns new document having reprs as first child.
80 Inkscape::XML::Document *
81 sp_repr_document_new_list(GSList *reprs)
82 {
83     g_assert(reprs != NULL);
85     Inkscape::XML::Document *doc = sp_repr_document_new("void");
86     doc->removeChild(doc->firstChild());
88     for ( GSList *iter = reprs ; iter ; iter = iter->next ) {
89         Inkscape::XML::Node *repr = (Inkscape::XML::Node *) iter->data;
90         doc->appendChild(repr);
91     }
93     g_assert(sp_repr_document_root(doc) != NULL);
95     return doc;
96 }
98 /*
99   Local Variables:
100   mode:c++
101   c-file-style:"stroustrup"
102   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
103   indent-tabs-mode:nil
104   fill-column:99
105   End:
106 */
107 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :