diff options
| author | Aaron Spike <aaron@ekips.org> | 2006-04-19 03:51:07 +0000 |
|---|---|---|
| committer | acspike <acspike@users.sourceforge.net> | 2006-04-19 03:51:07 +0000 |
| commit | f68dc06235a7c91fc2e78925cc1b886de8f5e826 (patch) | |
| tree | 0b6d86ae76e30447d52f98d96bd311cb51c83a39 /src/document.cpp | |
| parent | Crash fix (occured if creating layer in layerless document) (diff) | |
| download | inkscape-f68dc06235a7c91fc2e78925cc1b886de8f5e826.tar.gz inkscape-f68dc06235a7c91fc2e78925cc1b886de8f5e826.zip | |
Adding fit canvas verbs
a few fixes in verbs.cpp
and a new button
(bzr r539)
Diffstat (limited to 'src/document.cpp')
| -rw-r--r-- | src/document.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/document.cpp b/src/document.cpp index c5fa71f2b..863266c05 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -51,6 +51,8 @@ #include "unit-constants.h" #include "prefs-utils.h" #include "libavoid/router.h" +#include "libnr/nr-rect.h" +#include "sp-item-transform.h" #include "display/nr-arena-item.h" @@ -480,6 +482,26 @@ gdouble sp_document_height(SPDocument *document) return SP_ROOT(document->root)->height.computed; } +/** + * Given an NRRect 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) +{ + g_return_if_fail(!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))); + sp_item_move_rel((SPItem *) root, tr); +} + void sp_document_set_uri(SPDocument *document, gchar const *uri) { g_return_if_fail(document != NULL); |
