mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
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:
parent
059de2d04c
commit
443a453427
19
src/Row.cpp
19
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;
|
||||
// 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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user