From 8911d9a8ca0c7f4ef1476b2f056adf2afa4e99cd Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Thu, 30 Jun 2011 22:46:15 +0200 Subject: Implement decent snapping to text (baseline & anchor), and provide a toggle button for this (as requested in LP bug #727281 ) (bzr r10392) --- src/libnrtype/Layout-TNG-OutIter.cpp | 21 +++++++++++++++++++++ src/libnrtype/Layout-TNG.h | 2 ++ 2 files changed, 23 insertions(+) (limited to 'src/libnrtype') diff --git a/src/libnrtype/Layout-TNG-OutIter.cpp b/src/libnrtype/Layout-TNG-OutIter.cpp index 4d461a486..1d300b210 100644 --- a/src/libnrtype/Layout-TNG-OutIter.cpp +++ b/src/libnrtype/Layout-TNG-OutIter.cpp @@ -13,6 +13,7 @@ #include "font-instance.h" #include "svg/svg-length.h" #include <2geom/transforms.h> +#include <2geom/line.h> #include "style.h" namespace Inkscape { @@ -250,6 +251,26 @@ boost::optional Layout::baselineAnchorPoint() const } } +Geom::Path Layout::baseline() const +{ + iterator pos = this->begin(); + Geom::Point left_pt = this->characterAnchorPoint(pos); + pos.thisEndOfLine(); + Geom::Point right_pt = this->characterAnchorPoint(pos); + + if (this->_blockProgression() == LEFT_TO_RIGHT || this->_blockProgression() == RIGHT_TO_LEFT) { + left_pt = Geom::Point(left_pt[Geom::Y], left_pt[Geom::X]); + right_pt = Geom::Point(right_pt[Geom::Y], right_pt[Geom::X]); + } + + Geom::Path baseline; + baseline.start(left_pt); + baseline.appendNew(right_pt); + + return baseline; +} + + Geom::Point Layout::chunkAnchorPoint(iterator const &it) const { unsigned chunk_index; diff --git a/src/libnrtype/Layout-TNG.h b/src/libnrtype/Layout-TNG.h index 7d0c58c3e..6ab02c0e3 100644 --- a/src/libnrtype/Layout-TNG.h +++ b/src/libnrtype/Layout-TNG.h @@ -486,6 +486,8 @@ public: For rightmost text, the rightmost... you probably got it by now ;-)*/ boost::optional baselineAnchorPoint() const; + Geom::Path baseline() const; + /** This is that value to apply to the x,y attributes of tspan role=line elements, and hence it takes alignment into account. */ Geom::Point chunkAnchorPoint(iterator const &it) const; -- cgit v1.2.3