The branch, str-metrics, has been updated.

- Log -----------------------------------------------------------------

commit 13551a9f203a5f8d2d28ea9af4eeeb7fe15171b0
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Fri May 16 20:59:22 2014 +0200

    Fix bug where x2pos could return negative values

diff --git a/src/Row.cpp b/src/Row.cpp
index 50a47d3..a0c0dc4 100644
--- a/src/Row.cpp
+++ b/src/Row.cpp
@@ -62,7 +62,7 @@ pos_type Row::Element::x2pos(double &x) const
 {
        //lyxerr << "x2pos: x=" << x << " w=" << width() << " " << *this;
        bool const rtl = font.isVisibleRightToLeft();
-       size_t i;
+       size_t i = 0;
 
        switch (type) {
        case STRING: {
diff --git a/src/frontends/qt4/GuiFontMetrics.cpp 
b/src/frontends/qt4/GuiFontMetrics.cpp
index b6b2f5d..2ac588c 100644
--- a/src/frontends/qt4/GuiFontMetrics.cpp
+++ b/src/frontends/qt4/GuiFontMetrics.cpp
@@ -183,7 +183,12 @@ int GuiFontMetrics::x2pos(docstring const & s, int & x, 
bool const rtl) const
 {
        QTextLayout tl;
        setTextLayout(tl, s, font_, rtl);
-       int const pos = tl.lineForTextPosition(0).xToCursor(x) - 1;
+       int pos = tl.lineForTextPosition(0).xToCursor(x);
+       // take into account the unicode formatting characters
+       if (pos > 0)
+               --pos;
+       if (pos > int(s.length()))
+               pos = s.length();
        // correct x value to the actual cursor position.
        x = tl.lineForTextPosition(0).cursorToX(pos + 1);
        return pos;

-----------------------------------------------------------------------

Summary of changes:
 src/Row.cpp                          |    2 +-
 src/frontends/qt4/GuiFontMetrics.cpp |    7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)


hooks/post-receive
-- 
Repository for new features

Reply via email to