=== modified file 'src/file.cpp' --- src/file.cpp 2017-01-22 19:05:28 +0000 +++ src/file.cpp 2017-01-26 19:07:58 +0000 @@ -78,6 +78,7 @@ #include "ui/shape-editor.h" #include +#include using Inkscape::DocumentUndo; @@ -408,48 +409,84 @@ default: std::cerr << "sp_file_open: Unhandled height unit!" << std::endl; } - - // std::cout << "Absolute SVG units in root? " << (need_fix_viewbox?"true":"false") << std::endl; - // std::cout << "User units in root? " << (need_fix_units ?"true":"false") << std::endl; - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - if (!root->viewBox_set && need_fix_viewbox) { - - 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)")); - - Gtk::Label info; - info.set_markup(msg.c_str()); - info.show(); + if ( need_fix_units && need_fix_viewbox ) { + std::cerr << "Different units in document size !" << std::endl; + if(root->viewBox_set) + need_fix_viewbox = false; + else + need_fix_units = false; + } + + if ( (!root->viewBox_set && need_fix_viewbox ) || need_fix_units ) { + + + /******** UI *******/ + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Gtk::Dialog scaleDialog( _("Convert legacy Inkscape file")); + Gtk::Label explanation; + explanation.set_markup(Glib::ustring("") + doc->getName() + "\n" + _("was created in an older version of Inkscape (90 DPI) and we need\n" + "to make it compatible with newer versions (96 DPI). Tell us about this file:\n")); + Gtk::RadioButton::Group c1,c2; + + Gtk::Label choice1_label; + choice1_label.set_markup(_("This file contains digital artwork for screen display. (Choose if unsure.)")); + Gtk::RadioButton choice1(c1); + choice1.add(choice1_label); + Gtk::RadioButton choice2(c1,_("This file is intended for physical output, such as paper or 3D prints.")); + Gtk::Label choice2_1_label; + choice2_1_label.set_markup(_("The appearance of elements such as clips, masks, filters, and clones\n" + "is most important. (Choose if unsure.)")); + Gtk::RadioButton choice2_1(c2); + choice2_1.add(choice2_1_label); + Gtk::RadioButton choice2_2(c2,_("The accuracy of the physical unit size and position values of objects\n" + "in the file is most important. (Experimental.)")); + Gtk::CheckButton backupButton( _("Create a backup file in same directory.")); + Gtk::Expander moreinfo(_("More details...")); + Gtk::Label moreinfo_text; + moreinfo_text.set_markup(_( + "We've updated Inkscape to follow the CSS standard of 96 DPI for better browser\n compatibility; we used to use 90 DPI. " + "Digital artwork for screen display will be converted\n to 96 DPI without scaling and should be unaffected. " + "Artwork drawn at 90 DPI for a specific\n physical size will be too small if converted to 96 DPI without any scaling. There are two\n scaling methods:\n\n" + "Scaling the whole document: The least error-prone method, this preserves the\n appearance of the artwork, including filters and the position of masks, etc. " + "The scale\n of the artwork relative to the document size may not be accurate.\n\n" + "Scaling individual elements in the artwork: This method is less reliable and can\n result in a changed appearance, " + "but is better for physical output that relies on accurate\n sizes and positions (for example, for 3D printing.)\n\n" + "More information about this change are available in the Inkscape FAQ" + "")); + moreinfo.add(moreinfo_text); + Gtk::VBox b; + b.pack_start(choice2_1,false,false,0); + b.pack_start(choice2_2,false,false,0); + choice2_1.show(); + choice2_2.show(); + + + #if WITH_GTKMM_3_0 - scaleDialog.get_content_area()->pack_start(info, false, false, 20); + auto content = scaleDialog.get_content_area(); #else - scaleDialog.get_vbox()->pack_start(info, false, false, 20); + Gtk::VBox *content = scaleDialog.get_vbox(); #endif - - Gtk::CheckButton backupButton( _("Create backup file (in same directory).") ); + content->pack_start(explanation, false, false, 10); + content->pack_start(choice1, false, false, 5); + content->pack_start(choice2, false, false, 5); + content->pack_start(b, false, false, 20); + content->pack_start(backupButton, false, false, 20); + content->pack_start(explanation, false, false, 20); + scaleDialog.add_button(_("Convert file"),0); bool backup = prefs->getBool("/options/dpifixbackup", true); backupButton.set_active( backup ); - backupButton.show(); - -#if WITH_GTKMM_3_0 - scaleDialog.get_content_area()->pack_start(backupButton, false, false, 20); -#else - scaleDialog.get_vbox()->pack_start(backupButton, false, false, 20); -#endif - - scaleDialog.add_button(_("Set 'viewBox'"), 1); - scaleDialog.add_button(_("Scale elements"), 2); - scaleDialog.add_button(_("Ignore"), 3); - - gint response = scaleDialog.run(); + content->add(moreinfo); + scaleDialog.show_all_children(); + b.hide(); + choice1.signal_clicked().connect(sigc::mem_fun(b,&Gtk::VBox::hide)); + choice2.signal_clicked().connect(sigc::mem_fun(b,&Gtk::VBox::show)); + + scaleDialog.run(); + int response = choice1.get_active() ? 3 : choice2_1.get_active() ? 1 : 2; + backup = backupButton.get_active(); prefs->setBool("/options/dpifixbackup", backup); @@ -457,179 +494,62 @@ sp_file_save_backup( uri ); } + if ( !(response == 3 && need_fix_units) ){ + need_fix_guides = true; // Only fix guides if drawing scaled + need_fix_box3d = true; + + } + if (response == 1) { + double ratio_viewbox = need_fix_units ? 1.0 : ratio; doc->setViewBox(Geom::Rect::from_xywh( 0, 0, - doc->getWidth().value("px") * ratio, - doc->getHeight().value("px") * ratio)); + doc->getWidth().value("px") * ratio_viewbox, + doc->getHeight().value("px") * ratio_viewbox)); + Inkscape::Util::Quantity width = //maybe set it to mm ? + Inkscape::Util::Quantity(doc->getWidth().value("px")/ratio, "px" ); + Inkscape::Util::Quantity height = + Inkscape::Util::Quantity(doc->getHeight().value("px")/ratio,"px" ); + if (need_fix_units) + doc->setWidthAndHeight( width, height, false ); } else if (response == 2 ) { - // std::list effects; - // Inkscape::Extension::db.get_effect_list(effects); - // std::list::iterator it = effects.begin(); - // bool did = false; - // while (it != effects.end()) { - // if (strcmp((*it)->get_id(), "org.inkscape.dpi90to96") == 0) { - // Inkscape::UI::View::View *view = desktop; - // (*it)->effect(view); - // did = true; - // break; - // } - // ++it; - // } - // if (!did) { - // std::cerr << "sp_file_open: Failed to find dpi90to96 extension." << std::endl; - // } - - // Save preferences - bool transform_stroke = prefs->getBool("/options/transform/stroke", true); - bool transform_rectcorners = prefs->getBool("/options/transform/rectcorners", true); - bool transform_pattern = prefs->getBool("/options/transform/pattern", true); - bool transform_gradient = prefs->getBool("/options/transform/gradient", true); - - prefs->setBool("/options/transform/stroke", true); - prefs->setBool("/options/transform/rectcorners", true); - prefs->setBool("/options/transform/pattern", true); - prefs->setBool("/options/transform/gradient", true); - - Inkscape::UI::ShapeEditor::blockSetItem(true); - doc->getRoot()->scaleChildItemsRec(Geom::Scale(1/ratio),Geom::Point(0, 0), false); - Inkscape::UI::ShapeEditor::blockSetItem(false); - - // Restore preferences - prefs->setBool("/options/transform/stroke", transform_stroke); - prefs->setBool("/options/transform/rectcorners", transform_rectcorners); - prefs->setBool("/options/transform/pattern", transform_pattern); - prefs->setBool("/options/transform/gradient", transform_gradient); - - did_scaling = true; - } - - need_fix_box3d = true; - need_fix_guides = true; // Always fix guides - } - - else if (need_fix_units) { - - 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)")); - - Gtk::Label info; - info.set_markup(msg.c_str()); - info.show(); - -#if WITH_GTKMM_3_0 - scaleDialog.get_content_area()->pack_start(info, false, false, 20); -#else - scaleDialog.get_vbox()->pack_start(info, false, false, 20); -#endif - - Gtk::CheckButton backupButton( _("Create backup file (in same directory).") ); - bool backup = prefs->getBool("/options/dpifixbackup", true); - backupButton.set_active( backup ); - backupButton.show(); - -#if WITH_GTKMM_3_0 - scaleDialog.get_content_area()->pack_start(backupButton, false, false, 20); -#else - scaleDialog.get_vbox()->pack_start(backupButton, false, false, 20); -#endif - - scaleDialog.add_button(_("Set 'viewBox'"), 1); - scaleDialog.add_button(_("Scale elements"), 2); - scaleDialog.add_button(_("Ignore"), 3); - - gint response = scaleDialog.run(); - backup = backupButton.get_active(); - prefs->setBool("/options/dpifixbackup", backup); - - if ( backup && response != 3) { - sp_file_save_backup( uri ); - } - - if (response == 1) { - - if (!root->viewBox_set) { - doc->setViewBox(Geom::Rect::from_xywh( - 0, 0, - doc->getWidth().value("px"), - doc->getHeight().value("px"))); - } - Inkscape::Util::Quantity width = - Inkscape::Util::Quantity(doc->getWidth().value("px")/ratio, "px" ); - Inkscape::Util::Quantity height = - Inkscape::Util::Quantity(doc->getHeight().value("px")/ratio,"px" ); - doc->setWidthAndHeight( width, height, false ); - - need_fix_guides = true; // Only fix guides if drawing scaled - need_fix_box3d = true; - - } else if (response == 2) { - - // std::list effects; - // Inkscape::Extension::db.get_effect_list(effects); - // std::list::iterator it = effects.begin(); - // bool did = false; - // while (it != effects.end()){ - // if (strcmp((*it)->get_id(), "org.inkscape.dpi90to96") == 0) { - // Inkscape::UI::View::View *view = desktop; - // (*it)->effect(view); - // did = true; - // break; - // } - // ++it; - // } - // if (!did) { - // std::cerr << "sp_file_open: Failed to find dpi90to96 extension." << std::endl; - // } - // need_fix_guides = true; // Only fix guides if drawing scaled - - Inkscape::Util::Quantity width = - Inkscape::Util::Quantity(doc->getWidth().value("px")/ratio, "px" ); - Inkscape::Util::Quantity height = - Inkscape::Util::Quantity(doc->getHeight().value("px")/ratio,"px" ); - doc->setWidthAndHeight( width, height, false ); - - if (!root->viewBox_set) { - + Inkscape::Util::Quantity width = //maybe set it to mm ? + Inkscape::Util::Quantity(doc->getWidth().value("px")/ratio, "px" ); + Inkscape::Util::Quantity height = + Inkscape::Util::Quantity(doc->getHeight().value("px")/ratio,"px" ); + if (need_fix_units) + doc->setWidthAndHeight( width, height, false ); + + if (!root->viewBox_set) { // Save preferences bool transform_stroke = prefs->getBool("/options/transform/stroke", true); bool transform_rectcorners = prefs->getBool("/options/transform/rectcorners", true); bool transform_pattern = prefs->getBool("/options/transform/pattern", true); bool transform_gradient = prefs->getBool("/options/transform/gradient", true); - + prefs->setBool("/options/transform/stroke", true); prefs->setBool("/options/transform/rectcorners", true); prefs->setBool("/options/transform/pattern", true); prefs->setBool("/options/transform/gradient", true); - + Inkscape::UI::ShapeEditor::blockSetItem(true); doc->getRoot()->scaleChildItemsRec(Geom::Scale(1/ratio),Geom::Point(0, 0), false); Inkscape::UI::ShapeEditor::blockSetItem(false); - + // Restore preferences prefs->setBool("/options/transform/stroke", transform_stroke); prefs->setBool("/options/transform/rectcorners", transform_rectcorners); prefs->setBool("/options/transform/pattern", transform_pattern); prefs->setBool("/options/transform/gradient", transform_gradient); - + did_scaling = true; } - - need_fix_box3d = true; - need_fix_guides = true; // Only fix guides if drawing scaled - - } else { - // Ignore - need_fix_grid_mm = true; + } else { // response == 3 + if (need_fix_units) + need_fix_grid_mm = true; } }