diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2017-01-24 18:11:26 +0000 |
|---|---|---|
| committer | jabiertxof <info@marker.es> | 2017-01-24 18:11:26 +0000 |
| commit | 176b68d76f6b684b4bf0797e1d132e8377bddab0 (patch) | |
| tree | b1918157cb8d5ada5bb76a0fd98b2433d2dd476d /src/viewbox.cpp | |
| parent | Fix a translation bug in rotate copies LPE (diff) | |
| parent | Put namespace as constant (diff) | |
| download | inkscape-176b68d76f6b684b4bf0797e1d132e8377bddab0.tar.gz inkscape-176b68d76f6b684b4bf0797e1d132e8377bddab0.zip | |
merge lp:~inkscape.dev/inkscape/doc_rotate
(bzr r15444)
Diffstat (limited to 'src/viewbox.cpp')
| -rw-r--r-- | src/viewbox.cpp | 62 |
1 files changed, 49 insertions, 13 deletions
diff --git a/src/viewbox.cpp b/src/viewbox.cpp index 1b50fe71c..ebfc04d8a 100644 --- a/src/viewbox.cpp +++ b/src/viewbox.cpp @@ -17,6 +17,8 @@ #include "viewbox.h" #include "enums.h" #include "sp-item.h" +#include "inkscape.h" +#include "desktop.h" SPViewBox::SPViewBox() : viewBox_set(false) @@ -25,6 +27,11 @@ SPViewBox::SPViewBox() , aspect_align(SP_ASPECT_XMID_YMID) // Default per spec , aspect_clip(SP_ASPECT_MEET) , c2p(Geom::identity()) + , vbt(Geom::identity()) + , rotation(Geom::identity()) + , angle(0) + , previous_angle(0) + , rotated(false) { } @@ -159,6 +166,16 @@ void SPViewBox::set_preserveAspectRatio(const gchar* value) { } } +double SPViewBox::get_rotation() { + return this->angle; +} + +void SPViewBox::set_rotation(double angle_val) { + this->previous_angle = this->angle; + this->angle = angle_val; + this->rotated = true; +} + // Apply scaling from viewbox void SPViewBox::apply_viewbox(const Geom::Rect& in, double scale_none) { @@ -222,22 +239,41 @@ void SPViewBox::apply_viewbox(const Geom::Rect& in, double scale_none) { break; } } - /* Viewbox transform from scale and position */ - Geom::Affine q; - q[0] = scale_x; - q[1] = 0.0; - q[2] = 0.0; - q[3] = scale_y; - q[4] = x - scale_x * this->viewBox.left(); - q[5] = y - scale_y * this->viewBox.top(); - - // std::cout << " q\n" << q << std::endl; - - /* Append viewbox transformation */ - this->c2p = q * this->c2p; + vbt = Geom::identity(); + vbt[0] = scale_x; + vbt[1] = 0.0; + vbt[2] = 0.0; + vbt[3] = scale_y; + vbt[4] = x - scale_x * this->viewBox.left(); + vbt[5] = y - scale_y * this->viewBox.top(); + /* Append viewbox and turn transformation */ + Geom::Point page_center = this->viewBox.midpoint(); + SPDesktop * desktop = SP_ACTIVE_DESKTOP; + if (this->angle > 0.0 || this->angle < 0.0 ) { //!0 + if (desktop) { + rotation = Geom::Translate(page_center).inverse() * Geom::Rotate(Geom::rad_from_deg(angle)) * Geom::Translate(page_center); + this->c2p = rotation * vbt * this->c2p; + } else { + this->c2p = vbt * this->c2p; + } + } else { + this->c2p = vbt * this->c2p; + } + if (desktop && this->rotated) { + Geom::Rect view = desktop->get_display_area(); + Geom::Point view_center = desktop->doc2dt(view.midpoint()); + Geom::Affine center_rotation = Geom::identity(); + center_rotation *= Geom::Translate(page_center * vbt).inverse(); + center_rotation *= Geom::Rotate(Geom::rad_from_deg(this->angle - this->previous_angle)); + center_rotation *= Geom::Translate(page_center * vbt); + view_center = desktop->dt2doc(view_center * center_rotation); + desktop->zoom_relative(view_center[Geom::X], view_center[Geom::Y], 1.0); + this->rotated = false; + } } + SPItemCtx SPViewBox::get_rctx(const SPItemCtx* ictx, double scale_none) { /* Create copy of item context */ |
