summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeter Moulder <peter.moulder@monash.edu>2007-05-20 08:28:40 +0000
committerpjrm <pjrm@users.sourceforge.net>2007-05-20 08:28:40 +0000
commit9c0a99a22522b9a49a42eb2b80466bcc183c69fc (patch)
tree4ee474a9eea47d7c19bcf82a77c9fa510f6ab15e /src
parentdoc (diff)
downloadinkscape-9c0a99a22522b9a49a42eb2b80466bcc183c69fc.tar.gz
inkscape-9c0a99a22522b9a49a42eb2b80466bcc183c69fc.zip
noop: Change fitToRect to take NR::Rect instead of old NRRect. Update callers.
(bzr r3032)
Diffstat (limited to 'src')
-rw-r--r--src/document.cpp29
-rw-r--r--src/document.h2
-rw-r--r--src/selection-chemistry.cpp18
3 files changed, 25 insertions, 24 deletions
diff --git a/src/document.cpp b/src/document.cpp
index f4ebfb7cb..252c9b173 100644
--- a/src/document.cpp
+++ b/src/document.cpp
@@ -485,23 +485,26 @@ gdouble sp_document_height(SPDocument *document)
}
/**
- * Given an NRRect that may, for example, correspond to the bbox of an object
+ * Given an NR::Rect that may, for example, correspond to the bbox of an object,
* this function fits the canvas to that rect by resizing the canvas
* and translating the document root into position.
*/
-void SPDocument::fitToRect(NRRect const & rect)
+void SPDocument::fitToRect(NR::Rect const &rect)
{
- g_return_if_fail(!nr_rect_d_test_empty(&rect));
-
- gdouble w = rect.x1 - rect.x0;
- gdouble h = rect.y1 - rect.y0;
- gdouble old_height = sp_document_height(this);
- SPUnit unit = sp_unit_get_by_id(SP_UNIT_PX);
- sp_document_set_width(this, w, &unit);
- sp_document_set_height(this, h, &unit);
-
- NR::translate tr = NR::translate::translate(-rect.x0,-(rect.y0 + (h - old_height)));
- static_cast<SPGroup *>(root)->translateChildItems(tr);
+ g_return_if_fail(!rect.isEmpty());
+
+ using NR::X; using NR::Y;
+ double const w = rect.extent(X);
+ double const h = rect.extent(Y);
+
+ double const old_height = sp_document_height(this);
+ SPUnit const &px(sp_unit_get_by_id(SP_UNIT_PX));
+ sp_document_set_width(this, w, &px);
+ sp_document_set_height(this, h, &px);
+
+ NR::translate const tr(NR::Point(0, (old_height - h))
+ - rect.min());
+ SP_GROUP(root)->translateChildItems(tr);
}
void sp_document_set_uri(SPDocument *document, gchar const *uri)
diff --git a/src/document.h b/src/document.h
index 94b976314..16300d170 100644
--- a/src/document.h
+++ b/src/document.h
@@ -136,7 +136,7 @@ public:
sigc::connection _selection_changed_connection;
sigc::connection _desktop_activated_connection;
- void fitToRect(NRRect const & rect);
+ void fitToRect(NR::Rect const &rect);
};
SPDocument *sp_document_new (const gchar *uri, unsigned int keepalive, bool make_new = false);
diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp
index 2b13021a2..bd1f54b6b 100644
--- a/src/selection-chemistry.cpp
+++ b/src/selection-chemistry.cpp
@@ -2843,23 +2843,21 @@ void fit_canvas_to_selection(SPDesktop *desktop) {
g_return_if_fail(doc != NULL);
g_return_if_fail(desktop->selection != NULL);
g_return_if_fail(!desktop->selection->isEmpty());
- NRRect bbox(0, 0, 0, 0);
- desktop->selection->bounds(&bbox);
- if (!nr_rect_d_test_empty(&bbox)) {
- doc->fitToRect(bbox);
+ NR::Maybe<NR::Rect> const bbox(desktop->selection->bounds());
+ if (bbox && !bbox->isEmpty()) {
+ doc->fitToRect(*bbox);
}
};
void fit_canvas_to_drawing(SPDocument *doc) {
g_return_if_fail(doc != NULL);
- NRRect bbox(0, 0, 0, 0);
- sp_document_ensure_up_to_date (doc);
- sp_item_invoke_bbox(SP_ITEM(doc->root), &bbox, sp_item_i2r_affine(SP_ITEM(doc->root)), TRUE);
-
- if (!nr_rect_d_test_empty(&bbox)) {
- doc->fitToRect(bbox);
+ sp_document_ensure_up_to_date(doc);
+ SPItem const *const root = SP_ITEM(doc->root);
+ NR::Maybe<NR::Rect> const bbox(root->getBounds(sp_item_i2r_affine(root)));
+ if (bbox && !bbox->isEmpty()) {
+ doc->fitToRect(*bbox);
}
};