summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2015-01-05 09:35:44 +0000
committertavmjong-free <tavmjong@free.fr>2015-01-05 09:35:44 +0000
commitf8ba98f4439051bc268013a5aa0b0e2a97a45303 (patch)
tree74c44cf15afb1856af20329259c7f62081751ecd /src
parentFix for Bug #1407326 (Typo (toogle) in filletchanferpoinarray.cpp). (diff)
downloadinkscape-f8ba98f4439051bc268013a5aa0b0e2a97a45303.tar.gz
inkscape-f8ba98f4439051bc268013a5aa0b0e2a97a45303.zip
Avoid calling root->updateRepr() twice when changing width and height.
(bzr r13837)
Diffstat (limited to 'src')
-rw-r--r--src/document.cpp36
-rw-r--r--src/document.h1
-rw-r--r--src/ui/widget/page-sizer.cpp3
3 files changed, 35 insertions, 5 deletions
diff --git a/src/document.cpp b/src/document.cpp
index c7d14727a..4b074c2fa 100644
--- a/src/document.cpp
+++ b/src/document.cpp
@@ -610,6 +610,35 @@ Inkscape::Util::Unit const& SPDocument::getSVGUnit() const
return nv ? nv->getSVGUnit() : *unit_table.getUnit("px");
}
+// Avoid calling root->updateRepr() twice by combining setting width and height.
+// (As done on every delete as clipboard calls this via fitToRect(). Also called in page-sizer.cpp)
+void SPDocument::setWidthAndHeight(const Inkscape::Util::Quantity &width, const Inkscape::Util::Quantity &height, bool changeSize)
+{
+ Inkscape::Util::Unit const *old_width_units = unit_table.getUnit("px");
+ if (root->width.unit)
+ old_width_units = unit_table.getUnit(root->width.unit);
+ gdouble old_width_converted = Inkscape::Util::Quantity::convert(root->width.value, old_width_units, width.unit);
+
+ root->width.computed = width.value("px");
+ root->width.value = width.quantity;
+ root->width.unit = (SVGLength::Unit) width.unit->svgUnit();
+
+ Inkscape::Util::Unit const *old_height_units = unit_table.getUnit("px");
+ if (root->height.unit)
+ old_height_units = unit_table.getUnit(root->height.unit);
+ gdouble old_height_converted = Inkscape::Util::Quantity::convert(root->height.value, old_height_units, height.unit);
+
+ root->height.computed = height.value("px");
+ root->height.value = height.quantity;
+ root->height.unit = (SVGLength::Unit) height.unit->svgUnit();
+
+ if (root->viewBox_set && changeSize)
+ root->viewBox.setMax(Geom::Point(
+ root->viewBox.left() + (root->width.value / old_width_converted ) * root->viewBox.width(),
+ root->viewBox.top() + (root->height.value / old_height_converted) * root->viewBox.height()));
+ root->updateRepr();
+}
+
Inkscape::Util::Quantity SPDocument::getWidth() const
{
g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit("")));
@@ -739,9 +768,10 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins)
rect.min() - Geom::Point(margin_left, margin_bottom),
rect.max() + Geom::Point(margin_right, margin_top));
-
- setWidth(Inkscape::Util::Quantity(Inkscape::Util::Quantity::convert(rect_with_margins.width(), "px", nv_units), nv_units));
- setHeight(Inkscape::Util::Quantity(Inkscape::Util::Quantity::convert(rect_with_margins.height(), "px", nv_units), nv_units));
+ setWidthAndHeight(
+ Inkscape::Util::Quantity(Inkscape::Util::Quantity::convert(rect_with_margins.width(), "px", nv_units), nv_units),
+ Inkscape::Util::Quantity(Inkscape::Util::Quantity::convert(rect_with_margins.height(), "px", nv_units), nv_units)
+ );
Geom::Translate const tr(
Geom::Point(0, old_height - rect_with_margins.height())
diff --git a/src/document.h b/src/document.h
index 4a24ff502..d88670608 100644
--- a/src/document.h
+++ b/src/document.h
@@ -246,6 +246,7 @@ public:
Inkscape::Util::Quantity getHeight() const;
Geom::Point getDimensions() const;
Geom::OptRect preferredBounds() const;
+ void setWidthAndHeight(const Inkscape::Util::Quantity &width, const Inkscape::Util::Quantity &height, bool changeSize=true);
void setWidth(const Inkscape::Util::Quantity &width, bool changeSize=true);
void setHeight(const Inkscape::Util::Quantity &height, bool changeSize=true);
void setViewBox(const Geom::Rect &viewBox);
diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp
index d36c11ace..8c3b44bf5 100644
--- a/src/ui/widget/page-sizer.cpp
+++ b/src/ui/widget/page-sizer.cpp
@@ -479,8 +479,7 @@ PageSizer::setDim (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h, bool
if (SP_ACTIVE_DESKTOP && !_widgetRegistry->isUpdating()) {
SPDocument *doc = SP_ACTIVE_DESKTOP->getDocument();
Inkscape::Util::Quantity const old_height = doc->getHeight();
- doc->setWidth (w, changeSize);
- doc->setHeight (h, changeSize);
+ doc->setWidthAndHeight (w, h, changeSize);
// The origin for the user is in the lower left corner; this point should remain stationary when
// changing the page size. The SVG's origin however is in the upper left corner, so we must compensate for this
if (changeSize) {