From b1fd9e5520ba0578f3b1dbfa53a806bfdb74f3a3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 3 Oct 2016 00:48:49 +0200 Subject: Doc rotate start (bzr r15142.1.1) --- src/sp-namedview.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'src/sp-namedview.cpp') diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index b9526433f..69fc78b33 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -29,12 +29,14 @@ #include "desktop-events.h" #include "sp-guide.h" +#include "sp-root.h" #include "sp-item-group.h" #include "sp-namedview.h" #include "preferences.h" #include "desktop.h" +#include "selection.h" +#include "inkscape.h" #include "conn-avoid-ref.h" // for defaultConnSpacing. -#include "sp-root.h" #include using Inkscape::DocumentUndo; @@ -49,6 +51,7 @@ using Inkscape::Util::unit_table; #define DEFAULTPAGECOLOR 0xffffff00 static void sp_namedview_setup_guides(SPNamedView * nv); +static void sp_namedview_set_document_rotation(SPDocument * doc, SPNamedView * nv); static void sp_namedview_lock_guides(SPNamedView * nv); static void sp_namedview_show_single_guide(SPGuide* guide, bool show); static void sp_namedview_lock_single_guide(SPGuide* guide, bool show); @@ -72,6 +75,7 @@ SPNamedView::SPNamedView() : SPObjectGroup(), snap_manager(this) { this->pagecolor = 0; this->cx = 0; this->pageshadow = 0; + this->document_rotation = 0; this->window_width = 0; this->window_height = 0; this->window_maximized = 0; @@ -212,6 +216,7 @@ void SPNamedView::build(SPDocument *document, Inkscape::XML::Node *repr) { this->readAttr( "inkscape:zoom" ); this->readAttr( "inkscape:cx" ); this->readAttr( "inkscape:cy" ); + this->readAttr( "inkscape:document-rotation" ); this->readAttr( "inkscape:window-width" ); this->readAttr( "inkscape:window-height" ); this->readAttr( "inkscape:window-x" ); @@ -409,6 +414,13 @@ void SPNamedView::set(unsigned int key, const gchar* value) { this->cy = value ? g_ascii_strtod(value, NULL) : HUGE_VAL; // HUGE_VAL means not set this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_INKSCAPE_DOCUMENT_ROTATION: + this->document_rotation = value ? g_ascii_strtod(value, NULL) : 0; // zero means not set + if (value && document) { + sp_namedview_set_document_rotation(document, this); + } + this->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; case SP_ATTR_INKSCAPE_WINDOW_WIDTH: this->window_width = value? atoi(value) : -1; // -1 means not set this->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -939,6 +951,39 @@ static void sp_namedview_lock_guides(SPNamedView *nv) } } +static void sp_namedview_set_document_rotation(SPDocument *doc, SPNamedView *nv) +{ + SPDesktop * desktop = SP_ACTIVE_DESKTOP; + Geom::Rect area; + Geom::Point p = Geom::Point(); + if (desktop) { + area = desktop->get_display_area(); + p = area.midpoint(); + p *= desktop->doc2dt(); + p *= doc->getRoot()->rotation.inverse(); + } + doc->getRoot()->set_rotation(nv->document_rotation); + if (nv->document_rotation) { + nv->showborder = FALSE; + } else { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + nv->showborder = prefs->getBool("/template/base/showborder", 1.0); + } + if (desktop) { + p *= doc->getRoot()->rotation; + //desktop->scroll_world_in_svg_coords (p[Geom::X], p[Geom::Y], true); + // *= doc->getRoot()->c2p * doc->getRoot()->rotation(); + //desktop->zoom_absolute (p[Geom::X], p[Geom::Y], desktop->current_zoom()); + std::cout << p << "pppppp\n"; +// Geom::Point min_pt = Geom::Point(p[Geom::X] - (area.width() / 2.0), p[Geom::Y] - (area.height() / 2.0)); +// Geom::Point max_pt = Geom::Point(p[Geom::X] + (area.width() / 2.0), p[Geom::Y] + (area.height() / 2.0)); +// Geom::Rect const new_area(min_pt, max_pt); +// desktop->set_display_area (new_area, 0, false); + Inkscape::Selection * sel = desktop->getSelection(); + sel->clear(); + } +} + static void sp_namedview_show_single_guide(SPGuide* guide, bool show) { if (show) { -- cgit v1.2.3