commit 79014c7551de71488bb18e58ae8344cdbbde9490
Author: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date:   Fri Oct 18 17:55:30 2013 +0200

    More fixes to cursorX
    
    In Row::Element::pos2x, handle the boundaries in a cleaner way.

diff --git a/src/Row.cpp b/src/Row.cpp
index d074d73..d7940e9 100644
--- a/src/Row.cpp
+++ b/src/Row.cpp
@@ -36,17 +36,23 @@ using frontend::FontMetrics;
 
 double Row::Element::pos2x(pos_type const i) const
 {
+       LASSERT(i >= pos && i <= endpos, return 0);
+
        bool const rtl = font.isVisibleRightToLeft();
 
-       // handle first the two bounds of the element
-       if ((!rtl && pos >= i) || (rtl && endpos <= i))
-               return 0;
-       if ((!rtl && endpos <= i) || (rtl && pos >= i))
-               return width();
+       int w = 0;
+       //handle first the two bounds of the element
+       if (i == pos)
+               w = 0;
+       else if (i == endpos)
+               w = width();
+       else {
+               LASSERT(type == STRING, return 0);
+               FontMetrics const & fm = theFontMetrics(font);
+               // FIXME Avoid caching of metrics there?
+               w = fm.width(str.substr(0, i - pos));
+       }
 
-       FontMetrics const & fm = theFontMetrics(font);
-       // FIXME Avoid caching of metrics there?
-       int const w = fm.width(str.substr(0, i - pos));
        if (rtl)
                return width() - w;
        else
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index 8563975..b894133 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -1613,15 +1613,16 @@ int TextMetrics::cursorX(CursorSlice const & sl,
        double x = row.x;
 
        /**
-        * When boundary is true, position is on the row element (pos, endpos)
+        * When boundary is true, position i is in the row element (pos, endpos)
         * if
-        *    pos < pos <= endpos
+        *    pos < i <= endpos
         * whereas, when boundary is false, the test is
-        *    pos <= pos < endpos
+        *    pos <= i < endpos
         * The correction below allows to handle both cases.
        */
        int const boundary_corr = (boundary && pos) ? -1 : 0;
 
+       //?????
        if (row.empty()
            || (row.begin()->font.isVisibleRightToLeft()
                && pos == row.begin()->endpos))

Reply via email to