commit 443a45342743615977b024ebfbaf1ecf1af7ddc8
Author: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date:   Wed Mar 19 14:44:31 2014 +0100

    New reverseRTL implementation
    
    The old version was a bit complicated and wrong for RtL paragraphs
    containing LtR text. THe new one is clearer.

diff --git a/src/Row.cpp b/src/Row.cpp
index d784979..9da174f 100644
--- a/src/Row.cpp
+++ b/src/Row.cpp
@@ -382,24 +382,25 @@ void Row::shorten_if_needed(pos_type const keep, int 
const w)
 }
 
 
-void Row::reverseRTL()
+void Row::reverseRTL(bool const rtl_par)
 {
        pos_type i = 0;
        pos_type const end = elements_.size();
        while (i < end) {
-               // skip LtR elements
-               while (i < end && !elements_[i].font.isRightToLeft())
-                       ++i;
-               if (i >= end)
-                       break;
-
-               // look for a RTL sequence
+               // gather a sequence of elements with the same direction
+               bool const rtl = elements_[i].font.isVisibleRightToLeft();
                pos_type j = i;
-               while (j < end && elements_[j].font.isRightToLeft())
+               while (j < end && elements_[j].font.isVisibleRightToLeft() == 
rtl)
                        ++j;
-               reverse(elements_.begin() + i, elements_.begin() + j);
+               // if the direction is not the same as the paragraph
+               // direction, the sequence has to be reverted.
+               if (rtl != rtl_par)
+                       reverse(elements_.begin() + i, elements_.begin() + j);
                i = j;
        }
+       // If the paragraph itself is RTL, reverse everything
+       if (rtl_par)
+               reverse(elements_.begin(), elements_.end());
 }
 
 } // namespace lyx
diff --git a/src/Row.h b/src/Row.h
index 4f2bd74..2282c82 100644
--- a/src/Row.h
+++ b/src/Row.h
@@ -212,7 +212,7 @@ public:
         * Find sequences of right-to-left elements and reverse them.
         * This should be called once the row is completely built.
         */
-       void reverseRTL();
+       void reverseRTL(bool rtl_par);
 
        friend std::ostream & operator<<(std::ostream & os, Row const & row);
 
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index d949e3a..ca6408d 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -929,7 +929,7 @@ void TextMetrics::breakRow(Row & row, int const 
right_margin, pit_type const pit
                row.pop_back();
 
        // make sure that the RTL elements are in reverse ordering
-       row.reverseRTL();
+       row.reverseRTL(text_->isRTL(par));
 
        row.dimension().wid += right_margin;
 }

Reply via email to