From 5420b476f4668b03f4ce169494792c78b3a3235d Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 6 Jan 2015 13:37:55 +0100 Subject: Add getDocumentScale() to return "real-world" to "user-unit" scale factor. Use it to correct text postion after removing from path. (bzr r13843) --- src/document.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 4b074c2fa..2caefb4ed 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -604,12 +604,32 @@ 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) -- cgit v1.2.3