RowList::iterator -> Row &, ParagraphList::iterator -> Paragraph &

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7929 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-10-17 10:31:47 +00:00
parent 1684282f8a
commit 7f3eb7cf70
10 changed files with 272 additions and 343 deletions

View File

@ -399,8 +399,8 @@ void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
if (font.language() != ignore_language || if (font.language() != ignore_language ||
font.number() != LyXFont::IGNORE) { font.number() != LyXFont::IGNORE) {
LyXCursor & cursor = text->cursor; LyXCursor & cursor = text->cursor;
text->computeBidiTables(text->cursorPar(), *bv->buffer(), text->computeBidiTables(*text->cursorPar(), *bv->buffer(),
text->cursorRow()); *text->cursorRow());
if (cursor.boundary() != if (cursor.boundary() !=
text->isBoundary(*bv->buffer(), *text->cursorPar(), cursor.pos(), text->isBoundary(*bv->buffer(), *text->cursorPar(), cursor.pos(),
text->real_current_font)) text->real_current_font))
@ -411,11 +411,11 @@ void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
// deletes a selection during an insertion // deletes a selection during an insertion
void replaceSelection(LyXText * lt) void replaceSelection(LyXText * text)
{ {
if (lt->selection.set()) { if (text->selection.set()) {
lt->cutSelection(true, false); text->cutSelection(true, false);
lt->bv()->update(); text->bv()->update();
} }
} }

View File

@ -953,7 +953,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
} }
if (result == FINISHED_UP) { if (result == FINISHED_UP) {
RowList::iterator const irow = view()->text->cursorIRow(); RowList::iterator const irow = view()->text->cursorRow();
if (irow != view()->text->firstRow()) { if (irow != view()->text->firstRow()) {
#if 1 #if 1
view()->text->setCursorFromCoordinates( view()->text->setCursorFromCoordinates(
@ -973,7 +973,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose)
} }
if (result == FINISHED_DOWN) { if (result == FINISHED_DOWN) {
RowList::iterator const irow = view()->text->cursorIRow(); RowList::iterator const irow = view()->text->cursorRow();
if (irow != view()->text->lastRow()) { if (irow != view()->text->lastRow()) {
#if 1 #if 1
view()->text->setCursorFromCoordinates( view()->text->setCursorFromCoordinates(

View File

@ -15,11 +15,8 @@
#include "debug.h" #include "debug.h"
#include "lyxlayout.h" #include "lyxlayout.h"
#include "lyxrow.h" #include "lyxrow.h"
#include "lyxtext.h"
#include "paragraph.h" #include "paragraph.h"
#include <boost/next_prior.hpp>
using lyx::pos_type; using lyx::pos_type;
using std::max; using std::max;
@ -27,51 +24,28 @@ using std::min;
using std::endl; using std::endl;
bool isParEnd(Paragraph const & par, RowList::iterator rit) bool isParEnd(Paragraph const & par, Row const & row)
{ {
#if 0 return row.end() == par.size();
if ((boost::next(rit) == par.rows.end()) != (rit->end() >= par.size())) {
lyxerr << endl;
lyxerr << "broken row 1: end: " << rit->end() << " next: "
<< boost::next(rit)->pos() << endl;
lyxerr << endl;
BOOST_ASSERT(false);
}
#endif
return boost::next(rit) == par.rows.end();
} }
#if 1
pos_type lastPos(Paragraph const & par, RowList::iterator rit) pos_type lastPos(Paragraph const & par, Row const & row)
{ {
if (par.empty()) if (par.empty())
return 0; return 0;
pos_type pos = row.end() - 1;
if (isParEnd(par, rit)) if (pos == par.size())
return par.size() - 1; --pos;
return pos;
if (1 && boost::next(rit)->pos() != rit->end()) {
lyxerr << endl;
lyxerr << "broken row 2: end: " << rit->end() << " next: "
<< boost::next(rit)->pos() << endl;
lyxerr << endl;
BOOST_ASSERT(false);
}
return boost::next(rit)->pos() - 1;
} }
#else
pos_type lastPos(Paragraph const &, RowList::iterator rit)
{
return rit->end() - 1;
}
#endif
int numberOfSeparators(Paragraph const & par, RowList::iterator rit) int numberOfSeparators(Paragraph const & par, Row const & row)
{ {
pos_type const last = lastPos(par, rit); pos_type const last = lastPos(par, row);
int n = 0; int n = 0;
pos_type p = max(rit->pos(), par.beginningOfBody()); pos_type p = max(row.pos(), par.beginningOfBody());
for ( ; p < last; ++p) for ( ; p < last; ++p)
if (par.isSeparator(p)) if (par.isSeparator(p))
++n; ++n;
@ -81,10 +55,10 @@ int numberOfSeparators(Paragraph const & par, RowList::iterator rit)
// This is called _once_ from LyXText and should at least be moved into // This is called _once_ from LyXText and should at least be moved into
// an anonymous namespace there. (Lgb) // an anonymous namespace there. (Lgb)
int numberOfHfills(Paragraph const & par, RowList::iterator rit) int numberOfHfills(Paragraph const & par, Row const & row)
{ {
pos_type const last = lastPos(par, rit); pos_type const last = lastPos(par, row);
pos_type first = rit->pos(); pos_type first = row.pos();
// hfill *DO* count at the beginning of paragraphs! // hfill *DO* count at the beginning of paragraphs!
if (first) { if (first) {
@ -97,9 +71,10 @@ int numberOfHfills(Paragraph const & par, RowList::iterator rit)
int n = 0; int n = 0;
// last, because the end is ignored! // last, because the end is ignored!
for (pos_type p = first; p < last; ++p) for (pos_type p = first; p < last; ++p) {
if (par.isHfill(p)) if (par.isHfill(p))
++n; ++n;
}
return n; return n;
} }
@ -107,10 +82,10 @@ int numberOfHfills(Paragraph const & par, RowList::iterator rit)
// This is called _once_ from LyXText and should at least be moved into // This is called _once_ from LyXText and should at least be moved into
// an anonymous namespace there. (Lgb) // an anonymous namespace there. (Lgb)
int numberOfLabelHfills(Paragraph const & par, RowList::iterator rit) int numberOfLabelHfills(Paragraph const & par, Row const & row)
{ {
pos_type last = lastPos(par, rit); pos_type last = lastPos(par, row);
pos_type first = rit->pos(); pos_type first = row.pos();
// hfill *DO* count at the beginning of paragraphs! // hfill *DO* count at the beginning of paragraphs!
if (first) { if (first) {
@ -121,29 +96,30 @@ int numberOfLabelHfills(Paragraph const & par, RowList::iterator rit)
last = min(last, par.beginningOfBody()); last = min(last, par.beginningOfBody());
int n = 0; int n = 0;
// last, because the end is ignored! // last, because the end is ignored
for (pos_type p = first; p < last; ++p) { for (pos_type p = first; p < last; ++p) {
if (par.isHfill(p)) if (par.isHfill(p))
++n; ++n;
} }
return n; return n;
} }
bool hfillExpansion(Paragraph const & par, RowList::iterator rit, pos_type pos) bool hfillExpansion(Paragraph const & par, Row const & row, pos_type pos)
{ {
if (!par.isHfill(pos)) if (!par.isHfill(pos))
return false; return false;
// at the end of a row it does not count // at the end of a row it does not count
// unless another hfill exists on the line // unless another hfill exists on the line
if (pos >= lastPos(par, rit)) if (pos >= lastPos(par, row))
for (pos_type i = rit->pos(); i < pos && !par.isHfill(i); ++i) for (pos_type i = row.pos(); i < pos && !par.isHfill(i); ++i)
return false; return false;
// at the beginning of a row it does not count, if it is not // at the beginning of a row it does not count, if it is not
// the first row of a paragaph // the first row of a paragaph
if (rit->isParStart()) if (row.isParStart())
return true; return true;
// in some labels it does not count // in some labels it does not count
@ -154,7 +130,7 @@ bool hfillExpansion(Paragraph const & par, RowList::iterator rit, pos_type pos)
// if there is anything between the first char of the row and // if there is anything between the first char of the row and
// the specified position that is not a newline and not a hfill, // the specified position that is not a newline and not a hfill,
// the hfill will count, otherwise not // the hfill will count, otherwise not
pos_type i = rit->pos(); pos_type i = row.pos();
while (i < pos && (par.isNewline(i) || par.isHfill(i))) while (i < pos && (par.isNewline(i) || par.isHfill(i)))
++i; ++i;

View File

@ -13,22 +13,22 @@
#ifndef LYXROW_FUNCS_H #ifndef LYXROW_FUNCS_H
#define LYXROW_FUNCS_H #define LYXROW_FUNCS_H
#include "RowList_fwd.h"
#include "support/types.h" #include "support/types.h"
class Paragraph; class Paragraph;
class Row;
bool isParEnd(Paragraph const & par, RowList::iterator rit); bool isParEnd(Paragraph const & par, Row const & row);
lyx::pos_type lastPos(Paragraph const & par, RowList::iterator rit); lyx::pos_type lastPos(Paragraph const & par, Row const & row);
int numberOfSeparators(Paragraph const & par, RowList::iterator rit); int numberOfSeparators(Paragraph const & par, Row const & row);
int numberOfHfills(Paragraph const & par, RowList::iterator rit); int numberOfHfills(Paragraph const & par, Row const & row);
int numberOfLabelHfills(Paragraph const & par, RowList::iterator rit); int numberOfLabelHfills(Paragraph const & par, Row const & row);
bool hfillExpansion(Paragraph const & par, RowList::iterator rit, bool hfillExpansion(Paragraph const & par, Row const & row,
lyx::pos_type pos); lyx::pos_type pos);
#endif #endif

View File

@ -167,8 +167,7 @@ public:
private: private:
/// returns a pointer to a specified row. /// returns a pointer to a specified row.
RowList::iterator RowList::iterator getRow(Paragraph & par, lyx::pos_type pos) const;
getRow(ParagraphList::iterator pit, lyx::pos_type pos) const;
public: public:
/// returns an iterator pointing to a cursor row /// returns an iterator pointing to a cursor row
RowList::iterator getRow(LyXCursor const & cursor) const; RowList::iterator getRow(LyXCursor const & cursor) const;
@ -182,13 +181,6 @@ public:
int parOffset(ParagraphList::iterator pit) const; int parOffset(ParagraphList::iterator pit) const;
/// convenience /// convenience
ParagraphList::iterator cursorPar() const; ParagraphList::iterator cursorPar() const;
/**
* Return the next row, when cursor is at the end of the
* previous row, for insets that take a full row.
*
* FIXME: explain why we need this ? especially for y...
*/
RowList::iterator cursorIRow() const;
/** returns a pointer to the row near the specified y-coordinate /** returns a pointer to the row near the specified y-coordinate
(relative to the whole text). y is set to the real beginning (relative to the whole text). y is set to the real beginning
@ -201,7 +193,7 @@ public:
x is set to the real beginning of this column x is set to the real beginning of this column
*/ */
lyx::pos_type getColumnNearX(ParagraphList::iterator pit, lyx::pos_type getColumnNearX(ParagraphList::iterator pit,
RowList::iterator rit, int & x, bool & boundary) const; Row const & row, int & x, bool & boundary) const;
/// need the selection cursor: /// need the selection cursor:
void setSelection(); void setSelection();
@ -234,19 +226,14 @@ public:
/// ///
void setCursor(ParagraphList::iterator pit, lyx::pos_type pos); void setCursor(ParagraphList::iterator pit, lyx::pos_type pos);
/// returns true if par was empty and was removed /// returns true if par was empty and was removed
bool setCursor(lyx::paroffset_type par, bool setCursor(lyx::paroffset_type par, lyx::pos_type pos,
lyx::pos_type pos, bool setfont = true, bool boundary = false);
bool setfont = true,
bool boundary = false);
/// ///
void setCursor(LyXCursor &, lyx::paroffset_type par, void setCursor(LyXCursor &, lyx::paroffset_type par,
lyx::pos_type pos, lyx::pos_type pos, bool boundary = false);
bool boundary = false);
/// ///
void setCursorIntern(lyx::paroffset_type par, void setCursorIntern(lyx::paroffset_type par, lyx::pos_type pos,
lyx::pos_type pos, bool setfont = true, bool boundary = false);
bool setfont = true,
bool boundary = false);
/// ///
void setCurrentFont(); void setCurrentFont();
@ -255,8 +242,7 @@ public:
lyx::pos_type pos) const; lyx::pos_type pos) const;
/// ///
bool isBoundary(Buffer const &, Paragraph const & par, bool isBoundary(Buffer const &, Paragraph const & par,
lyx::pos_type pos, lyx::pos_type pos, LyXFont const & font) const;
LyXFont const & font) const;
/// ///
void recUndo(lyx::paroffset_type first, lyx::paroffset_type last) const; void recUndo(lyx::paroffset_type first, lyx::paroffset_type last) const;
@ -265,8 +251,7 @@ public:
/// ///
void setCursorFromCoordinates(int x, int y); void setCursorFromCoordinates(int x, int y);
/// ///
void setCursorFromCoordinates(LyXCursor &, void setCursorFromCoordinates(LyXCursor &, int x, int y);
int x, int y);
/// ///
void cursorUp(bool selecting = false); void cursorUp(bool selecting = false);
/// ///
@ -368,8 +353,8 @@ public:
int workWidth() const; int workWidth() const;
/// ///
void computeBidiTables(ParagraphList::iterator pit, void computeBidiTables(Paragraph const & par,
Buffer const &, RowList::iterator row) const; Buffer const &, Row & row) const;
/// Maps positions in the visual string to positions in logical string. /// Maps positions in the visual string to positions in logical string.
lyx::pos_type log2vis(lyx::pos_type pos) const; lyx::pos_type log2vis(lyx::pos_type pos) const;
/// Maps positions in the logical string to positions in visual string. /// Maps positions in the logical string to positions in visual string.
@ -381,13 +366,13 @@ public:
private: private:
/// ///
float getCursorX(ParagraphList::iterator pit, float getCursorX(ParagraphList::iterator pit,
RowList::iterator rit, lyx::pos_type pos, Row const & row, lyx::pos_type pos,
lyx::pos_type last, bool boundary) const; lyx::pos_type last, bool boundary) const;
/// used in setlayout /// used in setlayout
void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par); void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
/// Calculate and set the height of the row /// Calculate and set the height of the row
void setHeightOfRow(ParagraphList::iterator, RowList::iterator rit); void setHeightOfRow(ParagraphList::iterator, Row & row);
// fix the cursor `cur' after a characters has been deleted at `where' // fix the cursor `cur' after a characters has been deleted at `where'
// position. Called by deleteEmptyParagraphMechanism // position. Called by deleteEmptyParagraphMechanism
@ -429,7 +414,7 @@ public:
*/ */
int leftMargin(ParagraphList::iterator pit, Row const & row) const; int leftMargin(ParagraphList::iterator pit, Row const & row) const;
/// ///
int rightMargin(ParagraphList::iterator pit, Buffer const &, Row const & row) const; int rightMargin(Paragraph const & par, Buffer const &, Row const & row) const;
/** this calculates the specified parameters. needed when setting /** this calculates the specified parameters. needed when setting
* the cursor and when creating a visible row */ * the cursor and when creating a visible row */
@ -446,19 +431,13 @@ private:
/// ///
void deleteLineForward(); void deleteLineForward();
/*
* some low level functions
*/
/// sets row.end to the pos value *after* which a row should break. /// sets row.end to the pos value *after* which a row should break.
/// for example, the pos after which isNewLine(pos) == true /// for example, the pos after which isNewLine(pos) == true
lyx::pos_type rowBreakPoint(ParagraphList::iterator pit, lyx::pos_type rowBreakPoint(ParagraphList::iterator pit,
Row const & row) const; Row const & row) const;
/// returns the minimum space a row needs on the screen in pixel /// returns the minimum space a row needs on the screen in pixel
int fill(ParagraphList::iterator pit, int fill(ParagraphList::iterator pit, Row & row, int workwidth) const;
RowList::iterator row, int workwidth) const;
/** /**
* returns the minimum space a manual label needs on the * returns the minimum space a manual label needs on the

View File

@ -637,7 +637,7 @@ int Paragraph::beginningOfBody() const
// Unroll the first two cycles of the loop // Unroll the first two cycles of the loop
// and remember the previous character to // and remember the previous character to
// remove unnecessary GetChar() calls // remove unnecessary getChar() calls
pos_type i = 0; pos_type i = 0;
if (i < size() && !isNewline(i)) { if (i < size() && !isNewline(i)) {
++i; ++i;

View File

@ -257,7 +257,7 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos)
void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic) void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
{ {
pos_type pos = text_.vis2log(vpos); pos_type pos = text_.vis2log(vpos);
pos_type const last = lastPos(*pit_, row_); pos_type const last = lastPos(*pit_, *row_);
LyXFont orig_font = getFont(pos); LyXFont orig_font = getFont(pos);
// first character // first character
@ -434,7 +434,7 @@ void RowPainter::paintSelection()
int(x_), row_->height(), LColor::selection); int(x_), row_->height(), LColor::selection);
pos_type const body_pos = pit_->beginningOfBody(); pos_type const body_pos = pit_->beginningOfBody();
pos_type const last = lastPos(*pit_, row_); pos_type const last = lastPos(*pit_, *row_);
double tmpx = x_; double tmpx = x_;
for (pos_type vpos = row_->pos(); vpos <= last; ++vpos) { for (pos_type vpos = row_->pos(); vpos <= last; ++vpos) {
@ -450,7 +450,7 @@ void RowPainter::paintSelection()
tmpx -= singleWidth(body_pos - 1); tmpx -= singleWidth(body_pos - 1);
} }
if (hfillExpansion(*pit_, row_, pos)) { if (hfillExpansion(*pit_, *row_, pos)) {
tmpx += singleWidth(pos); tmpx += singleWidth(pos);
if (pos >= body_pos) if (pos >= body_pos)
tmpx += hfill_; tmpx += hfill_;
@ -486,7 +486,7 @@ void RowPainter::paintSelection()
void RowPainter::paintChangeBar() void RowPainter::paintChangeBar()
{ {
pos_type const start = row_->pos(); pos_type const start = row_->pos();
pos_type const end = lastPos(*pit_, row_); pos_type const end = lastPos(*pit_, *row_);
if (!pit_->isChanged(start, end)) if (!pit_->isChanged(start, end))
return; return;
@ -809,7 +809,7 @@ void RowPainter::paintFirst()
double x = x_; double x = x_;
if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) { if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
x = ((is_rtl ? leftMargin() : x_) x = ((is_rtl ? leftMargin() : x_)
+ ww - text_.rightMargin(pit_, *bv_.buffer(), *row_)) / 2; + ww - text_.rightMargin(*pit_, *bv_.buffer(), *row_)) / 2;
x -= font_metrics::width(str, font) / 2; x -= font_metrics::width(str, font) / 2;
} else if (is_rtl) { } else if (is_rtl) {
x = ww - leftMargin() - x = ww - leftMargin() -
@ -889,7 +889,7 @@ void RowPainter::paintLast()
string const & str = pit_->layout()->endlabelstring(); string const & str = pit_->layout()->endlabelstring();
double const x = is_rtl ? double const x = is_rtl ?
x_ - font_metrics::width(str, font) x_ - font_metrics::width(str, font)
: ww - text_.rightMargin(pit_, *bv_.buffer(), *row_) - row_->fill(); : ww - text_.rightMargin(*pit_, *bv_.buffer(), *row_) - row_->fill();
pain_.text(int(x), yo_ + row_->baseline(), str, font); pain_.text(int(x), yo_ + row_->baseline(), str, font);
break; break;
} }
@ -901,7 +901,7 @@ void RowPainter::paintLast()
void RowPainter::paintText() void RowPainter::paintText()
{ {
pos_type const last = lastPos(*pit_, row_); pos_type const last = lastPos(*pit_, *row_);
pos_type body_pos = pit_->beginningOfBody(); pos_type body_pos = pit_->beginningOfBody();
if (body_pos > 0 && if (body_pos > 0 &&
(body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) { (body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) {
@ -966,7 +966,7 @@ void RowPainter::paintText()
pain_.line(int(x_), y1, int(x_), y0, LColor::added_space); pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
if (hfillExpansion(*pit_, row_, pos)) { if (hfillExpansion(*pit_, *row_, pos)) {
int const y2 = (y0 + y1) / 2; int const y2 = (y0 + y1) / 2;
if (pos >= body_pos) { if (pos >= body_pos) {
@ -1039,7 +1039,7 @@ void RowPainter::paint()
if (row_->isParStart()) if (row_->isParStart())
paintFirst(); paintFirst();
if (isParEnd(*pit_, row_)) if (isParEnd(*pit_, *row_))
paintLast(); paintLast();
// paint text // paint text

View File

@ -31,6 +31,7 @@
#include "lyxrc.h" #include "lyxrc.h"
#include "lyxrow.h" #include "lyxrow.h"
#include "lyxrow_funcs.h" #include "lyxrow_funcs.h"
#include "metricsinfo.h"
#include "paragraph.h" #include "paragraph.h"
#include "paragraph_funcs.h" #include "paragraph_funcs.h"
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
@ -265,8 +266,8 @@ bool LyXText::bidi_InRange(lyx::pos_type pos) const
} }
void LyXText::computeBidiTables(ParagraphList::iterator pit, void LyXText::computeBidiTables(Paragraph const & par,
Buffer const & buf, RowList::iterator row) const Buffer const & buf, Row & row) const
{ {
bidi_same_direction = true; bidi_same_direction = true;
if (!lyxrc.rtl_support) { if (!lyxrc.rtl_support) {
@ -274,15 +275,15 @@ void LyXText::computeBidiTables(ParagraphList::iterator pit,
return; return;
} }
InsetOld * inset = pit->inInset(); InsetOld * inset = par.inInset();
if (inset && inset->owner() && if (inset && inset->owner() &&
inset->owner()->lyxCode() == InsetOld::ERT_CODE) { inset->owner()->lyxCode() == InsetOld::ERT_CODE) {
bidi_start = -1; bidi_start = -1;
return; return;
} }
bidi_start = row->pos(); bidi_start = row.pos();
bidi_end = lastPos(*pit, row); bidi_end = lastPos(par, row);
if (bidi_start > bidi_end) { if (bidi_start > bidi_end) {
bidi_start = -1; bidi_start = -1;
@ -304,26 +305,25 @@ void LyXText::computeBidiTables(ParagraphList::iterator pit,
BufferParams const & bufparams = buf.params(); BufferParams const & bufparams = buf.params();
pos_type stack[2]; pos_type stack[2];
bool const rtl_par = bool const rtl_par = par.isRightToLeftPar(bufparams);
pit->isRightToLeftPar(bufparams);
int level = 0; int level = 0;
bool rtl = false; bool rtl = false;
bool rtl0 = false; bool rtl0 = false;
pos_type const body_pos = pit->beginningOfBody(); pos_type const body_pos = par.beginningOfBody();
for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) { for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
bool is_space = pit->isLineSeparator(lpos); bool is_space = par.isLineSeparator(lpos);
pos_type const pos = pos_type const pos =
(is_space && lpos + 1 <= bidi_end && (is_space && lpos + 1 <= bidi_end &&
!pit->isLineSeparator(lpos + 1) && !par.isLineSeparator(lpos + 1) &&
!pit->isNewline(lpos + 1)) !par.isNewline(lpos + 1))
? lpos + 1 : lpos; ? lpos + 1 : lpos;
LyXFont font = pit->getFontSettings(bufparams, pos); LyXFont font = par.getFontSettings(bufparams, pos);
if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() && if (pos != lpos && 0 < lpos && rtl0 && font.isRightToLeft() &&
font.number() == LyXFont::ON && font.number() == LyXFont::ON &&
pit->getFontSettings(bufparams, lpos - 1).number() par.getFontSettings(bufparams, lpos - 1).number()
== LyXFont::ON) { == LyXFont::ON) {
font = pit->getFontSettings(bufparams, lpos); font = par.getFontSettings(bufparams, lpos);
is_space = false; is_space = false;
} }
@ -333,14 +333,15 @@ void LyXText::computeBidiTables(ParagraphList::iterator pit,
int new_level; int new_level;
if (lpos == body_pos - 1 if (lpos == body_pos - 1
&& row->pos() < body_pos - 1 && row.pos() < body_pos - 1
&& is_space) { && is_space) {
new_level = (rtl_par) ? 1 : 0; new_level = rtl_par ? 1 : 0;
new_rtl = new_rtl0 = rtl_par; new_rtl0 = rtl_par;
new_rtl = rtl_par;
} else if (new_rtl0) } else if (new_rtl0)
new_level = (new_rtl) ? 1 : 2; new_level = new_rtl ? 1 : 2;
else else
new_level = (rtl_par) ? 2 : 0; new_level = rtl_par ? 2 : 0;
if (is_space && new_level >= level) { if (is_space && new_level >= level) {
new_level = level; new_level = level;
@ -352,13 +353,13 @@ void LyXText::computeBidiTables(ParagraphList::iterator pit,
if (level == new_level && rtl0 != new_rtl0) { if (level == new_level && rtl0 != new_rtl0) {
--new_level2; --new_level2;
log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1; log2vis_list[lpos - bidi_start] = rtl ? 1 : -1;
} else if (level < new_level) { } else if (level < new_level) {
log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1; log2vis_list[lpos - bidi_start] = rtl ? -1 : 1;
if (new_level > rtl_par) if (new_level > rtl_par)
bidi_same_direction = false; bidi_same_direction = false;
} else } else
log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1; log2vis_list[lpos - bidi_start] = new_rtl ? -1 : 1;
rtl = new_rtl; rtl = new_rtl;
rtl0 = new_rtl0; rtl0 = new_rtl0;
bidi_levels[lpos - bidi_start] = new_level; bidi_levels[lpos - bidi_start] = new_level;
@ -542,10 +543,7 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const
case MARGIN_RIGHT_ADDRESS_BOX: case MARGIN_RIGHT_ADDRESS_BOX:
{ {
// ok, a terrible hack. The left margin depends on the widest // ok, a terrible hack. The left margin depends on the widest
// row in this paragraph. Do not care about footnotes, they // row in this paragraph.
// are *NOT* allowed in the LaTeX realisation of this layout.
// find the first row of this paragraph
RowList::iterator rit = pit->rows.begin(); RowList::iterator rit = pit->rows.begin();
RowList::iterator end = pit->rows.end(); RowList::iterator end = pit->rows.end();
int minfill = rit->fill(); int minfill = rit->fill();
@ -603,18 +601,18 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const
} }
int LyXText::rightMargin(ParagraphList::iterator pit, int LyXText::rightMargin(Paragraph const & par,
Buffer const & buf, Row const &) const Buffer const & buf, Row const &) const
{ {
LyXTextClass const & tclass = buf.params().getLyXTextClass(); LyXTextClass const & tclass = buf.params().getLyXTextClass();
LyXLayout_ptr const & layout = pit->layout(); LyXLayout_ptr const & layout = par.layout();
return PAPER_MARGIN return PAPER_MARGIN
+ font_metrics::signedWidth(tclass.rightmargin(), + font_metrics::signedWidth(tclass.rightmargin(),
tclass.defaultfont()); tclass.defaultfont());
+ font_metrics::signedWidth(layout->rightmargin, + font_metrics::signedWidth(layout->rightmargin,
tclass.defaultfont()) tclass.defaultfont())
* 4 / (pit->getDepth() + 4); * 4 / (par.getDepth() + 4);
} }
@ -638,10 +636,9 @@ namespace {
// this needs special handling - only newlines count as a break point // this needs special handling - only newlines count as a break point
pos_type addressBreakPoint(pos_type i, Paragraph const & par) pos_type addressBreakPoint(pos_type i, Paragraph const & par)
{ {
for (; i < par.size(); ++i) { for (; i < par.size(); ++i)
if (par.isNewline(i)) if (par.isNewline(i))
return i; return i;
}
return par.size(); return par.size();
} }
@ -653,8 +650,7 @@ pos_type LyXText::rowBreakPoint(ParagraphList::iterator pit,
Row const & row) const Row const & row) const
{ {
// maximum pixel width of a row. // maximum pixel width of a row.
int width = workWidth() int width = workWidth() - rightMargin(*pit, *bv()->buffer(), row);
- rightMargin(pit, *bv()->buffer(), row);
// inset->textWidth() returns -1 via workWidth(), // inset->textWidth() returns -1 via workWidth(),
// but why ? // but why ?
@ -726,12 +722,8 @@ pos_type LyXText::rowBreakPoint(ParagraphList::iterator pit,
// the right of the row // the right of the row
if (x >= width) { if (x >= width) {
// if no break before, break here // if no break before, break here
if (point == last || chunkwidth >= (width - left)) { if (point == last || chunkwidth >= width - left)
if (pos < i) point = (pos < i) ? i - 1 : i;
point = i - 1;
else
point = i;
}
break; break;
} }
@ -741,10 +733,7 @@ pos_type LyXText::rowBreakPoint(ParagraphList::iterator pit,
point = i; point = i;
chunkwidth = 0; chunkwidth = 0;
} }
continue;
} }
continue;
} }
if (point == last && x >= width) { if (point == last && x >= width) {
@ -767,8 +756,7 @@ pos_type LyXText::rowBreakPoint(ParagraphList::iterator pit,
// returns the minimum space a row needs on the screen in pixel // returns the minimum space a row needs on the screen in pixel
int LyXText::fill(ParagraphList::iterator pit, int LyXText::fill(ParagraphList::iterator pit, Row & row, int paper_width) const
RowList::iterator row, int paper_width) const
{ {
if (paper_width < 0) if (paper_width < 0)
return 0; return 0;
@ -781,15 +769,15 @@ int LyXText::fill(ParagraphList::iterator pit,
// special handling of the right address boxes // special handling of the right address boxes
if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) { if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
int const tmpfill = row->fill(); int const tmpfill = row.fill();
row->fill(0); // the minfill in MarginLeft() row.fill(0); // the minfill in MarginLeft()
w = leftMargin(pit, *row); w = leftMargin(pit, row);
row->fill(tmpfill); row.fill(tmpfill);
} else } else
w = leftMargin(pit, *row); w = leftMargin(pit, row);
pos_type const body_pos = pit->beginningOfBody(); pos_type const body_pos = pit->beginningOfBody();
pos_type i = row->pos(); pos_type i = row.pos();
if (! pit->empty() && i <= last) { if (! pit->empty() && i <= last) {
// We re-use the font resolution for the entire span when possible // We re-use the font resolution for the entire span when possible
@ -800,7 +788,7 @@ int LyXText::fill(ParagraphList::iterator pit,
w += font_metrics::width(layout->labelsep, getLabelFont(pit)); w += font_metrics::width(layout->labelsep, getLabelFont(pit));
if (pit->isLineSeparator(i - 1)) if (pit->isLineSeparator(i - 1))
w -= singleWidth(pit, i - 1); w -= singleWidth(pit, i - 1);
int left_margin = labelEnd(pit, *row); int left_margin = labelEnd(pit, row);
if (w < left_margin) if (w < left_margin)
w = left_margin; w = left_margin;
} }
@ -818,12 +806,12 @@ int LyXText::fill(ParagraphList::iterator pit,
w += font_metrics::width(layout->labelsep, getLabelFont(pit)); w += font_metrics::width(layout->labelsep, getLabelFont(pit));
if (last >= 0 && pit->isLineSeparator(last)) if (last >= 0 && pit->isLineSeparator(last))
w -= singleWidth(pit, last); w -= singleWidth(pit, last);
int const left_margin = labelEnd(pit, *row); int const left_margin = labelEnd(pit, row);
if (w < left_margin) if (w < left_margin)
w = left_margin; w = left_margin;
} }
int const fill = paper_width - w - rightMargin(pit, *bv()->buffer(), *row); int const fill = paper_width - w - rightMargin(*pit, *bv()->buffer(), row);
// If this case happens, it means that our calculation // If this case happens, it means that our calculation
// of the widths of the chars when we do rowBreakPoint() // of the widths of the chars when we do rowBreakPoint()
@ -835,7 +823,7 @@ int LyXText::fill(ParagraphList::iterator pit,
if (lyxerr.debugging() && fill < 0) { if (lyxerr.debugging() && fill < 0) {
lyxerr[Debug::GUI] << "Eek, fill() was < 0: " << fill lyxerr[Debug::GUI] << "Eek, fill() was < 0: " << fill
<< " w " << w << " paper_width " << paper_width << " w " << w << " paper_width " << paper_width
<< " right margin " << rightMargin(pit, *bv()->buffer(), *row) << endl; << " right margin " << rightMargin(*pit, *bv()->buffer(), row) << endl;
} }
return fill; return fill;
} }
@ -884,7 +872,7 @@ LColor_color LyXText::backgroundColor() const
} }
void LyXText::setHeightOfRow(ParagraphList::iterator pit, RowList::iterator rit) void LyXText::setHeightOfRow(ParagraphList::iterator pit, Row & row)
{ {
// get the maximum ascent and the maximum descent // get the maximum ascent and the maximum descent
double layoutasc = 0; double layoutasc = 0;
@ -899,7 +887,7 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, RowList::iterator rit)
// as max get the first character of this row then it can increase but not // as max get the first character of this row then it can increase but not
// decrease the height. Just some point to start with so we don't have to // decrease the height. Just some point to start with so we don't have to
// do the assignment below too often. // do the assignment below too often.
LyXFont font = getFont(pit, rit->pos()); LyXFont font = getFont(pit, row.pos());
LyXFont::FONT_SIZE const tmpsize = font.size(); LyXFont::FONT_SIZE const tmpsize = font.size();
font = getLayoutFont(pit); font = getLayoutFont(pit);
LyXFont::FONT_SIZE const size = font.size(); LyXFont::FONT_SIZE const size = font.size();
@ -919,20 +907,20 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, RowList::iterator rit)
int maxdesc = int(font_metrics::maxDescent(font) * int maxdesc = int(font_metrics::maxDescent(font) *
layout->spacing.getValue() * spacing_val); layout->spacing.getValue() * spacing_val);
pos_type const pos_end = lastPos(*pit, rit); pos_type const pos_end = lastPos(*pit, row);
int labeladdon = 0; int labeladdon = 0;
int maxwidth = 0; int maxwidth = 0;
if (!pit->empty()) { if (!pit->empty()) {
// We re-use the font resolution for the entire font span when possible // We re-use the font resolution for the entire font span when possible
LyXFont font = getFont(pit, rit->pos()); LyXFont font = getFont(pit, row.pos());
lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(rit->pos()); lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(row.pos());
// Optimisation // Optimisation
Paragraph const & par = *pit; Paragraph const & par = *pit;
// Check if any insets are larger // Check if any insets are larger
for (pos_type pos = rit->pos(); pos <= pos_end; ++pos) { for (pos_type pos = row.pos(); pos <= pos_end; ++pos) {
// Manual inlined optimised version of common case of // Manual inlined optimised version of common case of
// "maxwidth += singleWidth(pit, pos);" // "maxwidth += singleWidth(pit, pos);"
char const c = par.getChar(pos); char const c = par.getChar(pos);
@ -974,7 +962,7 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, RowList::iterator rit)
// This is not completely correct, but we can live with the small, // This is not completely correct, but we can live with the small,
// cosmetic error for now. // cosmetic error for now.
LyXFont::FONT_SIZE maxsize = LyXFont::FONT_SIZE maxsize =
pit->highestFontInRange(rit->pos(), pos_end, size); pit->highestFontInRange(row.pos(), pos_end, size);
if (maxsize > font.size()) { if (maxsize > font.size()) {
font.setSize(maxsize); font.setSize(maxsize);
maxasc = max(maxasc, font_metrics::maxAscent(font)); maxasc = max(maxasc, font_metrics::maxAscent(font));
@ -985,10 +973,10 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, RowList::iterator rit)
++maxasc; ++maxasc;
++maxdesc; ++maxdesc;
rit->ascent_of_text(maxasc); row.ascent_of_text(maxasc);
// is it a top line? // is it a top line?
if (!rit->pos()) { if (!row.pos()) {
BufferParams const & bufparams = bv()->buffer()->params(); BufferParams const & bufparams = bv()->buffer()->params();
// some parksips VERY EASY IMPLEMENTATION // some parksips VERY EASY IMPLEMENTATION
if (bv()->buffer()->params().paragraph_separation == if (bv()->buffer()->params().paragraph_separation ==
@ -1081,12 +1069,10 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, RowList::iterator rit)
prev->getLabelWidthString() == pit->getLabelWidthString()) prev->getLabelWidthString() == pit->getLabelWidthString())
{ {
layoutasc = (layout->itemsep * defaultRowHeight()); layoutasc = (layout->itemsep * defaultRowHeight());
} else if (rit != firstRow()) { // } else if (rit != firstRow()) {
} else if (pit != ownerParagraphs().begin() || row.pos() != 0) {
tmptop = layout->topsep; tmptop = layout->topsep;
//if (boost::prior(pit)->getDepth() >= pit->getDepth())
// tmptop -= getPar(previousRow(rit))->layout()->bottomsep;
if (tmptop > 0) if (tmptop > 0)
layoutasc = (tmptop * defaultRowHeight()); layoutasc = (tmptop * defaultRowHeight());
} else if (pit->params().lineTop()) { } else if (pit->params().lineTop()) {
@ -1110,7 +1096,7 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, RowList::iterator rit)
} }
// is it a bottom line? // is it a bottom line?
if (boost::next(rit) == pit->rows.end()) { if (row.end() == pit->size()) {
// the bottom margin // the bottom margin
ParagraphList::iterator nextpit = boost::next(pit); ParagraphList::iterator nextpit = boost::next(pit);
if (nextpit == ownerParagraphs().end() && !isInInset()) if (nextpit == ownerParagraphs().end() && !isInInset())
@ -1165,12 +1151,11 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, RowList::iterator rit)
maxasc += int(layoutasc * 2 / (2 + pit->getDepth())); maxasc += int(layoutasc * 2 / (2 + pit->getDepth()));
maxdesc += int(layoutdesc * 2 / (2 + pit->getDepth())); maxdesc += int(layoutdesc * 2 / (2 + pit->getDepth()));
rit->height(maxasc + maxdesc + labeladdon); row.height(maxasc + maxdesc + labeladdon);
rit->baseline(maxasc + labeladdon); row.baseline(maxasc + labeladdon);
rit->top_of_text(rit->baseline() - font_metrics::maxAscent(font)); row.top_of_text(row.baseline() - font_metrics::maxAscent(font));
double x = 0; row.width(maxwidth);
rit->width(int(maxwidth + x));
if (inset_owner) { if (inset_owner) {
width = max(0, workWidth()); width = max(0, workWidth());
RowList::iterator rit = firstRow(); RowList::iterator rit = firstRow();
@ -1408,7 +1393,7 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit,
bool const is_rtl = bool const is_rtl =
pit->isRightToLeftPar(bv()->buffer()->params()); pit->isRightToLeftPar(bv()->buffer()->params());
if (is_rtl) if (is_rtl)
x = workWidth() > 0 ? rightMargin(pit, *bv()->buffer(), *rit) : 0; x = workWidth() > 0 ? rightMargin(*pit, *bv()->buffer(), *rit) : 0;
else else
x = workWidth() > 0 ? leftMargin(pit, *rit) : 0; x = workWidth() > 0 ? leftMargin(pit, *rit) : 0;
@ -1418,7 +1403,7 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit,
if (layout->margintype == MARGIN_MANUAL if (layout->margintype == MARGIN_MANUAL
&& layout->labeltype == LABEL_MANUAL) { && layout->labeltype == LABEL_MANUAL) {
/// We might have real hfills in the label part /// We might have real hfills in the label part
int nlh = numberOfLabelHfills(*pit, rit); int nlh = numberOfLabelHfills(*pit, *rit);
// A manual label par (e.g. List) has an auto-hfill // A manual label par (e.g. List) has an auto-hfill
// between the label text and the body of the // between the label text and the body of the
@ -1434,7 +1419,7 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit,
} }
// are there any hfills in the row? // are there any hfills in the row?
int const nh = numberOfHfills(*pit, rit); int const nh = numberOfHfills(*pit, *rit);
if (nh) { if (nh) {
if (w > 0) if (w > 0)
@ -1463,7 +1448,7 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit,
switch (align) { switch (align) {
case LYX_ALIGN_BLOCK: case LYX_ALIGN_BLOCK:
{ {
int const ns = numberOfSeparators(*pit, rit); int const ns = numberOfSeparators(*pit, *rit);
RowList::iterator next_row = boost::next(rit); RowList::iterator next_row = boost::next(rit);
if (ns if (ns
&& next_row != pit->rows.end() && next_row != pit->rows.end()
@ -1484,10 +1469,10 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit,
} }
} }
computeBidiTables(pit, *bv()->buffer(), rit); computeBidiTables(*pit, *bv()->buffer(), *rit);
if (is_rtl) { if (is_rtl) {
pos_type body_pos = pit->beginningOfBody(); pos_type body_pos = pit->beginningOfBody();
pos_type last = lastPos(*pit, rit); pos_type last = lastPos(*pit, *rit);
if (body_pos > 0 && if (body_pos > 0 &&
(body_pos - 1 > last || (body_pos - 1 > last ||
@ -1987,21 +1972,20 @@ ParagraphList::iterator LyXText::getPar(int par) const
RowList::iterator LyXText::cursorRow() const RowList::iterator LyXText::cursorRow() const
{ {
return getRow(cursorPar(), cursor.pos()); return getRow(*cursorPar(), cursor.pos());
} }
RowList::iterator LyXText::getRow(LyXCursor const & cur) const RowList::iterator LyXText::getRow(LyXCursor const & cur) const
{ {
return getRow(getPar(cur), cur.pos()); return getRow(*getPar(cur), cur.pos());
} }
RowList::iterator RowList::iterator LyXText::getRow(Paragraph & par, pos_type pos) const
LyXText::getRow(ParagraphList::iterator pit, pos_type pos) const
{ {
RowList::iterator rit = boost::prior(pit->rows.end()); RowList::iterator rit = boost::prior(par.rows.end());
RowList::iterator const begin = pit->rows.begin(); RowList::iterator const begin = par.rows.begin();
while (rit != begin && rit->pos() > pos) while (rit != begin && rit->pos() > pos)
--rit; --rit;
@ -2010,15 +1994,8 @@ LyXText::getRow(ParagraphList::iterator pit, pos_type pos) const
} }
// returns pointer to some fancy row 'below' specified row RowList::iterator
RowList::iterator LyXText::cursorIRow() const LyXText::getRowNearY(int y, ParagraphList::iterator & pit) const
{
return getRow(cursorPar(), cursor.pos());
}
RowList::iterator LyXText::getRowNearY(int y, ParagraphList::iterator & pit)
const
{ {
//lyxerr << "getRowNearY: y " << y << endl; //lyxerr << "getRowNearY: y " << y << endl;
@ -2027,7 +2004,7 @@ RowList::iterator LyXText::getRowNearY(int y, ParagraphList::iterator & pit)
RowList::iterator rit = lastRow(); RowList::iterator rit = lastRow();
RowList::iterator rbegin = firstRow(); RowList::iterator rbegin = firstRow();
while (rit != rbegin && pit->y + rit->y_offset() > y) while (rit != rbegin && int(pit->y + rit->y_offset()) > y)
previousRow(pit, rit); previousRow(pit, rit);
return rit; return rit;
@ -2119,3 +2096,99 @@ int LyXText::parOffset(ParagraphList::iterator pit) const
{ {
return std::distance(ownerParagraphs().begin(), pit); return std::distance(ownerParagraphs().begin(), pit);
} }
int LyXText::redoParagraphInternal(ParagraphList::iterator pit)
{
// remove rows of paragraph, keep track of height changes
height -= pit->height;
pit->rows.clear();
// redo insets
InsetList::iterator ii = pit->insetlist.begin();
InsetList::iterator iend = pit->insetlist.end();
for (; ii != iend; ++ii) {
Dimension dim;
MetricsInfo mi(bv(), getFont(pit, ii->pos), workWidth());
ii->inset->metrics(mi, dim);
}
// rebreak the paragraph
int par_width = 0;
int const ww = workWidth();
pit->height = 0;
for (pos_type z = 0; z < pit->size() + 1; ) {
Row row(z);
z = rowBreakPoint(pit, row) + 1;
row.end(z);
pit->rows.push_back(row);
}
RowList::iterator rit = pit->rows.begin();
RowList::iterator end = pit->rows.end();
for (rit = pit->rows.begin(); rit != end; ++rit) {
int const f = fill(pit, *rit, ww);
int const w = ww - f;
par_width = std::max(par_width, w);
rit->fill(f);
rit->width(w);
prepareToPrint(pit, rit);
setHeightOfRow(pit, *rit);
rit->y_offset(pit->height);
pit->height += rit->height();
}
height += pit->height;
//lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
return par_width;
}
int LyXText::redoParagraphs(ParagraphList::iterator start,
ParagraphList::iterator end)
{
int pars_width = 0;
for ( ; start != end; ++start) {
int par_width = redoParagraphInternal(start);
pars_width = std::max(par_width, pars_width);
}
updateRowPositions();
return pars_width;
}
void LyXText::redoParagraph(ParagraphList::iterator pit)
{
redoParagraphInternal(pit);
updateRowPositions();
}
void LyXText::fullRebreak()
{
redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
redoCursor();
selection.cursor = cursor;
}
void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
{
//lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
// << " workWidth: " << workWidth() << endl;
//BOOST_ASSERT(mi.base.textwidth);
// rebuild row cache
width = 0;
///height = 0;
//anchor_y_ = 0;
width = redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
// final dimension
dim.asc = firstRow()->ascent_of_text();
dim.des = height - dim.asc;
dim.wid = std::max(mi.base.textwidth, int(width));
}

View File

@ -38,7 +38,6 @@
#include "lyxrc.h" #include "lyxrc.h"
#include "lyxrow.h" #include "lyxrow.h"
#include "lyxrow_funcs.h" #include "lyxrow_funcs.h"
#include "metricsinfo.h"
#include "paragraph.h" #include "paragraph.h"
#include "paragraph_funcs.h" #include "paragraph_funcs.h"
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
@ -545,103 +544,6 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
} }
int LyXText::redoParagraphInternal(ParagraphList::iterator pit)
{
RowList::iterator rit = pit->rows.begin();
RowList::iterator end = pit->rows.end();
// remove rows of paragraph, keep track of height changes
for (int i = 0; rit != end; ++rit, ++i)
height -= rit->height();
pit->rows.clear();
// redo insets
InsetList::iterator ii = pit->insetlist.begin();
InsetList::iterator iend = pit->insetlist.end();
for (; ii != iend; ++ii) {
Dimension dim;
MetricsInfo mi(bv(), getFont(pit, ii->pos), workWidth());
ii->inset->metrics(mi, dim);
}
// rebreak the paragraph
for (pos_type z = 0; z < pit->size() + 1; ) {
Row row(z);
z = rowBreakPoint(pit, row) + 1;
row.end(z);
pit->rows.push_back(row);
}
int par_width = 0;
// set height and fill and width of rows
int const ww = workWidth();
pit->height = 0;
for (rit = pit->rows.begin(); rit != end; ++rit) {
int const f = fill(pit, rit, ww);
int const w = ww - f;
par_width = std::max(par_width, w);
rit->fill(f);
rit->width(w);
prepareToPrint(pit, rit);
setHeightOfRow(pit, rit);
rit->y_offset(pit->height);
pit->height += rit->height();
}
height += pit->height;
//lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
return par_width;
}
int LyXText::redoParagraphs(ParagraphList::iterator start,
ParagraphList::iterator end)
{
int pars_width = 0;
for ( ; start != end; ++start) {
int par_width = redoParagraphInternal(start);
pars_width = std::max(par_width, pars_width);
}
updateRowPositions();
return pars_width;
}
void LyXText::redoParagraph(ParagraphList::iterator pit)
{
redoParagraphInternal(pit);
updateRowPositions();
}
void LyXText::fullRebreak()
{
redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
redoCursor();
selection.cursor = cursor;
}
void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
{
//lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
// << " workWidth: " << workWidth() << endl;
//BOOST_ASSERT(mi.base.textwidth);
// rebuild row cache
width = 0;
///height = 0;
//anchor_y_ = 0;
width = redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
// final dimension
dim.asc = firstRow()->ascent_of_text();
dim.des = height - dim.asc;
dim.wid = std::max(mi.base.textwidth, int(width));
}
// important for the screen // important for the screen
@ -1406,11 +1308,11 @@ void LyXText::setCursor(LyXCursor & cur, paroffset_type par,
// get the cursor y position in text // get the cursor y position in text
ParagraphList::iterator pit = getPar(par); ParagraphList::iterator pit = getPar(par);
RowList::iterator row = getRow(pit, pos); Row const & row = *getRow(*pit, pos);
int y = pit->y + row->y_offset(); int y = pit->y + row.y_offset();
// y is now the beginning of the cursor row // y is now the beginning of the cursor row
y += row->baseline(); y += row.baseline();
// y is now the cursor baseline // y is now the cursor baseline
cur.y(y); cur.y(y);
@ -1426,9 +1328,9 @@ void LyXText::setCursor(LyXCursor & cur, paroffset_type par,
// This shouldn't happen. // This shouldn't happen.
pos = last + 1; pos = last + 1;
cur.pos(pos); cur.pos(pos);
} else if (pos < row->pos()) { } else if (pos < row.pos()) {
lyxerr << "dont like 3 please report" << endl; lyxerr << "dont like 3 please report" << endl;
pos = row->pos(); pos = row.pos();
cur.pos(pos); cur.pos(pos);
} }
@ -1439,22 +1341,22 @@ void LyXText::setCursor(LyXCursor & cur, paroffset_type par,
} }
float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit, float LyXText::getCursorX(ParagraphList::iterator pit, Row const & row,
pos_type pos, pos_type last, bool boundary) const pos_type pos, pos_type last, bool boundary) const
{ {
pos_type cursor_vpos = 0; pos_type cursor_vpos = 0;
double x = rit->x(); double x = row.x();
double fill_separator = rit->fill_separator(); double fill_separator = row.fill_separator();
double fill_hfill = rit->fill_hfill(); double fill_hfill = row.fill_hfill();
double fill_label_hfill = rit->fill_label_hfill(); double fill_label_hfill = row.fill_label_hfill();
pos_type const rit_pos = rit->pos(); pos_type const row_pos = row.pos();
if (last < rit_pos) if (last < row_pos)
cursor_vpos = rit_pos; cursor_vpos = row_pos;
else if (pos > last && !boundary) else if (pos > last && !boundary)
cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params())) cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params()))
? rit_pos : last + 1; ? row_pos : last + 1;
else if (pos > rit_pos && (pos > last || boundary)) else if (pos > row_pos && (pos > last || boundary))
// Place cursor after char at (logical) position pos - 1 // Place cursor after char at (logical) position pos - 1
cursor_vpos = (bidi_level(pos - 1) % 2 == 0) cursor_vpos = (bidi_level(pos - 1) % 2 == 0)
? log2vis(pos - 1) + 1 : log2vis(pos - 1); ? log2vis(pos - 1) + 1 : log2vis(pos - 1);
@ -1468,7 +1370,7 @@ float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit,
(body_pos - 1 > last || !pit->isLineSeparator(body_pos - 1))) (body_pos - 1 > last || !pit->isLineSeparator(body_pos - 1)))
body_pos = 0; body_pos = 0;
for (pos_type vpos = rit_pos; vpos < cursor_vpos; ++vpos) { for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
pos_type pos = vis2log(vpos); pos_type pos = vis2log(vpos);
if (body_pos > 0 && pos == body_pos - 1) { if (body_pos > 0 && pos == body_pos - 1) {
x += fill_label_hfill + x += fill_label_hfill +
@ -1478,7 +1380,7 @@ float LyXText::getCursorX(ParagraphList::iterator pit, RowList::iterator rit,
x -= singleWidth(pit, body_pos - 1); x -= singleWidth(pit, body_pos - 1);
} }
if (hfillExpansion(*pit, rit, pos)) { if (hfillExpansion(*pit, row, pos)) {
x += singleWidth(pit, pos); x += singleWidth(pit, pos);
if (pos >= body_pos) if (pos >= body_pos)
x += fill_hfill; x += fill_hfill;
@ -1546,15 +1448,15 @@ void LyXText::setCurrentFont()
// returns the column near the specified x-coordinate of the row // returns the column near the specified x-coordinate of the row
// x is set to the real beginning of this column // x is set to the real beginning of this column
pos_type LyXText::getColumnNearX(ParagraphList::iterator pit, pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
RowList::iterator rit, int & x, bool & boundary) const Row const & row, int & x, bool & boundary) const
{ {
double tmpx = rit->x(); double tmpx = row.x();
double fill_separator = rit->fill_separator(); double fill_separator = row.fill_separator();
double fill_hfill = rit->fill_hfill(); double fill_hfill = row.fill_hfill();
double fill_label_hfill = rit->fill_label_hfill(); double fill_label_hfill = row.fill_label_hfill();
pos_type vc = rit->pos(); pos_type vc = row.pos();
pos_type last = lastPos(*pit, rit); pos_type last = lastPos(*pit, row);
pos_type c = 0; pos_type c = 0;
LyXLayout_ptr const & layout = pit->layout(); LyXLayout_ptr const & layout = pit->layout();
@ -1584,7 +1486,7 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
tmpx -= singleWidth(pit, body_pos - 1); tmpx -= singleWidth(pit, body_pos - 1);
} }
if (hfillExpansion(*pit, rit, c)) { if (hfillExpansion(*pit, row, c)) {
tmpx += singleWidth(pit, c); tmpx += singleWidth(pit, c);
if (c >= body_pos) if (c >= body_pos)
tmpx += fill_hfill; tmpx += fill_hfill;
@ -1611,8 +1513,7 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
boundary = false; boundary = false;
// This (rtl_support test) is not needed, but gives // This (rtl_support test) is not needed, but gives
// some speedup if rtl_support == false // some speedup if rtl_support == false
bool const lastrow = lyxrc.rtl_support bool const lastrow = lyxrc.rtl_support && row.end() == pit->size();
&& boost::next(rit) == pit->rows.end();
// If lastrow is false, we don't need to compute // If lastrow is false, we don't need to compute
// the value of rtl. // the value of rtl.
@ -1620,10 +1521,10 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
? pit->isRightToLeftPar(bv()->buffer()->params()) ? pit->isRightToLeftPar(bv()->buffer()->params())
: false; : false;
if (lastrow && if (lastrow &&
((rtl && left_side && vc == rit->pos() && x < tmpx - 5) || ((rtl && left_side && vc == row.pos() && x < tmpx - 5) ||
(!rtl && !left_side && vc == last + 1 && x > tmpx + 5))) (!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
c = last + 1; c = last + 1;
else if (vc == rit->pos()) { else if (vc == row.pos()) {
c = vis2log(vc); c = vis2log(vc);
if (bidi_level(c) % 2 == 1) if (bidi_level(c) % 2 == 1)
++c; ++c;
@ -1636,7 +1537,7 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
} }
} }
if (rit->pos() <= last && c > last && pit->isNewline(last)) { if (row.pos() <= last && c > last && pit->isNewline(last)) {
if (bidi_level(last) % 2 == 0) if (bidi_level(last) % 2 == 0)
tmpx -= singleWidth(pit, last); tmpx -= singleWidth(pit, last);
else else
@ -1644,7 +1545,7 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
c = last; c = last;
} }
c -= rit->pos(); c -= row.pos();
x = int(tmpx); x = int(tmpx);
return c; return c;
} }
@ -1663,15 +1564,15 @@ void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
{ {
// Get the row first. // Get the row first.
ParagraphList::iterator pit; ParagraphList::iterator pit;
RowList::iterator rit = getRowNearY(y, pit); Row const & row = *getRowNearY(y, pit);
y = pit->y + rit->y_offset(); y = pit->y + row.y_offset();
bool bound = false; bool bound = false;
pos_type const column = getColumnNearX(pit, rit, x, bound); pos_type const column = getColumnNearX(pit, row, x, bound);
cur.par(parOffset(pit)); cur.par(parOffset(pit));
cur.pos(rit->pos() + column); cur.pos(row.pos() + column);
cur.x(x); cur.x(x);
cur.y(y + rit->baseline()); cur.y(y + row.baseline());
cur.boundary(bound); cur.boundary(bound);
} }
@ -1742,7 +1643,7 @@ void LyXText::cursorDown(bool selecting)
int x = cursor.x_fix(); int x = cursor.x_fix();
int y = cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1; int y = cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1;
setCursorFromCoordinates(x, y); setCursorFromCoordinates(x, y);
if (!selecting && cursorRow() == cursorIRow()) { if (!selecting) {
int topy = bv_owner->top_y(); int topy = bv_owner->top_y();
int y1 = cursor.y() - topy; int y1 = cursor.y() - topy;
int y2 = y1; int y2 = y1;

View File

@ -313,8 +313,8 @@ void LyXText::cursorNext()
} }
ParagraphList::iterator dummypit; ParagraphList::iterator dummypit;
RowList::iterator rr = getRowNearY(y, dummypit); Row const & rr = *getRowNearY(y, dummypit);
y = dummypit->y + rr->y_offset(); y = dummypit->y + rr.y_offset();
setCursorFromCoordinates(cursor.x_fix(), y); setCursorFromCoordinates(cursor.x_fix(), y);
// + bv->workHeight()); // + bv->workHeight());