From 77c9748e54f9170aac7c8b292377951f73da487f Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Mon, 20 Jan 2014 20:11:09 -0500 Subject: Fix imprecise viewBox dimensions on page size change (bug #1235279). Fixed bugs: - https://launchpad.net/bugs/1235279 (bzr r12965) --- src/document.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index e56adee68..8b956d5e7 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -585,6 +585,7 @@ Inkscape::Util::Quantity SPDocument::getWidth() const void SPDocument::setWidth(const Inkscape::Util::Quantity &width) { gdouble old_computed = root->width.computed; + gdouble old_value = root->width.value; root->width.computed = width.value("px"); /* SVG does not support meters as a unit, so we must translate meters to * cm when writing */ @@ -596,8 +597,14 @@ void SPDocument::setWidth(const Inkscape::Util::Quantity &width) root->width.unit = (SVGLength::Unit) width.unit->svgUnit(); } - if (root->viewBox_set) - root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.computed / old_computed) * root->viewBox.width(), root->viewBox.bottom())); + if (root->viewBox_set) { + if (abs(old_value - root->viewBox.width()) < 0.00001) { + root->viewBox.setMax(Geom::Point(root->viewBox.left() + root->width.value, root->viewBox.bottom())); + } + else { + root->viewBox.setMax(Geom::Point(root->viewBox.left() + (root->width.computed / old_computed) * root->viewBox.width(), root->viewBox.bottom())); + } + } root->updateRepr(); } @@ -622,6 +629,7 @@ Inkscape::Util::Quantity SPDocument::getHeight() const void SPDocument::setHeight(const Inkscape::Util::Quantity &height) { gdouble old_computed = root->height.computed; + gdouble old_value = root->height.value; root->height.computed = height.value("px"); /* SVG does not support meters as a unit, so we must translate meters to * cm when writing */ @@ -633,8 +641,14 @@ void SPDocument::setHeight(const Inkscape::Util::Quantity &height) root->height.unit = (SVGLength::Unit) height.unit->svgUnit(); } - if (root->viewBox_set) - root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.computed / old_computed) * root->viewBox.height())); + if (root->viewBox_set) { + if (abs(old_value - root->viewBox.height()) < 0.00001) { + root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + root->height.value)); + } + else { + root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + (root->height.computed / old_computed) * root->viewBox.height())); + } + } root->updateRepr(); } -- cgit v1.2.3