The branch, rowpainter2, has been updated. - Log -----------------------------------------------------------------
commit 038f003be671995e7c60b2be884c7799303ca840 Author: Jean-Marc Lasgouttes <lasgout...@lyx.org> Date: Sat Jul 18 20:37:53 2015 +0200 Rewrite RowPainter::paintOnlyInsets to use row elements diff --git a/src/RowPainter.cpp b/src/RowPainter.cpp index 9469012..1c74107 100644 --- a/src/RowPainter.cpp +++ b/src/RowPainter.cpp @@ -606,27 +606,27 @@ void RowPainter::paintLast() void RowPainter::paintOnlyInsets() { - CoordCache const & cache = pi_.base.bv->coordCache(); - pos_type const end = row_.endpos(); - for (pos_type pos = row_.pos(); pos != end; ++pos) { - // If outer row has changed, nested insets are repaint completely. - Inset const * inset = par_.getInset(pos); - bool const nested_inset = inset && - ((inset->asInsetMath() && - !inset->asInsetMath()->asMacroTemplate()) - || inset->asInsetText() - || inset->asInsetTabular()); - if (!nested_inset) - continue; - if (x_ > pi_.base.bv->workWidth() - || !cache.getInsets().has(inset)) - continue; - x_ = cache.getInsets().x(inset); - Font const font = text_metrics_.displayFont(pit_, pos); - paintInset(inset, font, par_.lookupChange(pos), pos); + Row::const_iterator cit = row_.begin(); + Row::const_iterator const & end = row_.end(); + for ( ; cit != end ; ++cit) { + Row::Element const & e = *cit; + if (e.type == Row::INSET) { + // If outer row has changed, nested insets are repainted completely. + pi_.base.bv->coordCache().insets().add(e.inset, int(x_), yo_); + bool const nested_inset = + (e.inset->asInsetMath() && !e.inset->asInsetMath()->asMacroTemplate()) + || e.inset->asInsetText() || e.inset->asInsetTabular(); + if (!nested_inset) { + x_ += e.full_width(); + continue; + } + paintInset(e.inset, e.font, e.change, e.pos); + } else + x_ += e.full_width(); } } + void RowPainter::paintText() { Row::const_iterator cit = row_.begin(); commit d328fb20213bb96c32421cfd6c7db567ae02b0b1 Author: Jean-Marc Lasgouttes <lasgout...@lyx.org> Date: Sat Jul 18 00:39:55 2015 +0200 Rewrite Cursor::posVisToRowExtremity without Bidi class It is trivial to implement it using TextMetrics::getPosNearX. diff --git a/src/Cursor.cpp b/src/Cursor.cpp index c89db5d..270cf08 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -1018,139 +1018,17 @@ bool Cursor::posVisToNewRow(bool movingLeft) void Cursor::posVisToRowExtremity(bool left) { - // prepare bidi tables - Paragraph const & par = paragraph(); - Buffer const & buf = *buffer(); - Row const & row = textRow(); - Bidi bidi; - bidi.computeTables(par, buf, row); - LYXERR(Debug::RTL, "entering extremity: " << pit() << "," << pos() << "," << (boundary() ? 1 : 0)); - if (left) { // move to leftmost position - // if this is an RTL paragraph, and we're at the last row in the - // paragraph, move to lastpos - if (par.isRTL(buf.params()) && row.endpos() == lastpos()) - pos() = lastpos(); - else { - pos() = bidi.vis2log(row.pos()); - - // Moving to the leftmost position in the row, - // the cursor should normally be placed to the - // *left* of the leftmost position. A very - // common exception, though, is if the - // leftmost character also happens to be the - // separator at the (logical) end of the row - // --- in this case, the separator is - // positioned beyond the left margin, and we - // don't want to move the cursor there (moving - // to the left of the separator is equivalent - // to moving to the next line). So, in this - // case we actually want to place the cursor - // to the *right* of the leftmost position - // (the separator). Another exception is if - // we're moving to the logically last position - // in the row, which is *not* a separator: - // this means that the entire row has no - // separators (if there were any, the row - // would have been broken there); and - // therefore in this case we also move to the - // *right* of the last position (this - // indicates to the user that there is no - // space after this position, and is - // consistent with the behavior in the middle - // of a row --- moving right or left moves to - // the next/previous character; if we were to - // move to the *left* of this position, that - // would simulate a separator which is not - // really there!). Finally, there is an - // exception to the previous exception: if - // this non-separator-but-last-position-in-row - // is an inset, then we *do* want to stay to - // the left of it anyway: this is the - // "boundary" which we simulate at insets. - - // Another exception is when row.endpos() is - // 0. - - // do we want to be to the right of pos? - // as explained above, if at last pos in row, stay to the right - bool const right_of_pos = row.endpos() > 0 - && pos() == row.endpos() - 1 && !par.isInset(pos()); - - // Now we know if we want to be to the left or to the right of pos, - // let's make sure we are where we want to be. - bool const new_pos_is_RTL = - par.getFontSettings(buf.params(), pos()).isVisibleRightToLeft(); - - if (new_pos_is_RTL != right_of_pos) { - ++pos(); - boundary(true); - } - } - } else { - // move to rightmost position - // if this is an LTR paragraph, and we're at the last row in the - // paragraph, move to lastpos - if (!par.isRTL(buf.params()) && row.endpos() == lastpos()) - pos() = lastpos(); - else { - pos() = row.endpos() > 0 ? bidi.vis2log(row.endpos() - 1) : 0; - - // Moving to the rightmost position in the - // row, the cursor should normally be placed - // to the *right* of the rightmost position. A - // very common exception, though, is if the - // rightmost character also happens to be the - // separator at the (logical) end of the row - // --- in this case, the separator is - // positioned beyond the right margin, and we - // don't want to move the cursor there (moving - // to the right of the separator is equivalent - // to moving to the next line). So, in this - // case we actually want to place the cursor - // to the *left* of the rightmost position - // (the separator). Another exception is if - // we're moving to the logically last position - // in the row, which is *not* a separator: - // this means that the entire row has no - // separators (if there were any, the row - // would have been broken there); and - // therefore in this case we also move to the - // *left* of the last position (this indicates - // to the user that there is no space after - // this position, and is consistent with the - // behavior in the middle of a row --- moving - // right or left moves to the next/previous - // character; if we were to move to the - // *right* of this position, that would - // simulate a separator which is not really - // there!). Finally, there is an exception to - // the previous exception: if this - // non-separator-but-last-position-in-row is - // an inset, then we *do* want to stay to the - // right of it anyway: this is the "boundary" - // which we simulate at insets. Another - // exception is when row.endpos() is 0. - - // do we want to be to the left of pos? - // as explained above, if at last pos in row, stay to the left, - // unless the last position is the same as the first. - bool const left_of_pos = row.endpos() > 0 - && pos() == row.endpos() - 1 && !par.isInset(pos()); - - // Now we know if we want to be to the left or to the right of pos, - // let's make sure we are where we want to be. - bool const new_pos_is_RTL = - par.getFontSettings(buf.params(), pos()).isVisibleRightToLeft(); - - if (new_pos_is_RTL == left_of_pos) { - ++pos(); - boundary(true); - } - } - } + TextMetrics const & tm = bv_->textMetrics(text()); + // Looking for extremities is like clicking on the left or the + // right of the row. + int x = tm.origin().x_ + (left ? 0 : textRow().width()); + bool b = false; + pos() = tm.getPosNearX(textRow(), x, b); + boundary(b); + LYXERR(Debug::RTL, "leaving extremity: " << pit() << "," << pos() << "," << (boundary() ? 1 : 0)); } diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 1c34d5d..2f314b5 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -1090,6 +1090,7 @@ void TextMetrics::setRowHeight(Row & row, pit_type const pit, pos_type TextMetrics::getPosNearX(Row const & row, int & x, bool & boundary) const { + //LYXERR0("getPosNearX(" << x << ") row=" << row); /// For the main Text, it is possible that this pit is not /// yet in the CoordCache when moving cursor up. /// x Paragraph coordinate is always 0 for main text anyway. @@ -1145,6 +1146,7 @@ pos_type TextMetrics::getPosNearX(Row const & row, int & x, boundary = true; x += xo; + //LYXERR0("getPosNearX ==> pos=" << pos << ", boundary=" << boundary); return pos; } ----------------------------------------------------------------------- Summary of changes: src/Cursor.cpp | 138 +++------------------------------------------------ src/RowPainter.cpp | 36 +++++++------- src/TextMetrics.cpp | 2 + 3 files changed, 28 insertions(+), 148 deletions(-) hooks/post-receive -- Repository for new features