- // Now use the layout information.
- double layoutasc = 0;
- double layoutdesc = 0;
- int labeladdon = 0;
- ParagraphList const & pars = text_->paragraphs();
- Inset const & inset = text_->inset();
- double const dh = defaultRowHeight();
-
- // is it a top line?
- if (row.pos() == 0 && topBottomSpace) {
- BufferParams const & bufparams = bv_->buffer().params();
- // some parskips VERY EASY IMPLEMENTATION
- if (bufparams.paragraph_separation == BufferParams::ParagraphSkipSeparation
- && !inset.getLayout().parbreakIsNewline()
- && !par.layout().parbreak_is_newline
- && pit > 0
- && ((layout.isParagraph() && par.getDepth() == 0)
- || (pars[pit - 1].layout().isParagraph()
- && pars[pit - 1].getDepth() == 0))) {
- maxasc += bufparams.getDefSkip().inPixels(*bv_);
- }
-
- if (par.params().startOfAppendix())
- maxasc += int(3 * dh);
-
- // special code for the top label
- if (layout.labelIsAbove()
- && (!layout.isParagraphGroup() || text_->isFirstInSequence(pit))
- && !par.labelString().empty()) {
- FontInfo labelfont = text_->labelFont(par);
- FontMetrics const & lfm = theFontMetrics(labelfont);
- labeladdon = int(
- lfm.maxHeight()
- * layout.spacing.getValue()
- * text_->spacing(par)
- + (layout.topsep + layout.labelbottomsep) * dh);
- }
-
- // Add the layout spaces, for example before and after
- // a section, or between the items of a itemize or enumerate
- // environment.
-
- pit_type prev = text_->depthHook(pit, par.getDepth());
- Paragraph const & prevpar = pars[prev];
- if (prev != pit
- && prevpar.layout() == layout
- && prevpar.getDepth() == par.getDepth()
- && prevpar.getLabelWidthString()
- == par.getLabelWidthString()) {
- layoutasc = layout.itemsep * dh;
- } else if (pit != 0 || row.pos() != 0) {
- if (layout.topsep > 0)
- layoutasc = layout.topsep * dh;
- }
-
- prev = text_->outerHook(pit);
- if (prev != pit_type(pars.size())) {
- maxasc += int(pars[prev].layout().parsep * dh);
- } else if (pit != 0) {
- Paragraph const & prevpar = pars[pit - 1];
- if (prevpar.getDepth() != 0 ||
- prevpar.layout() == layout) {
- maxasc += int(layout.parsep * dh);
- }
- }
- }
-
- // is it a bottom line?
- if (row.endpos() >= par.size() && topBottomSpace) {
- // add the layout spaces, for example before and after
- // a section, or between the items of a itemize or enumerate
- // environment
- pit_type nextpit = pit + 1;
- if (nextpit != pit_type(pars.size())) {
- pit_type cpit = pit;
-
- if (pars[cpit].getDepth() > pars[nextpit].getDepth()) {
- double usual = pars[cpit].layout().bottomsep * dh;
- double unusual = 0;
- cpit = text_->depthHook(cpit, pars[nextpit].getDepth());
- if (pars[cpit].layout() != pars[nextpit].layout()
- || pars[nextpit].getLabelWidthString() != pars[cpit].getLabelWidthString())
- unusual = pars[cpit].layout().bottomsep * dh;
- layoutdesc = max(unusual, usual);
- } else if (pars[cpit].getDepth() == pars[nextpit].getDepth()) {
- if (pars[cpit].layout() != pars[nextpit].layout()
- || pars[nextpit].getLabelWidthString() != pars[cpit].getLabelWidthString())
- layoutdesc = int(pars[cpit].layout().bottomsep * dh);
- }
- }
- }
-
- // incalculate the layout spaces
- maxasc += int(layoutasc * 2 / (2 + pars[pit].getDepth()));
- maxdes += int(layoutdesc * 2 / (2 + pars[pit].getDepth()));
-
- // FIXME: the correct way is to do the following is to move the
- // following code in another method specially tailored for the
- // main Text. The following test is thus bogus.
- // Top and bottom margin of the document (only at top-level)
- if (text_->isMainText() && topBottomSpace) {
- if (pit == 0 && row.pos() == 0)
- maxasc += 20;
- if (pit + 1 == pit_type(pars.size()) &&
- row.endpos() == par.size() &&
- !(row.endpos() > 0 && par.isNewline(row.endpos() - 1)))
- maxdes += 20;
- }
-
- row.dimension().asc = maxasc + labeladdon;