From c56f8aa1ad194ab0714bbab259535ba6e3316085 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Fri, 16 Jan 2015 15:35:59 -0500 Subject: improve precision of i2doc for case where viewBox aspect ratio does not change (bzr r13859) --- src/viewbox.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/viewbox.cpp') diff --git a/src/viewbox.cpp b/src/viewbox.cpp index 662b05686..95a167109 100644 --- a/src/viewbox.cpp +++ b/src/viewbox.cpp @@ -175,7 +175,9 @@ void SPViewBox::apply_viewbox(const Geom::Rect& in) { /* Things are getting interesting */ double scalex = in.width() / ((float) this->viewBox.width()); double scaley = in.height() / ((float) this->viewBox.height()); - double scale = (this->aspect_clip == SP_ASPECT_MEET) ? MIN (scalex, scaley) : MAX (scalex, scaley); + double scale = (scalex + scaley)/2.0; // default if aspect ratio is not changing + if (!Geom::are_near(scalex / scaley, 1.0, Geom::EPSILON)) + scale = (this->aspect_clip == SP_ASPECT_MEET) ? MIN (scalex, scaley) : MAX (scalex, scaley); width = this->viewBox.width() * scale; height = this->viewBox.height() * scale; -- cgit v1.2.3 From 5bd949d8424ad8f690b012dee37d7f303b66c498 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Sun, 25 Jan 2015 18:56:38 -0500 Subject: for viewbox scaling, revert revs 13581, 13582, 13859, and handle the case of uniform scaling as a special case. (Bug 1373311) Fixed bugs: - https://launchpad.net/bugs/1373311 (bzr r13876) --- src/viewbox.cpp | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'src/viewbox.cpp') diff --git a/src/viewbox.cpp b/src/viewbox.cpp index 95a167109..d04d25eb0 100644 --- a/src/viewbox.cpp +++ b/src/viewbox.cpp @@ -164,22 +164,24 @@ void SPViewBox::set_preserveAspectRatio(const gchar* value) { void SPViewBox::apply_viewbox(const Geom::Rect& in) { /* Determine actual viewbox in viewport coordinates */ - /* These are floats since SVGLength is a float: See bug 1374614 */ - float x = 0.0; - float y = 0.0; - float width = in.width(); - float height = in.height(); - // std::cout << " width: " << width << " height: " << height << std::endl; - - if (this->aspect_align != SP_ASPECT_NONE) { - /* Things are getting interesting */ - double scalex = in.width() / ((float) this->viewBox.width()); - double scaley = in.height() / ((float) this->viewBox.height()); - double scale = (scalex + scaley)/2.0; // default if aspect ratio is not changing - if (!Geom::are_near(scalex / scaley, 1.0, Geom::EPSILON)) - scale = (this->aspect_clip == SP_ASPECT_MEET) ? MIN (scalex, scaley) : MAX (scalex, scaley); - width = this->viewBox.width() * scale; - height = this->viewBox.height() * scale; + double x = 0.0; + double y = 0.0; + double scalex = in.width() / this->viewBox.width(); + double scaley = in.height() / this->viewBox.height(); + double scale = 1.0; // uniform scale factor + + if (Geom::are_near(scalex / scaley, 1.0, Geom::EPSILON)) { + // scaling is already uniform, reduce numerical error + scale = (scalex + scaley)/2.0; + scalex = scale; + scaley = scale; + } else if (this->aspect_align != SP_ASPECT_NONE) { + // scaling is not uniform, but force it to be + scale = (this->aspect_clip == SP_ASPECT_MEET) ? MIN (scalex, scaley) : MAX (scalex, scaley); + scalex = scale; + scaley = scale; + double width = this->viewBox.width() * scale; + double height = this->viewBox.height() * scale; /* Now place viewbox to requested position */ switch (this->aspect_align) { @@ -220,12 +222,12 @@ void SPViewBox::apply_viewbox(const Geom::Rect& in) { /* Viewbox transform from scale and position */ Geom::Affine q; - q[0] = width / ((float) this->viewBox.width()); + q[0] = scalex; q[1] = 0.0; q[2] = 0.0; - q[3] = height / ((float) this->viewBox.height()); - q[4] = x - q[0] * ((float) this->viewBox.left()); - q[5] = y - q[3] * ((float) this->viewBox.top()); + q[3] = scaley; + q[4] = x - scalex * this->viewBox.left(); + q[5] = y - scaley * this->viewBox.top(); // std::cout << " q\n" << q << std::endl; -- cgit v1.2.3 From 8f79714bb6f47c78010192aac117f79a275a88ad Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Tue, 3 Feb 2015 14:10:16 -0500 Subject: for viewbox scaling, reduce numerical error if viewbox and page are same size (bzr r13896) --- src/viewbox.cpp | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'src/viewbox.cpp') diff --git a/src/viewbox.cpp b/src/viewbox.cpp index d04d25eb0..91f05668e 100644 --- a/src/viewbox.cpp +++ b/src/viewbox.cpp @@ -14,6 +14,9 @@ #include <2geom/transforms.h> +#include "inkscape.h" +#include "document.h" +#include "util/units.h" #include "viewbox.h" #include "attributes.h" #include "enums.h" @@ -166,22 +169,27 @@ void SPViewBox::apply_viewbox(const Geom::Rect& in) { /* Determine actual viewbox in viewport coordinates */ double x = 0.0; double y = 0.0; - double scalex = in.width() / this->viewBox.width(); - double scaley = in.height() / this->viewBox.height(); - double scale = 1.0; // uniform scale factor + double scale_x = in.width() / this->viewBox.width(); + double scale_y = in.height() / this->viewBox.height(); + double scale_uniform = 1.0; // used only if scaling is uniform + double scale_none = 1.0; // used only if viewbox and page size are same size - if (Geom::are_near(scalex / scaley, 1.0, Geom::EPSILON)) { + if (Geom::are_near(scale_x / scale_y, 1.0, Geom::EPSILON)) { // scaling is already uniform, reduce numerical error - scale = (scalex + scaley)/2.0; - scalex = scale; - scaley = scale; + scale_uniform = (scale_x + scale_y)/2.0; + if (SP_ACTIVE_DOCUMENT) + scale_none = Inkscape::Util::Quantity::convert(1, SP_ACTIVE_DOCUMENT->getDisplayUnit(), "px"); + if (Geom::are_near(scale_uniform / scale_none, 1.0, Geom::EPSILON)) + scale_uniform = scale_none; // objects are same size, reduce numerical error + scale_x = scale_uniform; + scale_y = scale_uniform; } else if (this->aspect_align != SP_ASPECT_NONE) { // scaling is not uniform, but force it to be - scale = (this->aspect_clip == SP_ASPECT_MEET) ? MIN (scalex, scaley) : MAX (scalex, scaley); - scalex = scale; - scaley = scale; - double width = this->viewBox.width() * scale; - double height = this->viewBox.height() * scale; + scale_uniform = (this->aspect_clip == SP_ASPECT_MEET) ? MIN (scale_x, scale_y) : MAX (scale_x, scale_y); + scale_x = scale_uniform; + scale_y = scale_uniform; + double width = this->viewBox.width() * scale_uniform; + double height = this->viewBox.height() * scale_uniform; /* Now place viewbox to requested position */ switch (this->aspect_align) { @@ -222,12 +230,12 @@ void SPViewBox::apply_viewbox(const Geom::Rect& in) { /* Viewbox transform from scale and position */ Geom::Affine q; - q[0] = scalex; + q[0] = scale_x; q[1] = 0.0; q[2] = 0.0; - q[3] = scaley; - q[4] = x - scalex * this->viewBox.left(); - q[5] = y - scaley * this->viewBox.top(); + 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; -- cgit v1.2.3 From b509a33d405dac5d1064f64644966d8304a21823 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Thu, 12 Feb 2015 11:17:54 -0500 Subject: use up-to-date document units when intiallizing viewbox during a file load (bzr r13918) --- src/viewbox.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/viewbox.cpp') diff --git a/src/viewbox.cpp b/src/viewbox.cpp index 91f05668e..e1da23efa 100644 --- a/src/viewbox.cpp +++ b/src/viewbox.cpp @@ -14,9 +14,6 @@ #include <2geom/transforms.h> -#include "inkscape.h" -#include "document.h" -#include "util/units.h" #include "viewbox.h" #include "attributes.h" #include "enums.h" @@ -164,21 +161,20 @@ void SPViewBox::set_preserveAspectRatio(const gchar* value) { } // Apply scaling from viewbox -void SPViewBox::apply_viewbox(const Geom::Rect& in) { +void SPViewBox::apply_viewbox(const Geom::Rect& in, double scale_none) { /* Determine actual viewbox in viewport coordinates */ + // scale_none is the scale that would apply if the viewbox and page size are same size + // it is passed here because it is a double-precision variable, while 'in' is originally float double x = 0.0; double y = 0.0; double scale_x = in.width() / this->viewBox.width(); double scale_y = in.height() / this->viewBox.height(); double scale_uniform = 1.0; // used only if scaling is uniform - double scale_none = 1.0; // used only if viewbox and page size are same size if (Geom::are_near(scale_x / scale_y, 1.0, Geom::EPSILON)) { // scaling is already uniform, reduce numerical error scale_uniform = (scale_x + scale_y)/2.0; - if (SP_ACTIVE_DOCUMENT) - scale_none = Inkscape::Util::Quantity::convert(1, SP_ACTIVE_DOCUMENT->getDisplayUnit(), "px"); if (Geom::are_near(scale_uniform / scale_none, 1.0, Geom::EPSILON)) scale_uniform = scale_none; // objects are same size, reduce numerical error scale_x = scale_uniform; @@ -243,7 +239,7 @@ void SPViewBox::apply_viewbox(const Geom::Rect& in) { this->c2p = q * this->c2p; } -SPItemCtx SPViewBox::get_rctx(const SPItemCtx* ictx) { +SPItemCtx SPViewBox::get_rctx(const SPItemCtx* ictx, double scale_none) { /* Create copy of item context */ SPItemCtx rctx = *ictx; @@ -254,7 +250,7 @@ SPItemCtx SPViewBox::get_rctx(const SPItemCtx* ictx) { if (this->viewBox_set) { // Adjusts c2p for viewbox - apply_viewbox( rctx.viewport ); + apply_viewbox( rctx.viewport, scale_none ); } rctx.i2doc = this->c2p * rctx.i2doc; -- cgit v1.2.3