diff options
| author | Marc Jeanmougin <marc@jeanmougin.fr> | 2016-11-06 15:33:01 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marcjeanmougin@free.fr> | 2016-11-06 15:33:01 +0000 |
| commit | 68c305f169dfe9a273e29dd2aa587f0d59071483 (patch) | |
| tree | 19a923f03230794f9d064b4d4fddf2edcdc83a31 /src | |
| parent | Minor tweak (diff) | |
| download | inkscape-68c305f169dfe9a273e29dd2aa587f0d59071483.tar.gz inkscape-68c305f169dfe9a273e29dd2aa587f0d59071483.zip | |
further cppification
Fixed bugs:
- https://launchpad.net/bugs/1306662
(bzr r15218)
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cpp | 10 | ||||
| -rw-r--r-- | src/object-set.h | 1 | ||||
| -rw-r--r-- | src/selection-chemistry.cpp | 34 | ||||
| -rw-r--r-- | src/selection-chemistry.h | 2 | ||||
| -rw-r--r-- | src/verbs.cpp | 2 |
5 files changed, 17 insertions, 32 deletions
diff --git a/src/main.cpp b/src/main.cpp index 0d5f35797..95764aea9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -119,6 +119,7 @@ #include "verbs.h" #include "path-chemistry.h" +#include "object-set.h" #include "sp-text.h" #include "sp-flowtext.h" #include "text-editing.h" @@ -1161,16 +1162,13 @@ static int sp_process_file_list(GSList *fl) // "crop" the document to the specified object, cleaning as we go. SPObject *obj = doc->getObjectById(sp_export_id); - Geom::OptRect const bbox(SP_ITEM(obj)->visualBounds()); - - if (bbox) { - doc->fitToRect(*bbox, false); - } - if (sp_export_id_only) { // If -j then remove all other objects to complete the "crop" doc->getRoot()->cropToObject(obj); } + Inkscape::ObjectSet s(doc); + s.set(obj); + s.fitCanvas(false); } Inkscape::Extension::save(Inkscape::Extension::db.get("org.inkscape.output.svg.plain"), doc, sp_export_svg, false, diff --git a/src/object-set.h b/src/object-set.h index a70730ef1..47a2efb9d 100644 --- a/src/object-set.h +++ b/src/object-set.h @@ -402,6 +402,7 @@ public: // various void getExportHints(Glib::ustring &filename, float *xdpi, float *ydpi); + bool fitCanvas(bool with_margins, bool skip_undo = false); protected: diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 2db059afe..cd61ffba3 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -4094,39 +4094,27 @@ void ObjectSet::unsetMask(bool apply_clip_path) { * "fit-margin-..." attributes. See SPDocument::fitToRect. * \return true if an undoable change should be recorded. */ -bool -fit_canvas_to_selection(SPDesktop *desktop, bool with_margins) +bool ObjectSet::fitCanvas(bool with_margins, bool skip_undo) { - g_return_val_if_fail(desktop != NULL, false); - SPDocument *doc = desktop->getDocument(); - - g_return_val_if_fail(doc != NULL, false); - g_return_val_if_fail(desktop->selection != NULL, false); + g_return_val_if_fail(document() != NULL, false); - if (desktop->selection->isEmpty()) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to fit canvas to.")); + if (isEmpty()) { + if(desktop()) + desktop()->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to fit canvas to.")); return false; } - Geom::OptRect const bbox(desktop->selection->visualBounds()); + Geom::OptRect const bbox(visualBounds()); if (bbox) { - doc->fitToRect(*bbox, with_margins); + document()->fitToRect(*bbox, with_margins); + if(!skip_undo) + DocumentUndo::done(document(), SP_VERB_FIT_CANVAS_TO_SELECTION, + _("Fit Page to Selection")); return true; } else { return false; } } -/** - * Fit canvas to the bounding box of the selection, as an undoable action. - */ -void -verb_fit_canvas_to_selection(SPDesktop *const desktop) -{ - if (fit_canvas_to_selection(desktop)) { - DocumentUndo::done(desktop->getDocument(), SP_VERB_FIT_CANVAS_TO_SELECTION, - _("Fit Page to Selection")); - } -} /** * \param with_margins margins defined in the xml under <sodipodi:namedview> @@ -4171,7 +4159,7 @@ void fit_canvas_to_selection_or_drawing(SPDesktop *desktop) { bool const changed = ( desktop->selection->isEmpty() ? fit_canvas_to_drawing(doc, true) - : fit_canvas_to_selection(desktop, true) ); + : desktop->selection->fitCanvas(true,true)); if (changed) { DocumentUndo::done(desktop->getDocument(), SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING, _("Fit Page to Selection or Drawing")); diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index 969a6e35a..c82c5a4a5 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -96,8 +96,6 @@ void sp_redo (SPDesktop *desktop, SPDocument *doc); void sp_document_get_export_hints (SPDocument * doc, Glib::ustring &filename, float *xdpi, float *ydpi); -bool fit_canvas_to_selection(SPDesktop *, bool with_margins = false); -void verb_fit_canvas_to_selection(SPDesktop *); bool fit_canvas_to_drawing(SPDocument *, bool with_margins = false); void verb_fit_canvas_to_drawing(SPDesktop *); void fit_canvas_to_selection_or_drawing(SPDesktop *); diff --git a/src/verbs.cpp b/src/verbs.cpp index dc92545e2..c2167f67c 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -2359,7 +2359,7 @@ void FitCanvasVerb::perform(SPAction *action, void *data) switch (reinterpret_cast<std::size_t>(data)) { case SP_VERB_FIT_CANVAS_TO_SELECTION: - verb_fit_canvas_to_selection(dt); + dt->selection->fitCanvas(true); break; case SP_VERB_FIT_CANVAS_TO_DRAWING: verb_fit_canvas_to_drawing(dt); |
