commit 8491962c6bc1c73df076fa4807cc6ee295ccce41
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Thu Jan 26 14:10:23 2017 +0100
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.
---
src/Row.cpp | 5 ++---
src/Row.h | 5 +++--
src/TextMetrics.cpp | 4 +++-
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/Row.cpp b/src/Row.cpp
index 9df5724..16ce90d 100644
--- a/src/Row.cpp
+++ b/src/Row.cpp
@@ -126,7 +126,6 @@ pos_type Row::Element::x2pos(int &x) const
}
//lyxerr << "=> p=" << pos + i << " x=" << x << endl;
return pos + i;
-
}
@@ -446,7 +445,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;
@@ -493,7 +492,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 7ae9c11..2204499 100644
--- a/src/Row.h
+++ b/src/Row.h
@@ -243,10 +243,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 3f6457e..96c2fb5 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -941,7 +941,9 @@ bool TextMetrics::breakRow(Row & row, int const
right_margin) const
// 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