Created
February 1, 2022 09:13
-
-
Save ctrlcctrlv/34a93e5e70a00b2d0941411a3155aaf4 to your computer and use it in GitHub Desktop.
Inkscape issues №356, №615, №1180 fixed—I think.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/file-update.cpp b/src/file-update.cpp | |
| index c363f19..962a6e7 100644 | |
| --- a/src/file-update.cpp | |
| +++ b/src/file-update.cpp | |
| @@ -306,19 +306,36 @@ bool sp_file_save_backup( Glib::ustring uri ) { | |
| return return_value; | |
| } | |
| +// See if we need to offer the user a fix for the 90->96 px per inch change. | |
| +// std::cout << "SPFileOpen:" << std::endl; | |
| +// std::cout << " Version: " << sp_version_to_string(root->version.inkscape) << std::endl; | |
| +// std::cout << " SVG file from old Inkscape version detected: " | |
| +// << sp_version_to_string(root->version.inkscape) << std::endl; | |
| +// 2022: Constant moved from void sp_file_convert_dpi(SPDocument *doc) // | |
| +static const double SP_FILE_RATIO = 90.0/96.0; | |
| + | |
| +void sp_file_fix_guides(SPDocument *doc) { | |
| + SPRoot *root = doc->getRoot(); | |
| + for (SPObject *child = root->firstChild(); child; child = child->getNext()) { | |
| + SPNamedView *nv = dynamic_cast<SPNamedView *>(child); | |
| + if (nv) { | |
| + for (SPObject *child2 = nv->firstChild(); child2; child2 = child2->getNext()) { | |
| + SPGuide *spgd = dynamic_cast<SPGuide *>(child2); | |
| + if (spgd) { | |
| + std::cout << "Fixing line" << std::endl; | |
| + Geom::Point point = spgd->getPoint(); | |
| + spgd->moveto(Geom::Point(point.x() * 1000, point.y() * 1000), true); | |
| + } | |
| + } | |
| + } | |
| + } | |
| +} | |
| void sp_file_convert_dpi(SPDocument *doc) | |
| { | |
| Inkscape::Preferences *prefs = Inkscape::Preferences::get(); | |
| SPRoot *root = doc->getRoot(); | |
| - // See if we need to offer the user a fix for the 90->96 px per inch change. | |
| - // std::cout << "SPFileOpen:" << std::endl; | |
| - // std::cout << " Version: " << sp_version_to_string(root->version.inkscape) << std::endl; | |
| - // std::cout << " SVG file from old Inkscape version detected: " | |
| - // << sp_version_to_string(root->version.inkscape) << std::endl; | |
| - static const double ratio = 90.0/96.0; | |
| - | |
| bool need_fix_viewbox = false; | |
| bool need_fix_units = false; | |
| bool need_fix_guides = false; | |
| @@ -503,21 +520,21 @@ void sp_file_convert_dpi(SPDocument *doc) | |
| } | |
| if (response == FILE_DPI_VIEWBOX_SCALED) { | |
| - double ratio_viewbox = need_fix_units ? 1.0 : ratio; | |
| + double ratio_viewbox = need_fix_units ? 1.0 : SP_FILE_RATIO; | |
| doc->setViewBox(Geom::Rect::from_xywh(0, 0, 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"); | |
| + Inkscape::Util::Quantity(doc->getWidth().value("px") / SP_FILE_RATIO, "px"); | |
| + Inkscape::Util::Quantity height = Inkscape::Util::Quantity(doc->getHeight().value("px") / SP_FILE_RATIO, "px"); | |
| if (need_fix_units) | |
| doc->setWidthAndHeight(width, height, false); | |
| } else if (response == FILE_DPI_DOCUMENT_SCALED) { | |
| 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"); | |
| + Inkscape::Util::Quantity(doc->getWidth().value("px") / SP_FILE_RATIO, "px"); | |
| + Inkscape::Util::Quantity height = Inkscape::Util::Quantity(doc->getHeight().value("px") / SP_FILE_RATIO, "px"); | |
| if (need_fix_units) | |
| doc->setWidthAndHeight(width, height, false); | |
| @@ -534,7 +551,7 @@ void sp_file_convert_dpi(SPDocument *doc) | |
| prefs->setBool("/options/transform/gradient", true); | |
| Inkscape::UI::ShapeEditor::blockSetItem(true); | |
| - doc->getRoot()->scaleChildItemsRec(Geom::Scale(1 / ratio), Geom::Point(0, 0), false); | |
| + doc->getRoot()->scaleChildItemsRec(Geom::Scale(1 / SP_FILE_RATIO), Geom::Point(0, 0), false); | |
| Inkscape::UI::ShapeEditor::blockSetItem(false); | |
| // Restore preferences | |
| @@ -553,19 +570,14 @@ void sp_file_convert_dpi(SPDocument *doc) | |
| } | |
| // Fix guides and grids and perspective | |
| + if (need_fix_guides) { | |
| + // std::cout << "Fixing guides" << std::endl; | |
| + sp_file_fix_guides(doc); | |
| + } | |
| + | |
| for (SPObject *child = root->firstChild(); child; child = child->getNext()) { | |
| SPNamedView *nv = dynamic_cast<SPNamedView *>(child); | |
| if (nv) { | |
| - if (need_fix_guides) { | |
| - // std::cout << "Fixing guides" << std::endl; | |
| - for (SPObject *child2 = nv->firstChild(); child2; child2 = child2->getNext()) { | |
| - SPGuide *gd = dynamic_cast<SPGuide *>(child2); | |
| - if (gd) { | |
| - gd->moveto(gd->getPoint() / ratio, true); | |
| - } | |
| - } | |
| - } | |
| - | |
| for (auto grid : nv->grids) { | |
| Inkscape::CanvasXYGrid *xy = dynamic_cast<Inkscape::CanvasXYGrid *>(grid); | |
| if (xy) { | |
| @@ -579,12 +591,12 @@ void sp_file_convert_dpi(SPDocument *doc) | |
| if (need_fix_grid_mm) { | |
| xy->Scale(Geom::Scale(1, 1)); // See note below | |
| } else { | |
| - scale *= Geom::Scale(ratio, ratio); | |
| + scale *= Geom::Scale(SP_FILE_RATIO, SP_FILE_RATIO); | |
| xy->Scale(scale.inverse()); /* *** */ | |
| } | |
| } else { | |
| if (need_fix_grid_mm) { | |
| - xy->Scale(Geom::Scale(ratio, ratio)); | |
| + xy->Scale(Geom::Scale(SP_FILE_RATIO, SP_FILE_RATIO)); | |
| } else { | |
| xy->Scale(scale.inverse()); /* *** */ | |
| } | |
| @@ -592,7 +604,7 @@ void sp_file_convert_dpi(SPDocument *doc) | |
| } else { | |
| if (need_fix_guides) { | |
| if (did_scaling) { | |
| - xy->Scale(Geom::Scale(ratio, ratio).inverse()); | |
| + xy->Scale(Geom::Scale(SP_FILE_RATIO, SP_FILE_RATIO).inverse()); | |
| } else { | |
| // HACK: Scaling the document does not seem to cause | |
| // grids defined in document units to be updated. | |
| @@ -624,10 +636,10 @@ void sp_file_convert_dpi(SPDocument *doc) | |
| Proj::Pt2 pt_y(vp_y); | |
| Proj::Pt2 pt_z(vp_z); | |
| Proj::Pt2 pt_o(vp_o); | |
| - pt_x = pt_x * (1.0 / ratio); | |
| - pt_y = pt_y * (1.0 / ratio); | |
| - pt_z = pt_z * (1.0 / ratio); | |
| - pt_o = pt_o * (1.0 / ratio); | |
| + pt_x = pt_x * (1.0 / SP_FILE_RATIO); | |
| + pt_y = pt_y * (1.0 / SP_FILE_RATIO); | |
| + pt_z = pt_z * (1.0 / SP_FILE_RATIO); | |
| + pt_o = pt_o * (1.0 / SP_FILE_RATIO); | |
| persp3d->setAttribute("inkscape:vp_x", pt_x.coord_string()); | |
| persp3d->setAttribute("inkscape:vp_y", pt_y.coord_string()); | |
| persp3d->setAttribute("inkscape:vp_z", pt_z.coord_string()); | |
| diff --git a/src/file.h b/src/file.h | |
| index c8e7a9b..8e32d53 100644 | |
| --- a/src/file.h | |
| +++ b/src/file.h | |
| @@ -173,6 +173,7 @@ void sp_file_convert_dpi(SPDocument *doc); | |
| void sp_file_fix_empty_lines(SPDocument *doc); | |
| void sp_file_fix_osb(SPObject *doc); | |
| void sp_file_fix_feComposite(SPObject *doc); | |
| +void sp_file_fix_guides(SPDocument *doc); | |
| void sp_file_fix_lpe(SPDocument *doc); | |
| enum File_DPI_Fix { FILE_DPI_UNCHANGED = 0, FILE_DPI_VIEWBOX_SCALED, FILE_DPI_DOCUMENT_SCALED }; | |
| extern int sp_file_convert_dpi_method_commandline; | |
| diff --git a/src/inkscape-application.cpp b/src/inkscape-application.cpp | |
| index e348885..f120788 100644 | |
| --- a/src/inkscape-application.cpp | |
| +++ b/src/inkscape-application.cpp | |
| @@ -354,6 +354,8 @@ InkscapeApplication::document_fix(InkscapeWindow* window) | |
| } | |
| /** Update LPE and Fix legacy LPE system **/ | |
| sp_file_fix_lpe(document); | |
| + // Fix guideline positions at document startup | |
| + sp_file_fix_guides(document); | |
| // Check for font substitutions, requires text to have been rendered. | |
| Inkscape::UI::Dialog::FontSubstitution::getInstance().checkFontSubstitutions(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment