From a06f0e48ec579c7ff4e059f08fd0e3983f6d4dfe Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 22 Sep 2021 13:17:46 +0200 Subject: [PATCH] Simplify setting of RTL in rows Set RTL status at row creation, which allows to remove a parameter from cleanupRow. --- src/Row.cpp | 7 +++---- src/Row.h | 4 +++- src/TextMetrics.cpp | 9 +++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Row.cpp b/src/Row.cpp index 6b0faa3292..4b9836edff 100644 --- a/src/Row.cpp +++ b/src/Row.cpp @@ -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 diff --git a/src/Row.h b/src/Row.h index bf49eb1b33..2c60638f34 100644 --- a/src/Row.h +++ b/src/Row.h @@ -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; } diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 76e2fb1170..14dc7051ef 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -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); }