From fa0468e791e623b679faafdc40c97678316e30e1 Mon Sep 17 00:00:00 2001 From: sasilver Date: Sat, 31 May 2008 15:16:57 +0000 Subject: [PATCH] wrtlprnft's patch for bug 234834 - keeps guidelines in same position relative to objects when doing "Fit page to selection", and also keeps the objects in the same position on the screen --- src/desktop.cpp | 10 ++++++++++ src/desktop.h | 1 + src/document.cpp | 10 ++++++++++ src/sp-namedview.cpp | 17 +++++++++++++++++ src/sp-namedview.h | 3 +++ 5 files changed, 41 insertions(+) diff --git a/src/desktop.cpp b/src/desktop.cpp index eee0446db..5796ed638 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -975,6 +975,16 @@ SPDesktop::zoom_drawing() set_display_area(*d, 10); } +/** + * Scroll canvas by specific coordinate amount in svg coordinates. + */ +void +SPDesktop::scroll_world_in_svg_coords (double dx, double dy, bool is_scrolling) +{ + double scale = expansion(_d2w); + scroll_world(dx*scale, dy*scale, is_scrolling); +} + /** * Scroll canvas by specific coordinate amount. */ diff --git a/src/desktop.h b/src/desktop.h index df9848282..af0d41b2a 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -257,6 +257,7 @@ struct SPDesktop : public Inkscape::UI::View::View using NR::Y; scroll_world(scroll[X], scroll[Y], is_scrolling); } + void scroll_world_in_svg_coords (double dx, double dy, bool is_scrolling = false); void getWindowGeometry (gint &x, gint &y, gint &w, gint &h); void setWindowPosition (NR::Point p); diff --git a/src/document.cpp b/src/document.cpp index d0792ab8a..bf5ef089e 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -48,6 +48,8 @@ #include "inkscape-private.h" #include "inkscape_version.h" #include "sp-object-repr.h" +#include "sp-namedview.h" +#include "desktop.h" #include "document-private.h" #include "dir-util.h" #include "unit-constants.h" @@ -557,6 +559,14 @@ void SPDocument::fitToRect(NR::Rect const &rect) NR::translate const tr(NR::Point(0, (old_height - h)) - rect.min()); SP_GROUP(root)->translateChildItems(tr); + SPNamedView *nv = sp_document_namedview(this, 0); + if(nv) { + NR::translate tr2(-rect.min()); + nv->translateGuides(tr2); + + // update the viewport so the drawing appears to stay where it was + nv->scrollAllDesktops(-tr2[0], tr2[1], false); + } } void sp_document_set_uri(SPDocument *document, gchar const *uri) diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 3575ce6ae..3f52232cb 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -1063,6 +1063,23 @@ Inkscape::CanvasGrid * sp_namedview_get_first_enabled_grid(SPNamedView *namedvie return NULL; } +void SPNamedView::translateGuides(NR::translate const &tr) { + for (GSList *l = guides; l != NULL; l = l->next) { + SPGuide &guide = *SP_GUIDE(l->data); + Geom::Point point_on_line = guide.point_on_line; + point_on_line[0] += tr[0]; + point_on_line[1] += tr[1]; + sp_guide_moveto(guide, point_on_line, true); + } +} + +void SPNamedView::scrollAllDesktops(double dx, double dy, bool is_scrolling) { + for(GSList *l = views; l; l = l->next) { + SPDesktop *desktop = static_cast(l->data); + desktop->scroll_world_in_svg_coords(dx, dy, is_scrolling); + } +} + /* Local Variables: diff --git a/src/sp-namedview.h b/src/sp-namedview.h index 6055f5c71..cfc57d1c4 100644 --- a/src/sp-namedview.h +++ b/src/sp-namedview.h @@ -87,6 +87,9 @@ struct SPNamedView : public SPObjectGroup { guint getViewCount(); GSList const *getViewList() const; SPMetric getDefaultMetric() const; + + void translateGuides(NR::translate const &translation); + void scrollAllDesktops(double dx, double dy, bool is_scrolling); }; struct SPNamedViewClass { -- 2.30.2