mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Move TextMetrics::findRowElement to Row class
This commit is contained in:
parent
57c3a94730
commit
1fca708c7f
@ -785,9 +785,8 @@ void Cursor::getSurroundingPos(pos_type & left_pos, pos_type & right_pos) const
|
||||
right_pos = -1;
|
||||
|
||||
Row const & row = textRow();
|
||||
TextMetrics const & tm = bv_->textMetrics(text());
|
||||
double dummy = 0;
|
||||
Row::const_iterator cit = tm.findRowElement(row, pos(), boundary(), dummy);
|
||||
Row::const_iterator cit = row.findElement(pos(), boundary(), dummy);
|
||||
// Handle the case of empty row
|
||||
if (cit == row.end()) {
|
||||
if (row.isRTL())
|
||||
|
49
src/Row.cpp
49
src/Row.cpp
@ -569,4 +569,53 @@ void Row::reverseRTL(bool const rtl_par)
|
||||
rtl_ = rtl_par;
|
||||
}
|
||||
|
||||
Row::const_iterator const
|
||||
Row::findElement(pos_type const pos, bool const boundary, double & x) const
|
||||
{
|
||||
/**
|
||||
* When boundary is true, position i is in the row element (pos, endpos)
|
||||
* if
|
||||
* pos < i <= endpos
|
||||
* whereas, when boundary is false, the test is
|
||||
* pos <= i < endpos
|
||||
* The correction below allows to handle both cases.
|
||||
*/
|
||||
int const boundary_corr = (boundary && pos) ? -1 : 0;
|
||||
|
||||
x = left_margin;
|
||||
|
||||
/** Early return in trivial cases
|
||||
* 1) the row is empty
|
||||
* 2) the position is the left-most position of the row; there
|
||||
* is a quirk here however: if the first element is virtual
|
||||
* (end-of-par marker for example), then we have to look
|
||||
* closer
|
||||
*/
|
||||
if (empty()
|
||||
|| (pos == begin()->left_pos() && !boundary
|
||||
&& !begin()->isVirtual()))
|
||||
return begin();
|
||||
|
||||
Row::const_iterator cit = begin();
|
||||
for ( ; cit != end() ; ++cit) {
|
||||
/** Look whether the cursor is inside the element's
|
||||
* span. Note that it is necessary to take the
|
||||
* boundary into account, and to accept virtual
|
||||
* elements, which have pos == endpos.
|
||||
*/
|
||||
if (pos + boundary_corr >= cit->pos
|
||||
&& (pos + boundary_corr < cit->endpos || cit->isVirtual())) {
|
||||
x += cit->pos2x(pos);
|
||||
break;
|
||||
}
|
||||
x += cit->full_width();
|
||||
}
|
||||
|
||||
if (cit == end())
|
||||
--cit;
|
||||
|
||||
return cit;
|
||||
}
|
||||
|
||||
|
||||
} // namespace lyx
|
||||
|
@ -266,6 +266,8 @@ public:
|
||||
void reverseRTL(bool rtl_par);
|
||||
///
|
||||
bool isRTL() const { return rtl_; }
|
||||
/// Find row element that contains \c pos, and compute x offset.
|
||||
const_iterator const findElement(pos_type pos, bool boundary, double & x) const;
|
||||
|
||||
friend std::ostream & operator<<(std::ostream & os, Row const & row);
|
||||
|
||||
|
@ -1471,56 +1471,6 @@ Inset * TextMetrics::checkInsetHit(int x, int y)
|
||||
}
|
||||
|
||||
|
||||
Row::const_iterator const
|
||||
TextMetrics::findRowElement(Row const & row, pos_type const pos,
|
||||
bool const boundary, double & x) const
|
||||
{
|
||||
/**
|
||||
* When boundary is true, position i is in the row element (pos, endpos)
|
||||
* if
|
||||
* pos < i <= endpos
|
||||
* whereas, when boundary is false, the test is
|
||||
* pos <= i < endpos
|
||||
* The correction below allows to handle both cases.
|
||||
*/
|
||||
int const boundary_corr = (boundary && pos) ? -1 : 0;
|
||||
|
||||
x = row.left_margin;
|
||||
|
||||
/** Early return in trivial cases
|
||||
* 1) the row is empty
|
||||
* 2) the position is the left-most position of the row; there
|
||||
* is a quirk here however: if the first element is virtual
|
||||
* (end-of-par marker for example), then we have to look
|
||||
* closer
|
||||
*/
|
||||
if (row.empty()
|
||||
|| (pos == row.begin()->left_pos() && !boundary
|
||||
&& !row.begin()->isVirtual()))
|
||||
return row.begin();
|
||||
|
||||
Row::const_iterator cit = row.begin();
|
||||
for ( ; cit != row.end() ; ++cit) {
|
||||
/** Look whether the cursor is inside the element's
|
||||
* span. Note that it is necessary to take the
|
||||
* boundary into account, and to accept virtual
|
||||
* elements, which have pos == endpos.
|
||||
*/
|
||||
if (pos + boundary_corr >= cit->pos
|
||||
&& (pos + boundary_corr < cit->endpos || cit->isVirtual())) {
|
||||
x += cit->pos2x(pos);
|
||||
break;
|
||||
}
|
||||
x += cit->full_width();
|
||||
}
|
||||
|
||||
if (cit == row.end())
|
||||
--cit;
|
||||
|
||||
return cit;
|
||||
}
|
||||
|
||||
|
||||
int TextMetrics::cursorX(CursorSlice const & sl,
|
||||
bool boundary) const
|
||||
{
|
||||
@ -1533,7 +1483,7 @@ int TextMetrics::cursorX(CursorSlice const & sl,
|
||||
pos_type const pos = sl.pos();
|
||||
|
||||
double x = 0;
|
||||
findRowElement(row, pos, boundary, x);
|
||||
row.findElement(pos, boundary, x);
|
||||
return int(x);
|
||||
|
||||
}
|
||||
|
@ -190,12 +190,6 @@ public:
|
||||
/// x,y are screen coordinates
|
||||
void setCursorFromCoordinates(Cursor & cur, int x, int y);
|
||||
|
||||
/// Helper function: find row element that contains pos, and
|
||||
/// compute x offset.
|
||||
Row::const_iterator const
|
||||
findRowElement(Row const & row, pos_type const pos,
|
||||
bool const boundary, double & x) const;
|
||||
|
||||
///
|
||||
int cursorX(CursorSlice const & cursor, bool boundary) const;
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user