From a4d0a358424440128cd4c4fb2915ccc4b86f4587 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Thu, 5 May 2011 23:21:51 -0700 Subject: Adding initial cut of resource manager. (bzr r10198) --- src/xml/repr-io.cpp | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'src/xml/repr-io.cpp') diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp index 5f7654ba8..2a0bb6ce8 100644 --- a/src/xml/repr-io.cpp +++ b/src/xml/repr-io.cpp @@ -52,6 +52,7 @@ static void sp_repr_write_stream_root_element(Node *repr, Writer &out, int inlineattrs, int indent, gchar const *old_href_abs_base, gchar const *new_href_abs_base); + static void sp_repr_write_stream_element(Node *repr, Writer &out, gint indent_level, bool add_whitespace, Glib::QueryQuark elide_prefix, @@ -644,7 +645,7 @@ sp_repr_save_rebased_file(Document *doc, gchar const *const filename, gchar cons return false; } - gchar *old_href_abs_base = NULL; + std::string old_href_abs_base; gchar *new_href_abs_base = NULL; if (for_filename) { old_href_abs_base = calc_abs_doc_base(old_base); @@ -662,9 +663,8 @@ sp_repr_save_rebased_file(Document *doc, gchar const *const filename, gchar cons * to using sodipodi:absref instead of the xlink:href value, * then we should do `if streq() { free them and set both to NULL; }'. */ } - sp_repr_save_stream(doc, file, default_ns, compress, old_href_abs_base, new_href_abs_base); + sp_repr_save_stream(doc, file, default_ns, compress, old_href_abs_base.c_str(), new_href_abs_base); - g_free(old_href_abs_base); g_free(new_href_abs_base); if (fclose (file) != 0) { @@ -879,17 +879,16 @@ void sp_repr_write_stream( Node *repr, Writer &out, gint indent_level, } -static void -sp_repr_write_stream_element (Node * repr, Writer & out, gint indent_level, - bool add_whitespace, - Glib::QueryQuark elide_prefix, - List attributes, - int inlineattrs, int indent, - gchar const *const old_href_base, - gchar const *const new_href_base) +void sp_repr_write_stream_element( Node * repr, Writer & out, + gint indent_level, bool add_whitespace, + Glib::QueryQuark elide_prefix, + List attributes, + int inlineattrs, int indent, + gchar const *old_href_base, + gchar const *new_href_base ) { - Node *child; - bool loose; + Node *child = 0; + bool loose = false; g_return_if_fail (repr != NULL); @@ -921,6 +920,28 @@ sp_repr_write_stream_element (Node * repr, Writer & out, gint indent_level, add_whitespace = false; } + + { + GQuark const href_key = g_quark_from_static_string("xlink:href"); + GQuark const absref_key = g_quark_from_static_string("sodipodi:absref"); + + gchar const *xxHref = 0; + gchar const *xxAbsref = 0; + for ( List ai(attributes); ai; ++ai ) { + if ( ai->key == href_key ) { + xxHref = ai->value; + } else if ( ai->key == absref_key ) { + xxAbsref = ai->value; + } + } + + // Might add a special case for absref but no href. + if ( old_href_base && new_href_base && xxHref ) { + //g_message("href rebase test with [%s] and [%s]", xxHref, xxAbsref); + //std::string newOne = rebase_href_attrs( old_href_base, new_href_base, xxHref, xxAbsref ); + } + } + for ( List iter = rebase_href_attrs(old_href_base, new_href_base, attributes); iter ; ++iter ) -- cgit v1.2.3 From 8a73582fd88bffa4e219dfce758a930b43c06a98 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 8 Sep 2011 16:27:40 +0200 Subject: Preserve CDATA sections on output. (bzr r10625) --- src/xml/repr-io.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/xml/repr-io.cpp') 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(node->content)); + // We keep track of original node type so that CDATA sections are preserved on output. + return xml_doc->createTextNode(reinterpret_cast(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(repr)->is_CData() ) { + // Preserve CDATA sections, not converting '&' to &, etc. + out.printf( "", repr->content() ); + } else { + repr_quote_write( out, repr->content() ); + } break; } case Inkscape::XML::COMMENT_NODE: { -- cgit v1.2.3 From 771029025214cffd0bc9783656c29e08ad208743 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 29 Nov 2011 12:27:10 +0100 Subject: Add possibility to check validity of attributes and usefulness of properties. This code adds the ability to check for every elment in an SVG document if its attributes are valid and the styling properties are useful. Options under the SVG Output section of the Inkscape Preferences dialog control what should be checked when, and what actions should be taken if invalid attributes or non-useful properties are found. (bzr r10753) --- src/xml/repr-io.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/xml/repr-io.cpp') diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp index 365415488..39eb2637a 100644 --- a/src/xml/repr-io.cpp +++ b/src/xml/repr-io.cpp @@ -33,6 +33,8 @@ #include "extension/extension.h" +#include "attribute-rel-util.h" + #include "preferences.h" using Inkscape::IO::Writer; @@ -256,6 +258,7 @@ int XmlSource::close() Document * sp_repr_read_file (const gchar * filename, const gchar *default_ns) { + // g_warning( "Reading file: %s", filename ); xmlDocPtr doc = 0; Document * rdoc = 0; @@ -446,6 +449,18 @@ sp_repr_do_read (xmlDocPtr doc, const gchar *default_ns) promote_to_namespace(root, INKSCAPE_EXTENSION_NS_NC); } } + + + // Clean unnecessary attributes and style properties from SVG documents. (Controlled by + // preferences.) Note: internal Inkscape svg files will also be cleaned (filters.svg, + // icons.svg). How can one tell if a file is internal? + if ( !strcmp(root->name(), "svg:svg" ) ) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + bool clean = prefs->getBool("/options/svgoutput/check_on_reading"); + if( clean ) { + sp_attribute_clean_tree( root ); + } + } } g_hash_table_destroy (prefix_map); @@ -806,6 +821,12 @@ sp_repr_write_stream_root_element(Node *repr, Writer &out, using Inkscape::Util::ptr_shared; g_assert(repr != NULL); + + // Clean unnecessary attributes and stype properties. (Controlled by preferences.) + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + bool clean = prefs->getBool("/options/svgoutput/check_on_writing"); + if (clean) sp_attribute_clean_tree( repr ); + Glib::QueryQuark xml_prefix=g_quark_from_static_string("xml"); NSMap ns_map; @@ -928,7 +949,7 @@ void sp_repr_write_stream_element( Node * repr, Writer & out, add_whitespace = false; } - + // THIS DOESN'T APPEAR TO DO ANYTHING. Can it be commented out or deleted? { GQuark const href_key = g_quark_from_static_string("xlink:href"); GQuark const absref_key = g_quark_from_static_string("sodipodi:absref"); -- cgit v1.2.3 From 568092089e052882df7f160a3ba8bec9e275c437 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sun, 4 Dec 2011 11:10:12 +0100 Subject: cppcheck (bzr r10759) --- src/xml/repr-io.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/xml/repr-io.cpp') diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp index 39eb2637a..7252845b1 100644 --- a/src/xml/repr-io.cpp +++ b/src/xml/repr-io.cpp @@ -82,6 +82,10 @@ public: instr(0), gzin(0) { + for (int k=0;k<4;k++) + { + firstFew[k]=0; + } } virtual ~XmlSource() { -- cgit v1.2.3