+
+ // the paper margins
+ if (!row_ptr->par()->previous() && bv_owner)
+ maxasc += LYX_PAPER_MARGIN;
+
+ // add the vertical spaces, that the user added
+ maxasc += getLengthMarkerHeight(bview, firstpar->params().spaceTop());
+
+ // do not forget the DTP-lines!
+ // there height depends on the font of the nearest character
+ if (firstpar->params().lineTop())
+ maxasc += 2 * lyxfont::ascent('x', getFont(bview->buffer(),
+ firstpar, 0));
+
+ // and now the pagebreaks
+ if (firstpar->params().pagebreakTop())
+ maxasc += 3 * defaultHeight();
+
+ // This is special code for the chapter, since the label of this
+ // layout is printed in an extra row
+ if (layout.labeltype == LABEL_COUNTER_CHAPTER
+ && bview->buffer()->params.secnumdepth >= 0)
+ {
+ float spacing_val = 1.0;
+ if (!row_ptr->par()->params().spacing().isDefault()) {
+ spacing_val = row_ptr->par()->params().spacing().getValue();
+ } else {
+ spacing_val = bview->buffer()->params.spacing.getValue();
+ }
+
+ labeladdon = int(lyxfont::maxDescent(labelfont) *
+ layout.spacing.getValue() *
+ spacing_val)
+ + int(lyxfont::maxAscent(labelfont) *
+ layout.spacing.getValue() *
+ spacing_val);
+ }
+
+ // special code for the top label
+ if ((layout.labeltype == LABEL_TOP_ENVIRONMENT
+ || layout.labeltype == LABEL_BIBLIO
+ || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
+ && row_ptr->par()->isFirstInSequence()
+ && !row_ptr->par()->getLabelstring().empty())
+ {
+ float spacing_val = 1.0;
+ if (!row_ptr->par()->params().spacing().isDefault()) {
+ spacing_val = row_ptr->par()->params().spacing().getValue();
+ } else {
+ spacing_val = bview->buffer()->params.spacing.getValue();
+ }
+
+ labeladdon = int(
+ (lyxfont::maxAscent(labelfont) *
+ layout.spacing.getValue() *
+ spacing_val)
+ +(lyxfont::maxDescent(labelfont) *
+ layout.spacing.getValue() *
+ spacing_val)
+ + layout.topsep * defaultHeight()
+ + layout.labelbottomsep * defaultHeight());
+ }
+
+ // and now the layout spaces, for example before and after a section,
+ // or between the items of a itemize or enumerate environment
+
+ if (!firstpar->params().pagebreakTop()) {
+ Paragraph * prev = row_ptr->par()->previous();
+ if (prev)
+ prev = row_ptr->par()->depthHook(row_ptr->par()->getDepth());
+ if (prev && prev->layout() == firstpar->layout() &&
+ prev->getDepth() == firstpar->getDepth() &&
+ prev->getLabelWidthString() == firstpar->getLabelWidthString())
+ {
+ layoutasc = (layout.itemsep * defaultHeight());
+ } else if (row_ptr->previous()) {
+ tmptop = layout.topsep;
+
+ if (row_ptr->previous()->par()->getDepth() >= row_ptr->par()->getDepth())
+ tmptop -= textclasslist[bview->buffer()->params.textclass][row_ptr->previous()->par()->layout()].bottomsep;
+
+ if (tmptop > 0)
+ layoutasc = (tmptop * defaultHeight());
+ } else if (row_ptr->par()->params().lineTop()) {
+ tmptop = layout.topsep;
+
+ if (tmptop > 0)
+ layoutasc = (tmptop * defaultHeight());
+ }
+
+ prev = row_ptr->par()->outerHook();
+ if (prev) {
+ maxasc += int(textclasslist[bview->buffer()->params.textclass][prev->layout()].parsep * defaultHeight());
+ } else {
+ if (firstpar->previous() &&
+ firstpar->previous()->getDepth() == 0 &&
+ firstpar->previous()->layout() !=
+ firstpar->layout())
+ {
+ // avoid parsep
+ } else if (firstpar->previous()) {
+ maxasc += int(layout.parsep * defaultHeight());
+ }
+ }
+ }
+ }
+
+ // is it a bottom line?
+ if (row_ptr->par() == par
+ && (!row_ptr->next() || row_ptr->next()->par() != row_ptr->par()))
+ {
+ // the paper margins
+ if (!par->next() && bv_owner)
+ maxdesc += LYX_PAPER_MARGIN;
+
+ // add the vertical spaces, that the user added
+ maxdesc += getLengthMarkerHeight(bview, firstpar->params().spaceBottom());
+
+ // do not forget the DTP-lines!
+ // there height depends on the font of the nearest character
+ if (firstpar->params().lineBottom())
+ maxdesc += 2 * lyxfont::ascent('x',
+ getFont(bview->buffer(),
+ par,
+ max(pos_type(0), par->size() - 1)));
+
+ // and now the pagebreaks
+ if (firstpar->params().pagebreakBottom())
+ maxdesc += 3 * defaultHeight();
+
+ // and now the layout spaces, for example before and after
+ // a section, or between the items of a itemize or enumerate
+ // environment
+ if (!firstpar->params().pagebreakBottom()
+ && row_ptr->par()->next()) {
+ Paragraph * nextpar = row_ptr->par()->next();
+ Paragraph * comparepar = row_ptr->par();
+ float usual = 0;
+ float unusual = 0;
+
+ if (comparepar->getDepth() > nextpar->getDepth()) {
+ usual = (textclasslist[bview->buffer()->params.textclass][comparepar->layout()].bottomsep * defaultHeight());
+ comparepar = comparepar->depthHook(nextpar->getDepth());
+ if (comparepar->layout()!= nextpar->layout()
+ || nextpar->getLabelWidthString() !=
+ comparepar->getLabelWidthString())
+ {
+ unusual = (textclasslist[bview->buffer()->params.textclass][comparepar->layout()].bottomsep * defaultHeight());
+ }
+ if (unusual > usual)
+ layoutdesc = unusual;
+ else
+ layoutdesc = usual;
+ } else if (comparepar->getDepth() == nextpar->getDepth()) {
+
+ if (comparepar->layout() != nextpar->layout()
+ || nextpar->getLabelWidthString() !=
+ comparepar->getLabelWidthString())
+ layoutdesc = int(textclasslist[bview->buffer()->params.textclass][comparepar->layout()].bottomsep * defaultHeight());
+ }
+ }
+ }
+
+ // incalculate the layout spaces
+ maxasc += int(layoutasc * 2 / (2 + firstpar->getDepth()));
+ maxdesc += int(layoutdesc * 2 / (2 + firstpar->getDepth()));
+
+ // calculate the new height of the text
+ height -= row_ptr->height();
+
+ row_ptr->height(maxasc + maxdesc + labeladdon);
+ row_ptr->baseline(maxasc + labeladdon);
+
+ height += row_ptr->height();
+ float x = 0;
+ if (layout.margintype != MARGIN_RIGHT_ADDRESS_BOX) {
+ float dummy;
+ // this IS needed
+ row_ptr->width(maxwidth);
+ prepareToPrint(bview, row_ptr, x, dummy, dummy, dummy, false);
+ }
+ row_ptr->width(int(maxwidth + x));
+ if (inset_owner) {
+ Row * r = firstrow;
+ width = max(0,workWidth(bview));
+ while (r) {
+ if (r->width() > width)
+ width = r->width();
+ r = r->next();
+ }
+ }
+}
+
+
+/* Appends the implicit specified paragraph behind the specified row,
+ * start at the implicit given position */
+void LyXText::appendParagraph(BufferView * bview, Row * row) const
+{
+ bool not_ready = true;
+
+ // The last character position of a paragraph is an invariant so we can
+ // safely get it here. (Asger)
+ pos_type const lastposition = row->par()->size();
+ do {
+ // Get the next breakpoint
+ pos_type z = nextBreakPoint(bview, row, workWidth(bview));
+
+ Row * tmprow = row;
+
+ // Insert the new row
+ if (z < lastposition) {
+ ++z;
+ insertRow(row, row->par(), z);
+ row = row->next();
+
+ row->height(0);
+ } else
+ not_ready = false;
+
+ // Set the dimensions of the row
+ // fixed fill setting now by calling inset->update() in
+ // SingleWidth when needed!
+ tmprow->fill(fill(bview, tmprow, workWidth(bview)));
+ setHeightOfRow(bview, tmprow);
+
+ } while (not_ready);
+}
+
+
+void LyXText::breakAgain(BufferView * bview, Row * row) const
+{
+ bool not_ready = true;
+
+ do {
+ // get the next breakpoint
+ pos_type z = nextBreakPoint(bview, row, workWidth(bview));
+ Row * tmprow = row;
+
+ if (z < row->par()->size()) {
+ if (!row->next() || (row->next() && row->next()->par() != row->par())) {
+ // insert a new row
+ ++z;
+ insertRow(row, row->par(), z);
+ row = row->next();
+ row->height(0);
+ } else {
+ row = row->next();
+ ++z;
+ if (row->pos() == z)
+ not_ready = false; // the rest will not change
+ else {
+ row->pos(z);
+ }
+ }
+ } else {
+ /* if there are some rows too much, delete them */
+ /* only if you broke the whole paragraph! */
+ Row * tmprow2 = row;
+ while (tmprow2->next() && tmprow2->next()->par() == row->par()) {
+ tmprow2 = tmprow2->next();
+ }
+ while (tmprow2 != row) {
+ tmprow2 = tmprow2->previous();
+ removeRow(tmprow2->next());
+ }
+ not_ready = false;
+ }
+
+ /* set the dimensions of the row */
+ tmprow->fill(fill(bview, tmprow, workWidth(bview)));