diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2011-09-08 14:27:40 +0000 |
|---|---|---|
| committer | tavmjong-free <tavmjong@free.fr> | 2011-09-08 14:27:40 +0000 |
| commit | 8a73582fd88bffa4e219dfce758a930b43c06a98 (patch) | |
| tree | 625d3418f77eb5db1aa913f522773ed0f4bd4f55 /src | |
| parent | Obey to dont-scale-strokewidth preference, even when scaling one dimension to... (diff) | |
| download | inkscape-8a73582fd88bffa4e219dfce758a930b43c06a98.tar.gz inkscape-8a73582fd88bffa4e219dfce758a930b43c06a98.zip | |
Preserve CDATA sections on output.
(bzr r10625)
Diffstat (limited to 'src')
| -rw-r--r-- | src/xml/document.h | 1 | ||||
| -rw-r--r-- | src/xml/repr-io.cpp | 12 | ||||
| -rw-r--r-- | src/xml/simple-document.cpp | 4 | ||||
| -rw-r--r-- | src/xml/simple-document.h | 4 | ||||
| -rw-r--r-- | src/xml/text-node.h | 13 |
5 files changed, 30 insertions, 4 deletions
diff --git a/src/xml/document.h b/src/xml/document.h index 98cc0522e..3bf0a63a6 100644 --- a/src/xml/document.h +++ b/src/xml/document.h @@ -92,6 +92,7 @@ public: */ virtual Node *createElement(char const *name)=0; virtual Node *createTextNode(char const *content)=0; + virtual Node *createTextNode(char const *content, bool is_CData)=0; virtual Node *createComment(char const *content)=0; virtual Node *createPI(char const *target, char const *content)=0; /*@}*/ diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp index 2a0bb6ce8..365415488 100644 --- a/src/xml/repr-io.cpp +++ b/src/xml/repr-io.cpp @@ -24,6 +24,7 @@ #include "xml/attribute-record.h" #include "xml/rebase-hrefs.h" #include "xml/simple-document.h" +#include "xml/text-node.h" #include "io/sys.h" #include "io/uristream.h" @@ -497,7 +498,9 @@ sp_repr_svg_read_node (Document *xml_doc, xmlNodePtr node, const gchar *default_ return NULL; // we do not preserve all-whitespace nodes unless we are asked to } - return xml_doc->createTextNode(reinterpret_cast<gchar *>(node->content)); + // We keep track of original node type so that CDATA sections are preserved on output. + return xml_doc->createTextNode(reinterpret_cast<gchar *>(node->content), + node->type == XML_CDATA_SECTION_NODE ); } if (node->type == XML_COMMENT_NODE) { @@ -849,7 +852,12 @@ void sp_repr_write_stream( Node *repr, Writer &out, gint indent_level, { switch (repr->type()) { case Inkscape::XML::TEXT_NODE: { - repr_quote_write( out, repr->content() ); + if( dynamic_cast<const Inkscape::XML::TextNode *>(repr)->is_CData() ) { + // Preserve CDATA sections, not converting '&' to &, etc. + out.printf( "<![CDATA[%s]]>", repr->content() ); + } else { + repr_quote_write( out, repr->content() ); + } break; } case Inkscape::XML::COMMENT_NODE: { diff --git a/src/xml/simple-document.cpp b/src/xml/simple-document.cpp index 2807133af..0287c4458 100644 --- a/src/xml/simple-document.cpp +++ b/src/xml/simple-document.cpp @@ -58,6 +58,10 @@ Node *SimpleDocument::createTextNode(char const *content) { return new TextNode(Util::share_string(content), this); } +Node *SimpleDocument::createTextNode(char const *content, bool const is_CData) { + return new TextNode(Util::share_string(content), this, is_CData); +} + Node *SimpleDocument::createComment(char const *content) { return new CommentNode(Util::share_string(content), this); } diff --git a/src/xml/simple-document.h b/src/xml/simple-document.h index 8a37c577c..ff1d94b0c 100644 --- a/src/xml/simple-document.h +++ b/src/xml/simple-document.h @@ -31,7 +31,7 @@ class SimpleDocument : public SimpleNode, public: explicit SimpleDocument() : SimpleNode(g_quark_from_static_string("xml"), this), - _in_transaction(false) {} + _in_transaction(false), _is_CData(false) {} NodeType type() const { return Inkscape::XML::DOCUMENT_NODE; } @@ -44,6 +44,7 @@ public: Node *createElement(char const *name); Node *createTextNode(char const *content); + Node *createTextNode(char const *content, bool const is_CData); Node *createComment(char const *content); Node *createPI(char const *target, char const *content); @@ -76,6 +77,7 @@ protected: private: bool _in_transaction; LogBuilder _log_builder; + bool _is_CData; }; } diff --git a/src/xml/text-node.h b/src/xml/text-node.h index b0b7c884b..2fabd6953 100644 --- a/src/xml/text-node.h +++ b/src/xml/text-node.h @@ -30,14 +30,25 @@ struct TextNode : public SimpleNode { : SimpleNode(g_quark_from_static_string("string"), doc) { setContent(content); + _is_CData = false; + } + TextNode(Util::ptr_shared<char> content, Document *doc, bool is_CData) + : SimpleNode(g_quark_from_static_string("string"), doc) + { + setContent(content); + _is_CData = is_CData; } TextNode(TextNode const &other, Document *doc) - : SimpleNode(other, doc) {} + : SimpleNode(other, doc) { + _is_CData = other._is_CData; + } Inkscape::XML::NodeType type() const { return Inkscape::XML::TEXT_NODE; } + bool is_CData() const { return _is_CData; } protected: SimpleNode *_duplicate(Document* doc) const { return new TextNode(*this, doc); } + bool _is_CData; }; } |
