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 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

View File

@ -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);

View File

@ -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;
}