summaryrefslogtreecommitdiffstats
path: root/src/viewbox.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-03-18 18:07:14 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-03-18 18:07:14 +0000
commite77956b4dbd029c9f6949f81fe083606f995c624 (patch)
tree74adda4df8986d65f70efb341c6235277361fd35 /src/viewbox.cpp
parentupdated code to work on 0.92 code (diff)
parentLatvian translation update (diff)
downloadinkscape-e77956b4dbd029c9f6949f81fe083606f995c624.tar.gz
inkscape-e77956b4dbd029c9f6949f81fe083606f995c624.zip
update to trunk
(bzr r12588.1.39)
Diffstat (limited to 'src/viewbox.cpp')
-rw-r--r--src/viewbox.cpp50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/viewbox.cpp b/src/viewbox.cpp
index 662b05686..e1da23efa 100644
--- a/src/viewbox.cpp
+++ b/src/viewbox.cpp
@@ -161,23 +161,31 @@ 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 */
- /* 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 = (this->aspect_clip == SP_ASPECT_MEET) ? MIN (scalex, scaley) : MAX (scalex, scaley);
- width = this->viewBox.width() * scale;
- height = this->viewBox.height() * scale;
+ // 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
+
+ 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 (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_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) {
@@ -218,12 +226,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] = scale_x;
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] = 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;
@@ -231,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;
@@ -242,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;