]> git.lyx.org Git - features.git/commitdiff
Simplify setting of RTL in rows
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 22 Sep 2021 11:17:46 +0000 (13:17 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 23 Nov 2021 15:31:30 +0000 (16:31 +0100)
Set RTL status at row creation, which allows to remove a parameter from
cleanupRow.

src/Row.cpp
src/Row.h
src/TextMetrics.cpp

index 6b0faa329241fd59162d6fc290100dae467fd801..4b9836edff3a19bc6d55f88ec8eb128e2f3635f4 100644 (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
index bf49eb1b33025c3238bb7ca9a0d5a59396f11aa1..2c60638f344d2731c32a452a2b28e776225fc873 100644 (file)
--- 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; }
index 76e2fb117067af081a24c1753b5456255cf47f1b..14dc7051ef1c760047a92187a36367b8dce21b90 100644 (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);
        }