]> git.lyx.org Git - features.git/commitdiff
Fix wrong splitting of text row
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 26 Jan 2017 13:10:23 +0000 (14:10 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 6 Feb 2017 09:37:12 +0000 (10:37 +0100)
The code that tries to decide whether it is worth splitting a given
text row element had a shortcoming: it did not take into account the
left margin of the new row that would be created.

The problem is that this left margin is not the same as the left
margin of the current row, because there can be for example
indentation effects.

To fix this problem, we pass the amount of available space on the
next row as a parameter of Row::shortenIfNeeded.

Note that there is no need to care about RtL row elements at this
point, since the bidi algorithm will be applied to the row
subsequently.
(cherry picked from commit 8491962c6bc1c73df076fa4807cc6ee295ccce41)

src/Row.cpp
src/Row.h
src/TextMetrics.cpp
status.22x

index 58a23805f2ff35491df7fe56d265fcda40e85b52..ba1a5aa9bbca4316c1de22e9ca7031ee43c54d8a 100644 (file)
@@ -110,7 +110,6 @@ pos_type Row::Element::x2pos(int &x) const
        }
        //lyxerr << "=> p=" << pos + i << " x=" << x << endl;
        return pos + i;
-
 }
 
 
@@ -413,7 +412,7 @@ void Row::pop_back()
 }
 
 
-bool Row::shortenIfNeeded(pos_type const keep, int const w)
+bool Row::shortenIfNeeded(pos_type const keep, int const w, int const next_width)
 {
        if (empty() || width() <= w)
                return false;
@@ -460,7 +459,7 @@ bool Row::shortenIfNeeded(pos_type const keep, int const w)
                         * next row. Thus breaking does not help.
                         */
                        if (wid_brk + cit_brk->dim.wid < w
-                           && dim_.wid - (wid_brk + brk.dim.wid) >= w) {
+                           && dim_.wid - (wid_brk + brk.dim.wid) >= next_width) {
                                break;
                        }
                        end_ = brk.endpos;
index 0bd4597746616ac5dd03fb3f2a6b57a226f933f4..b35c976083fccb98744d1524bbcd5faf83ba26b5 100644 (file)
--- a/src/Row.h
+++ b/src/Row.h
@@ -230,10 +230,11 @@ public:
         * separator and update endpos if necessary. If all that
         * remains is a large word, cut it to \param width.
         * \param body_pos minimum amount of text to keep.
-        * \param width maximum width of the row
+        * \param width maximum width of the row.
+        * \param available width on next row.
         * \return true if the row has been shortened.
         */
-       bool shortenIfNeeded(pos_type const body_pos, int const width);
+       bool shortenIfNeeded(pos_type const body_pos, int const width, int const next_width);
 
        /**
         * If last element of the row is a string, compute its width
index c537e4536b0715e74c4902180da2118acf268a88..dbe1f6370dbbb86b3d42a756dd6cedb4e71fce36 100644 (file)
@@ -933,7 +933,9 @@ void TextMetrics::breakRow(Row & row, int const right_margin, pit_type const pit
 
        // if the row is too large, try to cut at last separator. In case
        // of success, reset indication that the row was broken abruptly.
-       if (row.shortenIfNeeded(body_pos, width))
+       int const next_width = max_width_ - leftMargin(max_width_, row.pit(), row.endpos())
+               - rightMargin(row.pit());
+       if (row.shortenIfNeeded(body_pos, width, next_width))
                row.right_boundary(!row.empty() && row.back().endpos == row.endpos());
 
        // make sure that the RTL elements are in reverse ordering
index 5c969b2bf6e398cd0fcd54cf70820fca9ec18b3b..23deeb493e5abed83260063c5368f35d8833b685 100644 (file)
@@ -161,6 +161,9 @@ What's new
 - Fix cursor movement when the document contains high-plane Unicode
   characters (bug 10443).
 
+- Fix wrong on-screen text layout where a word would be alone on a
+  line.
+
 - Fix crash when the document contains Unicode line-breaking characters.
 
 - Allow using colors supported by xcolor inside mathed (bug 10417).