From 443a45342743615977b024ebfbaf1ecf1af7ddc8 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 19 Mar 2014 14:44:31 +0100 Subject: [PATCH] New reverseRTL implementation The old version was a bit complicated and wrong for RtL paragraphs containing LtR text. THe new one is clearer. --- src/Row.cpp | 21 +++++++++++---------- src/Row.h | 2 +- src/TextMetrics.cpp | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Row.cpp b/src/Row.cpp index d784979d34..9da174fa26 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 4f2bd744d4..2282c82d93 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 d949e3a75a..ca6408d2bc 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; } -- 2.39.5