summaryrefslogtreecommitdiffstats
path: root/src/document.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-01-16 16:18:45 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-01-16 16:18:45 +0000
commit03cb69220632b0c674efff5be3aab8be35d23eff (patch)
tree464a1f74c57b796604ceb38c1687d579d2891800 /src/document.cpp
parentupdate to trunk (diff)
parentTest implementation of 'shape-padding'. (diff)
downloadinkscape-03cb69220632b0c674efff5be3aab8be35d23eff.tar.gz
inkscape-03cb69220632b0c674efff5be3aab8be35d23eff.zip
update to trunk
(bzr r13708.1.7)
Diffstat (limited to 'src/document.cpp')
-rw-r--r--src/document.cpp56
1 files changed, 53 insertions, 3 deletions
diff --git a/src/document.cpp b/src/document.cpp
index c7d14727a..2caefb4ed 100644
--- a/src/document.cpp
+++ b/src/document.cpp
@@ -604,12 +604,61 @@ Inkscape::Util::Unit const* SPDocument::getDisplayUnit() const
/// guaranteed not to return nullptr
// returns 'px' units as default, like legacy Inkscape
+// THIS SHOULD NOT BE USED... INSTEAD USE DOCUMENT SCALE
Inkscape::Util::Unit const& SPDocument::getSVGUnit() const
{
SPNamedView const* nv = sp_document_namedview(this, NULL);
return nv ? nv->getSVGUnit() : *unit_table.getUnit("px");
}
+/// Returns document scale as defined by width/height and viewBox (real world to user-units).
+Geom::Scale SPDocument::getDocumentScale() const
+{
+ Geom::Scale scale;
+ if( root->viewBox_set ) {
+ double scale_x = 1.0;
+ double scale_y = 1.0;
+ if( root->viewBox.width() > 0.0 ) {
+ scale_x = root->width.computed / root->viewBox.width();
+ }
+ if( root->viewBox.height() > 0.0 ) {
+ scale_y = root->height.computed / root->viewBox.height();
+ }
+ scale = Geom::Scale(scale_x, scale_y);
+ }
+ // std::cout << "SPDocument::getDocumentScale():\n" << scale << std::endl;
+ return scale;
+}
+
+// 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 +788,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())