diff options
| author | MenTaLguY <mental@rydia.net> | 2008-03-07 22:18:56 +0000 |
|---|---|---|
| committer | mental <mental@users.sourceforge.net> | 2008-03-07 22:18:56 +0000 |
| commit | 31acc450aa0320ab82f5075adf8afbcae0763e6d (patch) | |
| tree | ef45a9eeb5a7baa754176307396a2837bca879e0 /src/xml | |
| parent | Fix #include (diff) | |
| download | inkscape-31acc450aa0320ab82f5075adf8afbcae0763e6d.tar.gz inkscape-31acc450aa0320ab82f5075adf8afbcae0763e6d.zip | |
add basic support for preserving processing instructions in the AST
(bzr r4987)
Diffstat (limited to 'src/xml')
| -rw-r--r-- | src/xml/Makefile_insert | 1 | ||||
| -rw-r--r-- | src/xml/document.h | 1 | ||||
| -rw-r--r-- | src/xml/node.h | 3 | ||||
| -rw-r--r-- | src/xml/pi-node.h | 52 | ||||
| -rw-r--r-- | src/xml/repr-io.cpp | 13 | ||||
| -rw-r--r-- | src/xml/simple-document.cpp | 5 | ||||
| -rw-r--r-- | src/xml/simple-document.h | 1 |
7 files changed, 71 insertions, 5 deletions
diff --git a/src/xml/Makefile_insert b/src/xml/Makefile_insert index 0a95a2062..ac7b03751 100644 --- a/src/xml/Makefile_insert +++ b/src/xml/Makefile_insert @@ -26,6 +26,7 @@ xml_libspxml_a_SOURCES = \ xml/log-builder.h \ xml/node-fns.cpp \ xml/node-fns.h \ + xml/pi-node.h \ xml/repr-io.cpp \ xml/repr-sorting.cpp \ xml/repr-sorting.h \ diff --git a/src/xml/document.h b/src/xml/document.h index de9164aa2..5065092d0 100644 --- a/src/xml/document.h +++ b/src/xml/document.h @@ -37,6 +37,7 @@ public: virtual Node *createElement(char const *name)=0; virtual Node *createTextNode(char const *content)=0; virtual Node *createComment(char const *content)=0; + virtual Node *createPI(char const *target, char const *content)=0; }; } diff --git a/src/xml/node.h b/src/xml/node.h index 997f3ccda..ab7e2ba2f 100644 --- a/src/xml/node.h +++ b/src/xml/node.h @@ -31,7 +31,8 @@ enum NodeType { DOCUMENT_NODE, ELEMENT_NODE, TEXT_NODE, - COMMENT_NODE + COMMENT_NODE, + PI_NODE }; // careful; GC::Anchored should only appear once in the inheritance diff --git a/src/xml/pi-node.h b/src/xml/pi-node.h new file mode 100644 index 000000000..c3f84b636 --- /dev/null +++ b/src/xml/pi-node.h @@ -0,0 +1,52 @@ +/* + * Inkscape::XML::PINode - simple XML comment implementation + * + * Copyright 2004-2005 MenTaLguY <mental@rydia.net> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * See the file COPYING for details. + * + */ + +#ifndef SEEN_INKSCAPE_XML_PI_NODE_H +#define SEEN_INKSCAPE_XML_PI_NODE_H + +#include <glib/gquark.h> +#include "xml/simple-node.h" + +namespace Inkscape { + +namespace XML { + +struct PINode : public SimpleNode { + explicit PINode(GQuark target, Util::ptr_shared<char> content) + : SimpleNode(target) + { + setContent(content); + } + + Inkscape::XML::NodeType type() const { return Inkscape::XML::PI_NODE; } + +protected: + SimpleNode *_duplicate(Document* doc) const { return new PINode(*this); } +}; + +} + +} + +#endif +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp index 28e7c4f21..26537d750 100644 --- a/src/xml/repr-io.cpp +++ b/src/xml/repr-io.cpp @@ -395,10 +395,10 @@ sp_repr_do_read (xmlDocPtr doc, const gchar *default_ns) root = NULL; break; } - } else if ( node->type == XML_COMMENT_NODE ) { - Node *comment=sp_repr_svg_read_node(rdoc, node, default_ns, prefix_map); - rdoc->appendChild(comment); - Inkscape::GC::release(comment); + } else if ( node->type == XML_COMMENT_NODE || node->type == XML_PI_NODE ) { + Node *repr=sp_repr_svg_read_node(rdoc, node, default_ns, prefix_map); + rdoc->appendChild(repr); + Inkscape::GC::release(repr); } } @@ -463,6 +463,9 @@ sp_repr_svg_read_node (Document *xml_doc, xmlNodePtr node, const gchar *default_ if (node->type == XML_COMMENT_NODE) return xml_doc->createComment((const gchar *)node->content); + if (node->type == XML_PI_NODE) + return xml_doc->createPI((const gchar *)node->name, (const gchar *)node->content); + if (node->type == XML_ENTITY_DECL) return NULL; sp_repr_qualified_name (c, 256, node->ns, node->name, default_ns, prefix_map); @@ -717,6 +720,8 @@ sp_repr_write_stream (Node *repr, Writer &out, gint indent_level, repr_quote_write (out, repr->content()); } else if (repr->type() == Inkscape::XML::COMMENT_NODE) { out.printf( "<!--%s-->", repr->content() ); + } else if (repr->type() == Inkscape::XML::PI_NODE) { + out.printf( "<?%s %s?>", repr->name(), repr->content() ); } else if (repr->type() == Inkscape::XML::ELEMENT_NODE) { sp_repr_write_stream_element(repr, out, indent_level, add_whitespace, elide_prefix, repr->attributeList(), inlineattrs, indent); } else { diff --git a/src/xml/simple-document.cpp b/src/xml/simple-document.cpp index 30e74a455..d0aa31939 100644 --- a/src/xml/simple-document.cpp +++ b/src/xml/simple-document.cpp @@ -19,6 +19,7 @@ #include "xml/element-node.h" #include "xml/text-node.h" #include "xml/comment-node.h" +#include "xml/pi-node.h" namespace Inkscape { @@ -65,6 +66,10 @@ Node *SimpleDocument::createComment(char const *content) { return new CommentNode(Util::share_string(content)); } +Node *SimpleDocument::createPI(char const *target, char const *content) { + return new PINode(g_quark_from_string(target), Util::share_string(content)); +} + void SimpleDocument::notifyChildAdded(Node &parent, Node &child, Node *prev) diff --git a/src/xml/simple-document.h b/src/xml/simple-document.h index 17e283f2a..cadda36cb 100644 --- a/src/xml/simple-document.h +++ b/src/xml/simple-document.h @@ -49,6 +49,7 @@ public: Node *createElement(char const *name); Node *createTextNode(char const *content); Node *createComment(char const *content); + Node *createPI(char const *target, char const *content); void notifyChildAdded(Node &parent, Node &child, Node *prev); |
