From 884edd729abf49df5b3c9a4679a0d5b6c85d182c Mon Sep 17 00:00:00 2001 From: pjrm Date: Mon, 6 Apr 2009 21:53:09 +0000 Subject: [PATCH] noop: Rename argument from uri to filename for Extension::...::save implementations, given that that's how it's used at present. Add a couple of fixme comments to do with use of this argument. --- src/extension/internal/cairo-png-out.cpp | 4 ++-- src/extension/internal/cairo-png-out.h | 2 +- src/extension/internal/cairo-ps-out.cpp | 12 +++++----- src/extension/internal/cairo-ps-out.h | 2 +- .../internal/cairo-renderer-pdf-out.cpp | 6 ++--- .../internal/cairo-renderer-pdf-out.h | 2 +- src/extension/internal/emf-win32-inout.h | 2 +- src/extension/internal/javafx-out.cpp | 22 +++++++++++++------ src/extension/internal/javafx-out.h | 6 ++--- src/extension/internal/latex-pstricks-out.cpp | 4 ++-- src/extension/internal/latex-pstricks-out.h | 2 +- src/extension/internal/odf.cpp | 10 +++++---- src/extension/internal/odf.h | 2 +- src/extension/internal/pov-out.cpp | 17 +++++++------- src/extension/internal/pov-out.h | 6 ++--- src/extension/internal/svg.cpp | 8 +++---- src/extension/internal/svg.h | 2 +- src/extension/output.cpp | 6 ++--- 18 files changed, 63 insertions(+), 52 deletions(-) diff --git a/src/extension/internal/cairo-png-out.cpp b/src/extension/internal/cairo-png-out.cpp index 744d59f75..c81fdd029 100644 --- a/src/extension/internal/cairo-png-out.cpp +++ b/src/extension/internal/cairo-png-out.cpp @@ -92,9 +92,9 @@ png_render_document_to_file(SPDocument *doc, gchar const *filename) \param uri Filename to save to (probably will end in .png) */ void -CairoRendererOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri) +CairoRendererOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filename) { - if (!png_render_document_to_file(doc, uri)) + if (!png_render_document_to_file(doc, filename)) throw Inkscape::Extension::Output::save_failed(); return; diff --git a/src/extension/internal/cairo-png-out.h b/src/extension/internal/cairo-png-out.h index 625c53ffc..9b9bd6ffe 100644 --- a/src/extension/internal/cairo-png-out.h +++ b/src/extension/internal/cairo-png-out.h @@ -28,7 +28,7 @@ public: bool check(Inkscape::Extension::Extension *module); void save(Inkscape::Extension::Output *mod, SPDocument *doc, - gchar const *uri); + gchar const *filename); static void init(); }; diff --git a/src/extension/internal/cairo-ps-out.cpp b/src/extension/internal/cairo-ps-out.cpp index f8918c060..0ea0a051d 100644 --- a/src/extension/internal/cairo-ps-out.cpp +++ b/src/extension/internal/cairo-ps-out.cpp @@ -121,10 +121,10 @@ ps_print_document_to_file(SPDocument *doc, gchar const *filename, unsigned int l \brief This function calls the output module with the filename \param mod unused \param doc Document to be saved - \param uri Filename to save to (probably will end in .ps) + \param filename Filename to save to (probably will end in .ps) */ void -CairoPsOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri) +CairoPsOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filename) { Inkscape::Extension::Extension * ext; unsigned int ret; @@ -172,7 +172,7 @@ CairoPsOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gc } catch(...) {} gchar * final_name; - final_name = g_strdup_printf("> %s", uri); + final_name = g_strdup_printf("> %s", filename); ret = ps_print_document_to_file(doc, final_name, level, new_textToPath, new_blurToBitmap, new_bitmapResolution, new_exportId, new_areaDrawing, new_areaCanvas); g_free(final_name); @@ -185,10 +185,10 @@ CairoPsOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gc \brief This function calls the output module with the filename \param mod unused \param doc Document to be saved - \param uri Filename to save to (probably will end in .ps) + \param filename Filename to save to (probably will end in .ps) */ void -CairoEpsOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri) +CairoEpsOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filename) { Inkscape::Extension::Extension * ext; unsigned int ret; @@ -236,7 +236,7 @@ CairoEpsOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const g } catch(...) {} gchar * final_name; - final_name = g_strdup_printf("> %s", uri); + final_name = g_strdup_printf("> %s", filename); ret = ps_print_document_to_file(doc, final_name, level, new_textToPath, new_blurToBitmap, new_bitmapResolution, new_exportId, new_areaDrawing, new_areaCanvas, true); g_free(final_name); diff --git a/src/extension/internal/cairo-ps-out.h b/src/extension/internal/cairo-ps-out.h index d6730c9ce..019b6b810 100644 --- a/src/extension/internal/cairo-ps-out.h +++ b/src/extension/internal/cairo-ps-out.h @@ -29,7 +29,7 @@ public: bool check(Inkscape::Extension::Extension *module); void save(Inkscape::Extension::Output *mod, SPDocument *doc, - gchar const *uri); + gchar const *filename); static void init(); bool textToPath(Inkscape::Extension::Print *ext); diff --git a/src/extension/internal/cairo-renderer-pdf-out.cpp b/src/extension/internal/cairo-renderer-pdf-out.cpp index 4b37cae5c..3a4dde639 100644 --- a/src/extension/internal/cairo-renderer-pdf-out.cpp +++ b/src/extension/internal/cairo-renderer-pdf-out.cpp @@ -110,14 +110,14 @@ pdf_render_document_to_file(SPDocument *doc, gchar const *filename, unsigned int \brief This function calls the output module with the filename \param mod unused \param doc Document to be saved - \param uri Filename to save to (probably will end in .pdf) + \param filename Filename to save to (probably will end in .pdf) The most interesting thing that this function does is just attach an '>' on the front of the filename. This is the syntax used to tell the printing system to save to file. */ void -CairoRendererPdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri) +CairoRendererPdfOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filename) { Inkscape::Extension::Extension * ext; unsigned int ret; @@ -186,7 +186,7 @@ CairoRendererPdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, } gchar * final_name; - final_name = g_strdup_printf("> %s", uri); + final_name = g_strdup_printf("> %s", filename); ret = pdf_render_document_to_file(doc, final_name, level, new_textToPath, new_blurToBitmap, new_bitmapResolution, new_exportId, new_exportDrawing, new_exportCanvas); diff --git a/src/extension/internal/cairo-renderer-pdf-out.h b/src/extension/internal/cairo-renderer-pdf-out.h index 1c18519a0..d76ffb4d4 100644 --- a/src/extension/internal/cairo-renderer-pdf-out.h +++ b/src/extension/internal/cairo-renderer-pdf-out.h @@ -28,7 +28,7 @@ public: bool check(Inkscape::Extension::Extension *module); void save(Inkscape::Extension::Output *mod, SPDocument *doc, - gchar const *uri); + gchar const *filename); static void init(); }; diff --git a/src/extension/internal/emf-win32-inout.h b/src/extension/internal/emf-win32-inout.h index 49c1826e4..c62d7a4e9 100644 --- a/src/extension/internal/emf-win32-inout.h +++ b/src/extension/internal/emf-win32-inout.h @@ -29,7 +29,7 @@ public: void save(Inkscape::Extension::Output *mod, // Save the given document to the given filename SPDocument *doc, - gchar const *uri); + gchar const *filename); virtual SPDocument *open( Inkscape::Extension::Input *mod, const gchar *uri ); diff --git a/src/extension/internal/javafx-out.cpp b/src/extension/internal/javafx-out.cpp index 1c3ae9c2a..fd28011c3 100644 --- a/src/extension/internal/javafx-out.cpp +++ b/src/extension/internal/javafx-out.cpp @@ -823,12 +823,12 @@ void JavaFXOutput::reset() /** * Saves the of an Inkscape SVG file as JavaFX spline definitions */ -bool JavaFXOutput::saveDocument(SPDocument *doc, gchar const *uri) +bool JavaFXOutput::saveDocument(SPDocument *doc, gchar const *filename_utf8) { reset(); - name = Glib::path_get_basename(uri); + name = Glib::path_get_basename(filename_utf8); int pos = name.find('.'); if (pos > 0) name = name.substr(0, pos); @@ -864,10 +864,10 @@ bool JavaFXOutput::saveDocument(SPDocument *doc, gchar const *uri) //###### WRITE TO FILE - FILE *f = Inkscape::IO::fopen_utf8name(uri, "w"); + FILE *f = Inkscape::IO::fopen_utf8name(filename_utf8, "w"); if (!f) { - err("Could open JavaFX file '%s' for writing", uri); + err("Could open JavaFX file '%s' for writing", filename_utf8); return false; } @@ -899,11 +899,19 @@ bool JavaFXOutput::saveDocument(SPDocument *doc, gchar const *uri) */ void JavaFXOutput::save(Inkscape::Extension::Output */*mod*/, - SPDocument *doc, gchar const *uri) + SPDocument *doc, gchar const *filename_utf8) { - if (!saveDocument(doc, uri)) + /* N.B. The name `filename_utf8' represents the fact that we want it to be in utf8; whereas in + * fact we know that some callers of Extension::save pass something in the filesystem's + * encoding, while others do g_filename_to_utf8 before calling. + * + * In terms of safety, it's best to make all callers pass actual filenames, since in general + * one can't round-trip from filename to utf8 back to the same filename. Whereas the argument + * for passing utf8 filenames is one of convenience: we often want to pass to g_warning or + * store as a string (rather than a byte stream) in XML, or the like. */ + if (!saveDocument(doc, filename_utf8)) { - g_warning("Could not save JavaFX file '%s'", uri); + g_warning("Could not save JavaFX file '%s'", filename_utf8); } } diff --git a/src/extension/internal/javafx-out.h b/src/extension/internal/javafx-out.h index b3552097f..691812ee2 100644 --- a/src/extension/internal/javafx-out.h +++ b/src/extension/internal/javafx-out.h @@ -55,8 +55,8 @@ public: /** * API call to perform the output to a file */ - virtual void save (Inkscape::Extension::Output *mod, - SPDocument *doc, const gchar *uri); + virtual void save(Inkscape::Extension::Output *mod, + SPDocument *doc, gchar const *filename); /** * Inkscape runtime startup call. @@ -124,7 +124,7 @@ private: /** * Actual method to save document */ - bool saveDocument(SPDocument *doc, const gchar *uri); + bool saveDocument(SPDocument *doc, gchar const *filename); //For statistics int nrNodes; diff --git a/src/extension/internal/latex-pstricks-out.cpp b/src/extension/internal/latex-pstricks-out.cpp index 8d89951ce..4a469a750 100644 --- a/src/extension/internal/latex-pstricks-out.cpp +++ b/src/extension/internal/latex-pstricks-out.cpp @@ -47,7 +47,7 @@ LatexOutput::check (Inkscape::Extension::Extension * module) void -LatexOutput::save (Inkscape::Extension::Output *mod2, SPDocument *doc, const gchar *uri) +LatexOutput::save(Inkscape::Extension::Output *mod2, SPDocument *doc, gchar const *filename) { Inkscape::Extension::Print *mod; SPPrintContext context; @@ -60,7 +60,7 @@ LatexOutput::save (Inkscape::Extension::Output *mod2, SPDocument *doc, const gch mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_LATEX); oldconst = mod->get_param_string("destination"); oldoutput = g_strdup(oldconst); - mod->set_param_string("destination", (gchar *)uri); + mod->set_param_string("destination", filename); /* Start */ context.module = mod; diff --git a/src/extension/internal/latex-pstricks-out.h b/src/extension/internal/latex-pstricks-out.h index 8e544d5b4..a12cdc3c1 100644 --- a/src/extension/internal/latex-pstricks-out.h +++ b/src/extension/internal/latex-pstricks-out.h @@ -28,7 +28,7 @@ public: void save(Inkscape::Extension::Output *mod, // Save the given document to the given filename SPDocument *doc, - gchar const *uri); + gchar const *filename); static void init(void);//Initialize the class }; diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp index c15b839d7..cc8489302 100644 --- a/src/extension/internal/odf.cpp +++ b/src/extension/internal/odf.cpp @@ -2367,12 +2367,14 @@ OdfOutput::reset() * Descends into the SVG tree, mapping things to ODF when appropriate */ void -OdfOutput::save(Inkscape::Extension::Output */*mod*/, SPDocument *doc, gchar const *uri) +OdfOutput::save(Inkscape::Extension::Output */*mod*/, SPDocument *doc, gchar const *filename) { reset(); - //g_message("native file:%s\n", uri); - documentUri = URI(uri); + //g_message("native file:%s\n", filename); + documentUri = URI(filename); + /* fixme: It looks like we really are using documentUri as a URI, so we ought to call + * g_filename_to_uri for the URI constructor. */ ZipFile zf; preprocess(zf, doc->rroot); @@ -2395,7 +2397,7 @@ OdfOutput::save(Inkscape::Extension::Output */*mod*/, SPDocument *doc, gchar con return; } - if (!zf.writeFile(uri)) + if (!zf.writeFile(filename)) { return; } diff --git a/src/extension/internal/odf.h b/src/extension/internal/odf.h index 8d38e530f..3854ddfe1 100644 --- a/src/extension/internal/odf.h +++ b/src/extension/internal/odf.h @@ -273,7 +273,7 @@ public: void save (Inkscape::Extension::Output *mod, SPDocument *doc, - const gchar *uri); + gchar const *filename); static void init (void); diff --git a/src/extension/internal/pov-out.cpp b/src/extension/internal/pov-out.cpp index 89f58befc..f30cbc317 100644 --- a/src/extension/internal/pov-out.cpp +++ b/src/extension/internal/pov-out.cpp @@ -576,7 +576,7 @@ void PovOutput::reset() /** * Saves the Shapes of an Inkscape SVG file as PovRay spline definitions */ -void PovOutput::saveDocument(SPDocument *doc, gchar const *uri) +void PovOutput::saveDocument(SPDocument *doc, gchar const *filename_utf8) { reset(); @@ -584,7 +584,7 @@ void PovOutput::saveDocument(SPDocument *doc, gchar const *uri) //# Lets do the curves first, to get the stats if (!doTree(doc)) { - err("Could not output curves for %s", uri); + err("Could not output curves for %s", filename_utf8); return; } @@ -593,7 +593,7 @@ void PovOutput::saveDocument(SPDocument *doc, gchar const *uri) if (!doHeader()) { - err("Could not write header for %s", uri); + err("Could not write header for %s", filename_utf8); return; } @@ -601,7 +601,7 @@ void PovOutput::saveDocument(SPDocument *doc, gchar const *uri) if (!doTail()) { - err("Could not write footer for %s", uri); + err("Could not write footer for %s", filename_utf8); return; } @@ -609,8 +609,8 @@ void PovOutput::saveDocument(SPDocument *doc, gchar const *uri) //###### WRITE TO FILE - Inkscape::IO::dump_fopen_call(uri, "L"); - FILE *f = Inkscape::IO::fopen_utf8name(uri, "w"); + Inkscape::IO::dump_fopen_call(filename_utf8, "L"); + FILE *f = Inkscape::IO::fopen_utf8name(filename_utf8, "w"); if (!f) return; @@ -641,9 +641,10 @@ void PovOutput::saveDocument(SPDocument *doc, gchar const *uri) */ void PovOutput::save(Inkscape::Extension::Output */*mod*/, - SPDocument *doc, gchar const *uri) + SPDocument *doc, gchar const *filename_utf8) { - saveDocument(doc, uri); + /* See comments in JavaFSOutput::save re the name `filename_utf8'. */ + saveDocument(doc, filename_utf8); } diff --git a/src/extension/internal/pov-out.h b/src/extension/internal/pov-out.h index a9f94b61a..0c3b73a7f 100644 --- a/src/extension/internal/pov-out.h +++ b/src/extension/internal/pov-out.h @@ -56,8 +56,8 @@ public: /** * API call to perform the output to a file */ - void save (Inkscape::Extension::Output *mod, - SPDocument *doc, const gchar *uri); + void save(Inkscape::Extension::Output *mod, + SPDocument *doc, gchar const *filename); /** * Inkscape runtime startup call. @@ -126,7 +126,7 @@ private: /** * Actual method to save document */ - void saveDocument(SPDocument *doc, const gchar *uri); + void saveDocument(SPDocument *doc, gchar const *filename); /** diff --git a/src/extension/internal/svg.cpp b/src/extension/internal/svg.cpp index 31178f8d5..4a323d7d7 100644 --- a/src/extension/internal/svg.cpp +++ b/src/extension/internal/svg.cpp @@ -191,12 +191,12 @@ Svg::open (Inkscape::Extension::Input */*mod*/, const gchar *uri) all of this code. I just stole it. */ void -Svg::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri) +Svg::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filename) { g_return_if_fail(doc != NULL); - g_return_if_fail(uri != NULL); + g_return_if_fail(filename != NULL); - gchar *save_path = g_path_get_dirname (uri); + gchar *save_path = g_path_get_dirname(filename); gboolean const spns = (!mod->get_id() || !strcmp (mod->get_id(), SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE) @@ -214,7 +214,7 @@ Svg::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri) Inkscape::IO::fixupHrefs( doc, save_path, spns ); - gboolean const s = sp_repr_save_file (repr->document(), uri, SP_SVG_NS_URI); + gboolean const s = sp_repr_save_file(repr->document(), filename, SP_SVG_NS_URI); if (s == FALSE) { throw Inkscape::Extension::Output::save_failed(); } diff --git a/src/extension/internal/svg.h b/src/extension/internal/svg.h index de75f0021..b97735dd8 100644 --- a/src/extension/internal/svg.h +++ b/src/extension/internal/svg.h @@ -26,7 +26,7 @@ class Svg : public Inkscape::Extension::Implementation::Implementation { public: virtual void save( Inkscape::Extension::Output *mod, SPDocument *doc, - const gchar *uri ); + gchar const *filename ); virtual SPDocument *open( Inkscape::Extension::Input *mod, const gchar *uri ); static void init( void ); diff --git a/src/extension/output.cpp b/src/extension/output.cpp index e0070339d..e1481d000 100644 --- a/src/extension/output.cpp +++ b/src/extension/output.cpp @@ -200,7 +200,7 @@ Output::prefs (void) \return None \brief Save a document as a file \param doc Document to save - \param uri File to save the document as + \param filename File to save the document as This function does a little of the dirty work involved in saving a document so that the implementation only has to worry about geting @@ -212,10 +212,10 @@ Output::prefs (void) could be changed, and old files will still work properly. */ void -Output::save (SPDocument * doc, const gchar * uri) +Output::save(SPDocument *doc, gchar const *filename) { try { - imp->save(this, doc, uri); + imp->save(this, doc, filename); } catch (...) { g_warning("There was an error saving the file."); -- 2.30.2