small stuff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7436 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-07-29 01:46:09 +00:00
parent 7fa3f39b0d
commit 6e844a0aed
2 changed files with 51 additions and 82 deletions

View File

@ -16,9 +16,7 @@ using std::min;
bool isParEnd(LyXText const & lt, RowList::iterator rit) bool isParEnd(LyXText const & lt, RowList::iterator rit)
{ {
RowList::iterator next_row = boost::next(rit); RowList::iterator next_row = boost::next(rit);
return next_row == lt.rows().end() || next_row->par() != rit->par();
return next_row == lt.rows().end() ||
next_row->par() != rit->par();
} }
@ -27,11 +25,10 @@ pos_type lastPos(LyXText const & lt, RowList::iterator rit)
if (rit->par()->empty()) if (rit->par()->empty())
return 0; return 0;
if (isParEnd(lt, rit)) { if (isParEnd(lt, rit))
return rit->par()->size() - 1; return rit->par()->size() - 1;
} else {
return boost::next(rit)->pos() - 1; return boost::next(rit)->pos() - 1;
}
} }
@ -75,15 +72,11 @@ int numberOfSeparators(LyXText const & lt, RowList::iterator rit)
{ {
pos_type const last = lastPrintablePos(lt, rit); pos_type const last = lastPrintablePos(lt, rit);
ParagraphList::iterator pit = rit->par(); ParagraphList::iterator pit = rit->par();
int n = 0; int n = 0;
pos_type p = max(rit->pos(), pit->beginningOfBody()); pos_type p = max(rit->pos(), pit->beginningOfBody());
for (; p < last; ++p) { for ( ; p < last; ++p)
if (pit->isSeparator(p)) { if (pit->isSeparator(p))
++n; ++n;
}
}
return n; return n;
} }
@ -98,10 +91,9 @@ int numberOfHfills(LyXText const & lt, RowList::iterator rit)
// hfill *DO* count at the beginning of paragraphs! // hfill *DO* count at the beginning of paragraphs!
if (first) { if (first) {
while (first < last && pit->isHfill(first)) { while (first < last && pit->isHfill(first))
++first; ++first;
} }
}
first = max(first, pit->beginningOfBody()); first = max(first, pit->beginningOfBody());
@ -151,15 +143,9 @@ bool hfillExpansion(LyXText const & lt, RowList::iterator rit, pos_type pos)
// 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(lt, rit)) { if (pos >= lastPos(lt, rit))
pos_type i = rit->pos(); for (pos_type i = rit->pos(); i < pos && !pit->isHfill(i); ++i)
while (i < pos && !pit->isHfill(i)) {
++i;
}
if (i == pos) {
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

View File

@ -154,7 +154,7 @@ int LyXText::workWidth(InsetOld const * inset) const
ownerParagraphs().end(), ownerParagraphs().end(),
*inset->parOwner()); *inset->parOwner());
if (par == ownerParagraphs().end()) { if (par == ownerParagraphs().end()) {
lyxerr[Debug::GUI] << "LyXText::workWidth: unexpected\n"; lyxerr << "LyXText::workWidth: unexpected\n";
return -1; return -1;
} }
@ -167,13 +167,10 @@ int LyXText::workWidth(InsetOld const * inset) const
// Optimization here: in most cases, the real row is // Optimization here: in most cases, the real row is
// not needed, but only the par/pos values. So we just // not needed, but only the par/pos values. So we just
// construct a dummy row for leftMargin. (JMarc) // construct a dummy row for leftMargin. (JMarc)
Row dummyrow; return workWidth() - leftMargin(Row(par, pos));
dummyrow.par(par); }
dummyrow.pos(pos);
return workWidth() - leftMargin(dummyrow); RowList::iterator row = getRow(par, pos);
} else {
int dummy_y;
RowList::iterator row = getRow(par, pos, dummy_y);
RowList::iterator frow = row; RowList::iterator frow = row;
RowList::iterator beg = rowlist_.begin(); RowList::iterator beg = rowlist_.begin();
@ -184,15 +181,11 @@ int LyXText::workWidth(InsetOld const * inset) const
unsigned int maxw = 0; unsigned int maxw = 0;
while (!isParEnd(*this, frow)) { while (!isParEnd(*this, frow)) {
if ((frow != row) && (maxw < frow->width())) if (frow != row && maxw < frow->width())
maxw = frow->width(); maxw = frow->width();
++frow; ++frow;
} }
if (maxw) return maxw ? maxw : workWidth();
return maxw;
}
return workWidth();
} }
@ -738,14 +731,12 @@ int LyXText::rightMargin(Buffer const & buf, Row const & row) const
LyXTextClass const & tclass = buf.params.getLyXTextClass(); LyXTextClass const & tclass = buf.params.getLyXTextClass();
LyXLayout_ptr const & layout = row.par()->layout(); LyXLayout_ptr const & layout = row.par()->layout();
int x = PAPER_MARGIN return PAPER_MARGIN
+ font_metrics::signedWidth(tclass.rightmargin(), + font_metrics::signedWidth(tclass.rightmargin(),
tclass.defaultfont()); tclass.defaultfont());
+ font_metrics::signedWidth(layout->rightmargin,
x += font_metrics::signedWidth(layout->rightmargin,
tclass.defaultfont()) tclass.defaultfont())
* 4 / (row.par()->getDepth() + 4); * 4 / (row.par()->getDepth() + 4);
return x;
} }
@ -1075,16 +1066,12 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
Assert(rit != rows().end()); Assert(rit != rows().end());
// get the maximum ascent and the maximum descent // get the maximum ascent and the maximum descent
float layoutasc = 0; double layoutasc = 0;
float layoutdesc = 0; double layoutdesc = 0;
float tmptop = 0; double tmptop = 0;
// ok, let us initialize the maxasc and maxdesc value. // ok, let us initialize the maxasc and maxdesc value.
// This depends in LaTeX of the font of the last character // Only the fontsize count. The other properties
// in the paragraph. The hack below is necessary because
// of the possibility of open footnotes
// Correction: only the fontsize count. The other properties
// are taken from the layoutfont. Nicer on the screen :) // are taken from the layoutfont. Nicer on the screen :)
ParagraphList::iterator pit = rit->par(); ParagraphList::iterator pit = rit->par();
@ -1101,20 +1088,17 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
LyXFont labelfont = getLabelFont(pit); LyXFont labelfont = getLabelFont(pit);
float spacing_val = 1.0; double spacing_val = 1.0;
if (!pit->params().spacing().isDefault()) { if (!pit->params().spacing().isDefault())
spacing_val = pit->params().spacing().getValue(); spacing_val = pit->params().spacing().getValue();
} else { else
spacing_val = bv()->buffer()->params.spacing.getValue(); spacing_val = bv()->buffer()->params.spacing.getValue();
}
//lyxerr << "spacing_val = " << spacing_val << endl; //lyxerr << "spacing_val = " << spacing_val << endl;
int maxasc = int(font_metrics::maxAscent(font) * int maxasc = int(font_metrics::maxAscent(font) *
layout->spacing.getValue() * layout->spacing.getValue() * spacing_val);
spacing_val);
int maxdesc = int(font_metrics::maxDescent(font) * int maxdesc = int(font_metrics::maxDescent(font) *
layout->spacing.getValue() * layout->spacing.getValue() * spacing_val);
spacing_val);
pos_type const pos_end = lastPos(*this, rit); pos_type const pos_end = lastPos(*this, rit);
int labeladdon = 0; int labeladdon = 0;
@ -1130,7 +1114,8 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
// 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 = rit->pos(); pos <= pos_end; ++pos) {
// Manual inlined optimised version of common case of "maxwidth += singleWidth(pit, pos);" // Manual inlined optimised version of common case of
// "maxwidth += singleWidth(pit, pos);"
char const c = par.getChar(pos); char const c = par.getChar(pos);
if (IsPrintable(c)) { if (IsPrintable(c)) {
@ -1391,9 +1376,9 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
double x = 0; double x = 0;
if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) { if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) {
double dummy;
// this IS needed // this IS needed
rit->width(maxwidth); rit->width(maxwidth);
double dummy;
prepareToPrint(rit, x, dummy, dummy, dummy, false); prepareToPrint(rit, x, dummy, dummy, dummy, false);
} }
rit->width(int(maxwidth + x)); rit->width(int(maxwidth + x));
@ -1401,11 +1386,10 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
width = max(0, workWidth()); width = max(0, workWidth());
RowList::iterator it = rows().begin(); RowList::iterator it = rows().begin();
RowList::iterator end = rows().end(); RowList::iterator end = rows().end();
for (; it != end; ++it) { for (; it != end; ++it)
if (it->width() > width) if (it->width() > width)
width = it->width(); width = it->width();
} }
}
} }
@ -2642,8 +2626,7 @@ void LyXText::backspace()
if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos()) if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
!= cursor.boundary()) != cursor.boundary())
setCursor(cursor.par(), cursor.pos(), false, setCursor(cursor.par(), cursor.pos(), false, !cursor.boundary());
!cursor.boundary());
lastpos = cursor.par()->size(); lastpos = cursor.par()->size();
if (cursor.pos() == lastpos) if (cursor.pos() == lastpos)