From f27d2cfa30aecd39afcac8a5b6532f9cf348aed6 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Sat, 27 Jan 2018 12:03:09 +0100 Subject: [PATCH] Revert "Remove 'premature optimization' that proved buggy" This reverts commit 894ae19224d0537c0c9ebd9ad45e547279769bd8. Fixes bug 10996. --- src/TextMetrics.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 620514421b..6c5a322277 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -834,6 +834,11 @@ bool TextMetrics::breakRow(Row & row, int const right_margin) const // the width available for the row. int const width = max_width_ - row.right_margin; + if (pos >= end || row.width() > width) { + row.endpos(end); + return need_new_row; + } + #if 0 //FIXME: As long as leftMargin() is not correctly implemented for // MARGIN_RIGHT_ADDRESS_BOX, we should also not do this here. @@ -852,7 +857,10 @@ bool TextMetrics::breakRow(Row & row, int const right_margin) const // or the end of the par, then build a representation of the row. pos_type i = pos; FontIterator fi = FontIterator(*this, par, row.pit(), pos); - while (i < end && row.width() <= width) { + do { + // this can happen for an empty row after a newline + if (i >= end) + break; char_type c = par.getChar(i); // The most special cases are handled first. if (par.isInset(i)) { @@ -934,7 +942,7 @@ bool TextMetrics::breakRow(Row & row, int const right_margin) const ++i; ++fi; - } + } while (i < end && row.width() <= width); row.finalizeLast(); row.endpos(i); -- 2.39.5