From: ishmal Date: Wed, 2 Apr 2008 20:38:51 +0000 (+0000) Subject: Fold sp_repr_save_file() into sp_repr_save_writer() so that it can also be called... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=587dd419e2c3a4858415b1f5d40043986e2e75b0;p=inkscape.git Fold sp_repr_save_file() into sp_repr_save_writer() so that it can also be called by sp_repr_save_buf() --- diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp index 19753e9e3..2a5125375 100644 --- a/src/xml/repr-io.cpp +++ b/src/xml/repr-io.cpp @@ -506,29 +506,22 @@ sp_repr_svg_read_node (Document *xml_doc, xmlNodePtr node, const gchar *default_ return repr; } + void -sp_repr_save_stream (Document *doc, FILE *fp, gchar const *default_ns, bool compress) +sp_repr_save_writer(Document *doc, Inkscape::IO::Writer *out, + gchar const *default_ns) { - Node *repr; - const gchar *str; - - Inkscape::URI dummy("x"); - Inkscape::IO::UriOutputStream bout(fp, dummy); - Inkscape::IO::GzipOutputStream *gout = compress ? new Inkscape::IO::GzipOutputStream(bout) : NULL; - Inkscape::IO::OutputStreamWriter *out = compress ? new Inkscape::IO::OutputStreamWriter( *gout ) : new Inkscape::IO::OutputStreamWriter( bout ); - int inlineattrs = prefs_get_int_attribute("options.svgoutput", "inlineattrs", 0); int indent = prefs_get_int_attribute("options.svgoutput", "indent", 2); /* fixme: do this The Right Way */ out->writeString( "\n" ); - str = ((Node *)doc)->attribute("doctype"); - if (str) { + const gchar *str = ((Node *)doc)->attribute("doctype"); + if (str) out->writeString( str ); - } - repr = sp_repr_document_first_child(doc); + Node *repr = sp_repr_document_first_child(doc); for ( repr = sp_repr_document_first_child(doc) ; repr ; repr = sp_repr_next(repr) ) { @@ -541,16 +534,45 @@ sp_repr_save_stream (Document *doc, FILE *fp, gchar const *default_ns, bool comp sp_repr_write_stream(repr, *out, 0, TRUE, GQuark(0), inlineattrs, indent); } } - if ( out ) { - delete out; - out = NULL; - } - if ( gout ) { - delete gout; - gout = NULL; - } } + + + +Glib::ustring +sp_repr_save_buf(Document *doc) +{ + Inkscape::IO::StringOutputStream souts; + Inkscape::IO::OutputStreamWriter outs(souts); + + sp_repr_save_writer(doc, &outs, SP_INKSCAPE_NS_URI); + + outs.close(); + Glib::ustring buf = souts.getString(); + + return buf; +} + + + + + +void +sp_repr_save_stream (Document *doc, FILE *fp, gchar const *default_ns, bool compress) +{ + Inkscape::URI dummy("x"); + Inkscape::IO::UriOutputStream bout(fp, dummy); + Inkscape::IO::GzipOutputStream *gout = compress ? new Inkscape::IO::GzipOutputStream(bout) : NULL; + Inkscape::IO::OutputStreamWriter *out = compress ? new Inkscape::IO::OutputStreamWriter( *gout ) : new Inkscape::IO::OutputStreamWriter( bout ); + + sp_repr_save_writer(doc, out, default_ns); + + delete out; + delete gout; +} + + + /* Returns TRUE if file successfully saved; FALSE if not */ bool @@ -741,22 +763,6 @@ sp_repr_write_stream (Node *repr, Writer &out, gint indent_level, } -Glib::ustring -sp_repr_write_buf(Node *repr, gint indent_level, - bool add_whitespace, Glib::QueryQuark elide_prefix, - int inlineattrs, int indent) -{ - Glib::ustring buf; - Inkscape::IO::StringOutputStream souts; - Inkscape::IO::OutputStreamWriter outs(souts); - sp_repr_write_stream(repr, outs, indent_level, add_whitespace, - elide_prefix, inlineattrs, indent); - outs.close(); - buf = souts.getString(); - return buf; -} - - void sp_repr_write_stream_element (Node * repr, Writer & out, gint indent_level, bool add_whitespace, diff --git a/src/xml/repr.h b/src/xml/repr.h index 69fe2adce..67616df29 100644 --- a/src/xml/repr.h +++ b/src/xml/repr.h @@ -182,9 +182,7 @@ void sp_repr_write_stream (Inkscape::XML::Node *repr, Inkscape::IO::Writer &out, gint indent_level, bool add_whitespace, Glib::QueryQuark elide_prefix, int inlineattrs, int indent); Inkscape::XML::Document *sp_repr_read_buf (const Glib::ustring &buf, const gchar *default_ns); -Glib::ustring sp_repr_write_buf(Inkscape::XML::Node *repr, gint indent_level, - bool add_whitespace, Glib::QueryQuark elide_prefix, - int inlineattrs, int indent); +Glib::ustring sp_repr_save_buf(Inkscape::XML::Document *doc); void sp_repr_save_stream(Inkscape::XML::Document *doc, FILE *to_file, gchar const *default_ns=NULL, bool compress = false); bool sp_repr_save_file(Inkscape::XML::Document *doc, gchar const *filename, gchar const *default_ns=NULL);