From b0673bd1fada03b93634c1f2fa7415e1f187f600 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 26 Jan 2017 14:10:23 +0100 Subject: [PATCH] Fix wrong splitting of text row 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 | 5 ++--- src/Row.h | 5 +++-- src/TextMetrics.cpp | 4 +++- status.22x | 3 +++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Row.cpp b/src/Row.cpp index 58a23805f2..ba1a5aa9bb 100644 --- a/src/Row.cpp +++ b/src/Row.cpp @@ -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; diff --git a/src/Row.h b/src/Row.h index 0bd4597746..b35c976083 100644 --- 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 diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index c537e4536b..dbe1f6370d 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -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 diff --git a/status.22x b/status.22x index 5c969b2bf6..23deeb493e 100644 --- a/status.22x +++ b/status.22x @@ -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).