diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2015-01-06 12:37:55 +0000 |
|---|---|---|
| committer | tavmjong-free <tavmjong@free.fr> | 2015-01-06 12:37:55 +0000 |
| commit | 5420b476f4668b03f4ce169494792c78b3a3235d (patch) | |
| tree | eb9e294469079afe8ace1c2809e0b41815d75b49 /src | |
| parent | UI/i18n. Fixing inconsistencies in the Fillet/Chamfer LPE dialogs. (diff) | |
| download | inkscape-5420b476f4668b03f4ce169494792c78b3a3235d.tar.gz inkscape-5420b476f4668b03f4ce169494792c78b3a3235d.zip | |
Add getDocumentScale() to return "real-world" to "user-unit" scale factor.
Use it to correct text postion after removing from path.
(bzr r13843)
Diffstat (limited to 'src')
| -rw-r--r-- | src/document.cpp | 20 | ||||
| -rw-r--r-- | src/document.h | 1 | ||||
| -rw-r--r-- | src/sp-tspan.cpp | 6 |
3 files changed, 25 insertions, 2 deletions
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) diff --git a/src/document.h b/src/document.h index d88670608..22c341eae 100644 --- a/src/document.h +++ b/src/document.h @@ -242,6 +242,7 @@ public: SPDocument *doUnref(); Inkscape::Util::Unit const* getDisplayUnit() const; Inkscape::Util::Unit const& getSVGUnit() const; + Geom::Scale getDocumentScale() const; Inkscape::Util::Quantity getWidth() const; Inkscape::Util::Quantity getHeight() const; Geom::Point getDimensions() const; diff --git a/src/sp-tspan.cpp b/src/sp-tspan.cpp index c3f7689e7..147efff33 100644 --- a/src/sp-tspan.cpp +++ b/src/sp-tspan.cpp @@ -42,6 +42,7 @@ #include "style.h" #include "xml/repr.h" #include "document.h" +#include "2geom/transforms.h" #include "sp-factory.h" @@ -447,7 +448,8 @@ void sp_textpath_to_text(SPObject *tp) } Geom::Point xy = bbox->min(); - + xy *= tp->document->getDocumentScale().inverse(); // Convert to user-units. + // make a list of textpath children GSList *tp_reprs = NULL; @@ -468,7 +470,7 @@ void sp_textpath_to_text(SPObject *tp) tp->deleteObject(); g_slist_free(tp_reprs); - // set x/y on text + // set x/y on text (to be near where it was when on path) /* fixme: Yuck, is this really the right test? */ if (xy[Geom::X] != 1e18 && xy[Geom::Y] != 1e18) { sp_repr_set_svg_double(text->getRepr(), "x", xy[Geom::X]); |
