Simplify setting of RTL in rows

Set RTL status at row creation, which allows to remove a parameter from
cleanupRow.
This commit is contained in:
Jean-Marc Lasgouttes 2021-09-22 13:17:46 +02:00
parent d723b90344
commit a06f0e48ec
3 changed files with 11 additions and 9 deletions

View File

@ -624,7 +624,7 @@ Row::Elements Row::shortenIfNeeded(int const w, int const next_width)
}
void Row::reverseRTL(bool const rtl_par)
void Row::reverseRTL()
{
pos_type i = 0;
pos_type const end = elements_.size();
@ -636,14 +636,13 @@ void Row::reverseRTL(bool const rtl_par)
++j;
// if the direction is not the same as the paragraph
// direction, the sequence has to be reverted.
if (rtl != rtl_par)
if (rtl != rtl_)
reverse(elements_.begin() + i, elements_.begin() + j);
i = j;
}
// If the paragraph itself is RTL, reverse everything
if (rtl_par)
if (rtl_)
reverse(elements_.begin(), elements_.end());
rtl_ = rtl_par;
}
Row::const_iterator const

View File

@ -301,10 +301,12 @@ public:
* Find sequences of right-to-left elements and reverse them.
* This should be called once the row is completely built.
*/
void reverseRTL(bool rtl_par);
void reverseRTL();
///
bool isRTL() const { return rtl_; }
///
void setRTL(bool rtl) { rtl_ = rtl; }
///
bool needsChangeBar() const { return changebar_; }
///
void needsChangeBar(bool ncb) { changebar_ = ncb; }

View File

@ -1050,6 +1050,7 @@ Row newRow(TextMetrics const & tm, pit_type pit, pos_type pos, bool is_rtl)
nrow.pos(pos);
nrow.left_margin = tm.leftMargin(pit, pos);
nrow.right_margin = tm.rightMargin(pit);
nrow.setRTL(is_rtl);
if (is_rtl)
swap(nrow.left_margin, nrow.right_margin);
// Remember that the row width takes into account the left_margin
@ -1059,7 +1060,7 @@ Row newRow(TextMetrics const & tm, pit_type pit, pos_type pos, bool is_rtl)
}
void cleanupRow(Row & row, bool at_end, bool is_rtl)
void cleanupRow(Row & row, bool at_end)
{
if (row.empty()) {
row.endpos(0);
@ -1074,7 +1075,7 @@ void cleanupRow(Row & row, bool at_end, bool is_rtl)
// boundary exists when there was no space at the end of row
row.right_boundary(!at_end && row.back().endpos == row.endpos());
// make sure that the RTL elements are in reverse ordering
row.reverseRTL(is_rtl);
row.reverseRTL();
}
@ -1118,7 +1119,7 @@ RowList TextMetrics::breakParagraph(Row const & bigrow) const
: fcit->row_flags;
if (rows.empty() || needsRowBreak(f1, f2)) {
if (!rows.empty())
cleanupRow(rows.back(), false, is_rtl);
cleanupRow(rows.back(), false);
pos_type pos = rows.empty() ? 0 : rows.back().endpos();
rows.push_back(newRow(*this, bigrow.pit(), pos, is_rtl));
// the width available for the row.
@ -1152,7 +1153,7 @@ RowList TextMetrics::breakParagraph(Row const & bigrow) const
}
if (!rows.empty()) {
cleanupRow(rows.back(), true, is_rtl);
cleanupRow(rows.back(), true);
// Last row in paragraph is flushed
rows.back().flushed(true);
}