From 6e844a0aed3070b58e820e1f14fc18da3f53ea24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 29 Jul 2003 01:46:09 +0000 Subject: [PATCH] small stuff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7436 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/lyxrow_funcs.C | 42 +++++++-------------- src/text.C | 91 +++++++++++++++++++--------------------------- 2 files changed, 51 insertions(+), 82 deletions(-) diff --git a/src/lyxrow_funcs.C b/src/lyxrow_funcs.C index 9161e092f6..f2ed678408 100644 --- a/src/lyxrow_funcs.C +++ b/src/lyxrow_funcs.C @@ -16,9 +16,7 @@ using std::min; bool isParEnd(LyXText const & lt, RowList::iterator 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()) return 0; - if (isParEnd(lt, rit)) { + if (isParEnd(lt, rit)) return rit->par()->size() - 1; - } else { - return boost::next(rit)->pos() - 1; - } + + return boost::next(rit)->pos() - 1; } @@ -73,18 +70,14 @@ pos_type lastPrintablePos(LyXText const & lt, RowList::iterator rit) 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(); - - int n = 0; - - pos_type p = max(rit->pos(), pit->beginningOfBody()); - for (; p < last; ++p) { - if (pit->isSeparator(p)) { - ++n; - } - } - return n; + int n = 0; + pos_type p = max(rit->pos(), pit->beginningOfBody()); + for ( ; p < last; ++p) + if (pit->isSeparator(p)) + ++n; + return n; } @@ -98,9 +91,8 @@ int numberOfHfills(LyXText const & lt, RowList::iterator rit) // hfill *DO* count at the beginning of paragraphs! if (first) { - while (first < last && pit->isHfill(first)) { + while (first < last && pit->isHfill(first)) ++first; - } } 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 // unless another hfill exists on the line - if (pos >= lastPos(lt, rit)) { - pos_type i = rit->pos(); - while (i < pos && !pit->isHfill(i)) { - ++i; - } - if (i == pos) { + if (pos >= lastPos(lt, rit)) + for (pos_type i = rit->pos(); i < pos && !pit->isHfill(i); ++i) return false; - } - } // at the beginning of a row it does not count, if it is not // the first row of a paragaph diff --git a/src/text.C b/src/text.C index c266b1f7a8..23dd040824 100644 --- a/src/text.C +++ b/src/text.C @@ -154,7 +154,7 @@ int LyXText::workWidth(InsetOld const * inset) const ownerParagraphs().end(), *inset->parOwner()); if (par == ownerParagraphs().end()) { - lyxerr[Debug::GUI] << "LyXText::workWidth: unexpected\n"; + lyxerr << "LyXText::workWidth: unexpected\n"; return -1; } @@ -167,32 +167,25 @@ int LyXText::workWidth(InsetOld const * inset) const // Optimization here: in most cases, the real row is // not needed, but only the par/pos values. So we just // construct a dummy row for leftMargin. (JMarc) - Row dummyrow; - dummyrow.par(par); - dummyrow.pos(pos); - return workWidth() - leftMargin(dummyrow); - } else { - int dummy_y; - RowList::iterator row = getRow(par, pos, dummy_y); - RowList::iterator frow = row; - RowList::iterator beg = rowlist_.begin(); - - while (frow != beg && frow->par() == boost::prior(frow)->par()) - --frow; - - // FIXME: I don't understand this code - jbl - - unsigned int maxw = 0; - while (!isParEnd(*this, frow)) { - if ((frow != row) && (maxw < frow->width())) - maxw = frow->width(); - ++frow; - } - if (maxw) - return maxw; - + return workWidth() - leftMargin(Row(par, pos)); } - return workWidth(); + + RowList::iterator row = getRow(par, pos); + RowList::iterator frow = row; + RowList::iterator beg = rowlist_.begin(); + + while (frow != beg && frow->par() == boost::prior(frow)->par()) + --frow; + + // FIXME: I don't understand this code - jbl + + unsigned int maxw = 0; + while (!isParEnd(*this, frow)) { + if (frow != row && maxw < frow->width()) + maxw = frow->width(); + ++frow; + } + return maxw ? maxw : workWidth(); } @@ -738,14 +731,12 @@ int LyXText::rightMargin(Buffer const & buf, Row const & row) const LyXTextClass const & tclass = buf.params.getLyXTextClass(); LyXLayout_ptr const & layout = row.par()->layout(); - int x = PAPER_MARGIN + return PAPER_MARGIN + font_metrics::signedWidth(tclass.rightmargin(), tclass.defaultfont()); - - x += font_metrics::signedWidth(layout->rightmargin, + + font_metrics::signedWidth(layout->rightmargin, tclass.defaultfont()) * 4 / (row.par()->getDepth() + 4); - return x; } @@ -1075,17 +1066,13 @@ void LyXText::setHeightOfRow(RowList::iterator rit) Assert(rit != rows().end()); // get the maximum ascent and the maximum descent - float layoutasc = 0; - float layoutdesc = 0; - float tmptop = 0; + double layoutasc = 0; + double layoutdesc = 0; + double tmptop = 0; // ok, let us initialize the maxasc and maxdesc value. - // This depends in LaTeX of the font of the last character - // 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 :) + // Only the fontsize count. The other properties + // are taken from the layoutfont. Nicer on the screen :) ParagraphList::iterator pit = rit->par(); LyXLayout_ptr const & layout = pit->layout(); @@ -1101,20 +1088,17 @@ void LyXText::setHeightOfRow(RowList::iterator rit) LyXFont labelfont = getLabelFont(pit); - float spacing_val = 1.0; - if (!pit->params().spacing().isDefault()) { + double spacing_val = 1.0; + if (!pit->params().spacing().isDefault()) spacing_val = pit->params().spacing().getValue(); - } else { + else spacing_val = bv()->buffer()->params.spacing.getValue(); - } //lyxerr << "spacing_val = " << spacing_val << endl; - int maxasc = int(font_metrics::maxAscent(font) * - layout->spacing.getValue() * - spacing_val); + int maxasc = int(font_metrics::maxAscent(font) * + layout->spacing.getValue() * spacing_val); int maxdesc = int(font_metrics::maxDescent(font) * - layout->spacing.getValue() * - spacing_val); + layout->spacing.getValue() * spacing_val); pos_type const pos_end = lastPos(*this, rit); int labeladdon = 0; @@ -1130,7 +1114,8 @@ void LyXText::setHeightOfRow(RowList::iterator rit) // Check if any insets are larger 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); if (IsPrintable(c)) { @@ -1391,9 +1376,9 @@ void LyXText::setHeightOfRow(RowList::iterator rit) double x = 0; if (layout->margintype != MARGIN_RIGHT_ADDRESS_BOX) { - double dummy; // this IS needed rit->width(maxwidth); + double dummy; prepareToPrint(rit, x, dummy, dummy, dummy, false); } rit->width(int(maxwidth + x)); @@ -1401,10 +1386,9 @@ void LyXText::setHeightOfRow(RowList::iterator rit) width = max(0, workWidth()); RowList::iterator it = rows().begin(); RowList::iterator end = rows().end(); - for (; it != end; ++it) { + for (; it != end; ++it) if (it->width() > width) width = it->width(); - } } } @@ -2642,8 +2626,7 @@ void LyXText::backspace() if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos()) != cursor.boundary()) - setCursor(cursor.par(), cursor.pos(), false, - !cursor.boundary()); + setCursor(cursor.par(), cursor.pos(), false, !cursor.boundary()); lastpos = cursor.par()->size(); if (cursor.pos() == lastpos)