diff options
| author | Bob Jamison <ishmalius@gmail.com> | 2008-04-02 20:38:51 +0000 |
|---|---|---|
| committer | ishmal <ishmal@users.sourceforge.net> | 2008-04-02 20:38:51 +0000 |
| commit | c373e8f37eeb74d126878b7c12b39644797c9812 (patch) | |
| tree | aed31c5b583e8d36f18057ee8a0144e8f49d3baa /src/xml | |
| parent | [INTL: pl] Updated Polish language translation for Windows installer (diff) | |
| download | inkscape-c373e8f37eeb74d126878b7c12b39644797c9812.tar.gz inkscape-c373e8f37eeb74d126878b7c12b39644797c9812.zip | |
Fold sp_repr_save_file() into sp_repr_save_writer() so that it can also be called by sp_repr_save_buf()
(bzr r5314)
Diffstat (limited to 'src/xml')
| -rw-r--r-- | src/xml/repr-io.cpp | 80 | ||||
| -rw-r--r-- | src/xml/repr.h | 4 |
2 files changed, 44 insertions, 40 deletions
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( "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\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); |
