mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-27 03:36:39 +00:00
make endpos behave
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7977 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
3e8ce5ac6c
commit
d8428d8976
@ -1,3 +1,11 @@
|
|||||||
|
2003-10-24 Alfredo Braunstein <abraunst@libero.it>
|
||||||
|
|
||||||
|
* paragraph.C (getChar): add strong asserts
|
||||||
|
|
||||||
|
* lyxrow_funcs.C (lastPos): remove hideous hack
|
||||||
|
|
||||||
|
* text.C (addressBreakPoint, rowBreakPoint): put endpos in place
|
||||||
|
(fill): adjust to that (avoid an infinite loop)
|
||||||
|
|
||||||
2003-10-23 Alfredo Braunstein <abraunst@libero.it>
|
2003-10-23 Alfredo Braunstein <abraunst@libero.it>
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ pos_type lastPos(Paragraph const & par, Row const & row)
|
|||||||
if (par.empty())
|
if (par.empty())
|
||||||
return 0;
|
return 0;
|
||||||
pos_type pos = row.endpos() - 1;
|
pos_type pos = row.endpos() - 1;
|
||||||
if (pos == par.size())
|
// if (pos == par.size())
|
||||||
--pos;
|
// --pos;
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1327,12 +1327,13 @@ Paragraph::value_type Paragraph::getChar(pos_type pos) const
|
|||||||
// This is in the critical path!
|
// This is in the critical path!
|
||||||
pos_type const siz = text_.size();
|
pos_type const siz = text_.size();
|
||||||
|
|
||||||
BOOST_ASSERT(pos <= siz);
|
BOOST_ASSERT(0 <= pos && pos <= siz);
|
||||||
|
|
||||||
if (pos == siz) {
|
if (pos == siz) {
|
||||||
lyxerr << "getChar() on pos " << pos << " in par id "
|
lyxerr << "getChar() on pos " << pos << " in par id "
|
||||||
<< id() << " of size " << siz
|
<< id() << " of size " << siz
|
||||||
<< " is a bit silly !" << endl;
|
<< " is a bit silly !" << endl;
|
||||||
|
BOOST_ASSERT(false);
|
||||||
return '\0';
|
return '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
45
src/text.C
45
src/text.C
@ -456,7 +456,7 @@ 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 + 1;
|
||||||
|
|
||||||
return par.size();
|
return par.size();
|
||||||
}
|
}
|
||||||
@ -466,6 +466,11 @@ pos_type addressBreakPoint(pos_type i, Paragraph const & par)
|
|||||||
|
|
||||||
void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
|
void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
|
||||||
{
|
{
|
||||||
|
if (pit->empty()) {
|
||||||
|
row.endpos(pit->size());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
@ -474,24 +479,24 @@ void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
|
|||||||
// inset->textWidth() returns -1 via workWidth(),
|
// inset->textWidth() returns -1 via workWidth(),
|
||||||
// but why ?
|
// but why ?
|
||||||
if (width < 0) {
|
if (width < 0) {
|
||||||
row.endpos(pit->size() + 1);
|
row.endpos(pit->size());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LyXLayout_ptr const & layout = pit->layout();
|
LyXLayout_ptr const & layout = pit->layout();
|
||||||
|
|
||||||
if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
|
if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
|
||||||
row.endpos(addressBreakPoint(row.pos(), *pit) + 1);
|
row.endpos(addressBreakPoint(row.pos(), *pit));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos_type const pos = row.pos();
|
pos_type const pos = row.pos();
|
||||||
pos_type const body_pos = pit->beginningOfBody();
|
pos_type const body_pos = pit->beginningOfBody();
|
||||||
pos_type const last = pit->size();
|
pos_type const end = pit->size();
|
||||||
pos_type point = last;
|
pos_type point = end - 1;
|
||||||
|
|
||||||
if (pos == last) {
|
if (pos == end) {
|
||||||
row.endpos(last + 1);
|
row.endpos(end);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -511,13 +516,13 @@ void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
|
|||||||
LyXFont font = getFont(pit, i);
|
LyXFont font = getFont(pit, i);
|
||||||
lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
|
lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
|
||||||
|
|
||||||
for ( ; i < last; ++i) {
|
for ( ; i < end; ++i) {
|
||||||
if (pit->isNewline(i)) {
|
if (pit->isNewline(i)) {
|
||||||
point = i;
|
point = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Break before...
|
// Break before...
|
||||||
if (i + 1 < last) {
|
if (i + 1 < end) {
|
||||||
InsetOld * in = pit->getInset(i + 1);
|
InsetOld * in = pit->getInset(i + 1);
|
||||||
if (in && in->display()) {
|
if (in && in->display()) {
|
||||||
point = i;
|
point = i;
|
||||||
@ -560,7 +565,7 @@ void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
|
|||||||
// 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 == end || chunkwidth >= width - left) {
|
||||||
if (pos < i) {
|
if (pos < i) {
|
||||||
point = i - 1;
|
point = i - 1;
|
||||||
// exit on last registered breakpoint:
|
// exit on last registered breakpoint:
|
||||||
@ -568,7 +573,7 @@ void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// emergency exit:
|
// emergency exit:
|
||||||
if (i + 1 < last)
|
if (i + 1 < end)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -583,13 +588,13 @@ void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (point == last && x >= width) {
|
if (point == end && x >= width) {
|
||||||
// didn't find one, break at the point we reached the edge
|
// didn't find one, break at the point we reached the edge
|
||||||
point = i;
|
point = i;
|
||||||
} else if (i == last && x < width) {
|
} else if (i == end && x < width) {
|
||||||
// found one, but we fell off the end of the par, so prefer
|
// found one, but we fell off the end of the par, so prefer
|
||||||
// that.
|
// that.
|
||||||
point = last;
|
point = end - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// manual labels cannot be broken in LaTeX. But we
|
// manual labels cannot be broken in LaTeX. But we
|
||||||
@ -1227,8 +1232,10 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
|
|||||||
// The test on pit->size() is to catch zero-size pars, which
|
// The test on pit->size() is to catch zero-size pars, which
|
||||||
// would trigger the assert in Paragraph::getInset().
|
// would trigger the assert in Paragraph::getInset().
|
||||||
//inset = pit->size() ? pit->getInset(row.pos()) : 0;
|
//inset = pit->size() ? pit->getInset(row.pos()) : 0;
|
||||||
inset = pit->isInset(row.pos()) ? pit->getInset(row.pos()) : 0;
|
if (!pit->empty()
|
||||||
if (inset && inset->display()) {
|
&& pit->isInset(row.pos())
|
||||||
|
&& pit->getInset(row.pos())->display())
|
||||||
|
{
|
||||||
align = LYX_ALIGN_CENTER;
|
align = LYX_ALIGN_CENTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1895,7 +1902,8 @@ void LyXText::redoParagraphInternal(ParagraphList::iterator pit)
|
|||||||
|
|
||||||
// rebreak the paragraph
|
// rebreak the paragraph
|
||||||
int const ww = workWidth();
|
int const ww = workWidth();
|
||||||
for (pos_type z = 0; z < pit->size() + 1; ) {
|
pos_type z = 0;
|
||||||
|
do {
|
||||||
Row row(z);
|
Row row(z);
|
||||||
rowBreakPoint(pit, row);
|
rowBreakPoint(pit, row);
|
||||||
z = row.endpos();
|
z = row.endpos();
|
||||||
@ -1906,7 +1914,8 @@ void LyXText::redoParagraphInternal(ParagraphList::iterator pit)
|
|||||||
pit->rows.push_back(row);
|
pit->rows.push_back(row);
|
||||||
pit->width = std::max(pit->width, row.width());
|
pit->width = std::max(pit->width, row.width());
|
||||||
pit->height += row.height();
|
pit->height += row.height();
|
||||||
}
|
} while (z < pit->size());
|
||||||
|
|
||||||
height += pit->height;
|
height += pit->height;
|
||||||
//lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
|
//lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
|
||||||
}
|
}
|
||||||
|
13
src/text2.C
13
src/text2.C
@ -1311,18 +1311,27 @@ void LyXText::setCursor(LyXCursor & cur, paroffset_type par,
|
|||||||
|
|
||||||
// None of these should happen, but we're scaredy-cats
|
// None of these should happen, but we're scaredy-cats
|
||||||
if (pos > pit->size()) {
|
if (pos > pit->size()) {
|
||||||
lyxerr << "dont like 1, pos: " << pos << " size: " << pit->size() << endl;
|
lyxerr << "dont like 1, pos: " << pos
|
||||||
|
<< " size: " << pit->size()
|
||||||
|
<< " row.pos():" << row.pos()
|
||||||
|
<< " paroffset: " << par << endl;
|
||||||
pos = 0;
|
pos = 0;
|
||||||
cur.pos(0);
|
cur.pos(0);
|
||||||
|
BOOST_ASSERT(false);
|
||||||
} else if (pos > last + 1) {
|
} else if (pos > last + 1) {
|
||||||
lyxerr << "dont like 2 please report" << endl;
|
lyxerr << "dont like 2 please report" << endl;
|
||||||
// This shouldn't happen.
|
// This shouldn't happen.
|
||||||
pos = last + 1;
|
pos = last + 1;
|
||||||
cur.pos(pos);
|
cur.pos(pos);
|
||||||
|
BOOST_ASSERT(false);
|
||||||
} else if (pos < row.pos()) {
|
} else if (pos < row.pos()) {
|
||||||
lyxerr << "dont like 3 please report" << endl;
|
lyxerr << "dont like 3 please report pos:" << pos
|
||||||
|
<< " size: " << pit->size()
|
||||||
|
<< " row.pos():" << row.pos()
|
||||||
|
<< " paroffset: " << par << endl;
|
||||||
pos = row.pos();
|
pos = row.pos();
|
||||||
cur.pos(pos);
|
cur.pos(pos);
|
||||||
|
BOOST_ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// now get the cursors x position
|
// now get the cursors x position
|
||||||
|
Loading…
Reference in New Issue
Block a user