summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2016-12-07 13:38:25 +0000
committertavmjong-free <tavmjong@free.fr>2016-12-07 13:38:25 +0000
commitf54d446fabea020ac142939915aecb225508f56f (patch)
treef93aa570c58d060312a8987b30051c7cd0b5c1e2
parentfix bug #1644621 on show handles. Fix start knot on closed paths (diff)
downloadinkscape-f54d446fabea020ac142939915aecb225508f56f.tar.gz
inkscape-f54d446fabea020ac142939915aecb225508f56f.zip
Add option to save a backup when updating file for dpi change.
(bzr r15307)
-rw-r--r--src/file.cpp73
1 files changed, 67 insertions, 6 deletions
diff --git a/src/file.cpp b/src/file.cpp
index 38c07311d..55089209a 100644
--- a/src/file.cpp
+++ b/src/file.cpp
@@ -68,9 +68,6 @@
#include "sp-guide.h"
#include <gtkmm.h>
-//#include <gtkmm/main.h>
-#include <glibmm/miscutils.h>
-#include <glibmm/convert.h>
using Inkscape::DocumentUndo;
@@ -239,6 +236,43 @@ sp_file_exit()
}
+// Quick and dirty internal backup function
+bool sp_file_save_backup( Glib::ustring uri ) {
+
+ Glib::ustring out = uri;
+ out.insert(out.find(".svg"),"_backup");
+
+ FILE *filein = Inkscape::IO::fopen_utf8name(uri.c_str(), "rb");
+ if (!filein) {
+ std::cerr << "sp_file_save_backup: failed to open: " << uri << std::endl;
+ return false;
+ }
+
+ FILE *fileout = Inkscape::IO::fopen_utf8name(out.c_str(), "wb");
+ if (!fileout) {
+ std::cerr << "sp_file_save_backup: failed to open: " << out << std::endl;
+ fclose( filein );
+ return false;
+ }
+
+ int ch;
+ while ((ch = fgetc(filein)) != EOF) {
+ fputc(ch, fileout);
+ }
+ fflush(fileout);
+
+ bool return_value = true;
+ if (ferror(fileout)) {
+ std::cerr << "sp_file_save_backup: error when writing to: " << out << std::endl;
+ return_value = false;
+ }
+
+ fclose(filein);
+ fclose(fileout);
+
+ return return_value;
+}
+
/*######################
## O P E N
######################*/
@@ -357,26 +391,41 @@ bool sp_file_open(const Glib::ustring &uri,
if (!root->viewBox_set && need_fix_viewbox) {
- std::string msg = _(
+ Glib::ustring msg = _(
"Old Inkscape files use 1in == 90px. CSS requires 1in == 96px.\n"
"Drawing elements may be too small. This can be corrected by\n"
"either setting the SVG 'viewBox' to compensate or by scaling\n"
"all the elements in the drawing.");
Gtk::Dialog scaleDialog( _("Old Inkscape file detected (90 DPI)"), false);
+
Gtk::Label info;
info.set_markup(msg.c_str());
info.show();
+
scaleDialog.get_content_area()->pack_start(info, false, false, 20);
+ Gtk::CheckButton backupButton( _("Create backup file (in same directory).") );
+ backupButton.set_active();
+ backupButton.show();
+
+ scaleDialog.get_content_area()->pack_start(backupButton, false, false, 20);
scaleDialog.add_button("Set 'viewBox'", 1);
scaleDialog.add_button("Scale elements", 2);
scaleDialog.add_button("Ignore", 3);
+
gint response = scaleDialog.run();
+ bool backup = backupButton.get_active();
if (response == 1) {
+ if (backup) {
+ sp_file_save_backup( uri );
+ }
doc->setViewBox(Geom::Rect::from_xywh(
0, 0,
doc->getWidth().value("px") * ratio,
doc->getHeight().value("px") * ratio));
} else if (response == 2 ) {
+ if (backup) {
+ sp_file_save_backup( uri );
+ }
std::list<Inkscape::Extension::Effect *> effects;
Inkscape::Extension::db.get_effect_list(effects);
std::list<Inkscape::Extension::Effect *>::iterator it = effects.begin();
@@ -399,24 +448,33 @@ bool sp_file_open(const Glib::ustring &uri,
}
if (need_fix_units) {
- std::string msg = (
+ Glib::ustring msg = (
"Old Inkscape files use 1in == 90px. CSS requires 1in == 96px.\n"
"Drawings meant to match a physical size (e.g. Letter or A4)\n"
"will be too small. Scaling the drawing can correct for this.\n"
"Internal scaling can be handled either by setting the SVG 'viewBox'\n"
"attribute to compensate or by scaling all objects in the drawing.");
Gtk::Dialog scaleDialog( _("Old Inkscape file detected (90 DPI)"), false);
+
Gtk::Label info;
info.set_markup(msg.c_str());
info.show();
scaleDialog.get_content_area()->pack_start(info, false, false, 20);
+
+ Gtk::CheckButton backupButton( _("Create backup file (in same directory).") );
+ scaleDialog.get_content_area()->pack_start(backupButton, false, false, 20);
+ backupButton.show();
+
scaleDialog.add_button("Set 'viewBox'", 1);
scaleDialog.add_button("Scale elements", 2);
scaleDialog.add_button("Ignore", 3);
gint response = scaleDialog.run();
+ bool backup = backupButton.get_active();
if (response == 1) {
-
+ if (backup) {
+ sp_file_save_backup( uri );
+ }
if (!root->viewBox_set) {
doc->setViewBox(Geom::Rect::from_xywh(
0, 0,
@@ -431,6 +489,9 @@ bool sp_file_open(const Glib::ustring &uri,
need_fix_guides = true; // Only fix guides if drawing scaled
} else if (response == 2) {
+ if (backup) {
+ sp_file_save_backup( uri );
+ }
std::list<Inkscape::Extension::Effect *> effects;
Inkscape::Extension::db.get_effect_list(effects);
std::list<Inkscape::Extension::Effect *>::iterator it = effects.begin();