New reverseRTL implementation

The old version was a bit complicated and wrong for RtL paragraphs
containing LtR text. THe new one is clearer.
This commit is contained in:
Jean-Marc Lasgouttes 2014-03-19 14:44:31 +01:00
parent 059de2d04c
commit 443a453427
3 changed files with 13 additions and 12 deletions

View File

@ -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 i = 0;
pos_type const end = elements_.size(); pos_type const end = elements_.size();
while (i < end) { while (i < end) {
// skip LtR elements // gather a sequence of elements with the same direction
while (i < end && !elements_[i].font.isRightToLeft()) bool const rtl = elements_[i].font.isVisibleRightToLeft();
++i;
if (i >= end)
break;
// look for a RTL sequence
pos_type j = i; pos_type j = i;
while (j < end && elements_[j].font.isRightToLeft()) while (j < end && elements_[j].font.isVisibleRightToLeft() == rtl)
++j; ++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; i = j;
} }
// If the paragraph itself is RTL, reverse everything
if (rtl_par)
reverse(elements_.begin(), elements_.end());
} }
} // namespace lyx } // namespace lyx

View File

@ -212,7 +212,7 @@ public:
* Find sequences of right-to-left elements and reverse them. * Find sequences of right-to-left elements and reverse them.
* This should be called once the row is completely built. * 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); friend std::ostream & operator<<(std::ostream & os, Row const & row);

View File

@ -929,7 +929,7 @@ void TextMetrics::breakRow(Row & row, int const right_margin, pit_type const pit
row.pop_back(); row.pop_back();
// make sure that the RTL elements are in reverse ordering // make sure that the RTL elements are in reverse ordering
row.reverseRTL(); row.reverseRTL(text_->isRTL(par));
row.dimension().wid += right_margin; row.dimension().wid += right_margin;
} }