-void LyXText::setHeightOfRow(BufferView const & bv, pit_type const pit,
- Row & row)
-{
- Paragraph const & par = pars_[pit];
- // get the maximum ascent and the maximum descent
- double layoutasc = 0;
- double layoutdesc = 0;
- double const dh = defaultRowHeight();
-
- // ok, let us initialize the maxasc and maxdesc value.
- // Only the fontsize count. The other properties
- // are taken from the layoutfont. Nicer on the screen :)
- LyXLayout_ptr const & layout = par.layout();
-
- // as max get the first character of this row then it can
- // increase but not decrease the height. Just some point to
- // start with so we don't have to do the assignment below too
- // often.
- Buffer const & buffer = *bv.buffer();
- LyXFont font = getFont(buffer, par, row.pos());
- LyXFont::FONT_SIZE const tmpsize = font.size();
- font = getLayoutFont(buffer, pit);
- LyXFont::FONT_SIZE const size = font.size();
- font.setSize(tmpsize);
-
- LyXFont labelfont = getLabelFont(buffer, par);
-
- FontMetrics const & labelfont_metrics = theFontMetrics(labelfont);
- FontMetrics const & fontmetrics = theFontMetrics(font);
-
- // these are minimum values
- double const spacing_val = layout->spacing.getValue()
- * spacing(*bv.buffer(), par);
- //lyxerr << "spacing_val = " << spacing_val << endl;
- int maxasc = int(fontmetrics.maxAscent() * spacing_val);
- int maxdesc = int(fontmetrics.maxDescent() * spacing_val);
-
- // insets may be taller
- InsetList::const_iterator ii = par.insetlist.begin();
- InsetList::const_iterator iend = par.insetlist.end();
- for ( ; ii != iend; ++ii) {
- if (ii->pos >= row.pos() && ii->pos < row.endpos()) {
- maxasc = max(maxasc, ii->inset->ascent());
- maxdesc = max(maxdesc, ii->inset->descent());
- }
- }
-
- // Check if any custom fonts are larger (Asger)
- // This is not completely correct, but we can live with the small,
- // cosmetic error for now.
- int labeladdon = 0;
- pos_type const pos_end = row.endpos();
-
- LyXFont::FONT_SIZE maxsize =
- par.highestFontInRange(row.pos(), pos_end, size);
- if (maxsize > font.size()) {
- font.setSize(maxsize);
- maxasc = max(maxasc, fontmetrics.maxAscent());
- maxdesc = max(maxdesc, fontmetrics.maxDescent());
- }
-
- // This is nicer with box insets:
- ++maxasc;
- ++maxdesc;
-
- row.ascent(maxasc);
-
- // is it a top line?
- if (row.pos() == 0) {
- Buffer const & buffer = *bv.buffer();
- BufferParams const & bufparams = buffer.params();
- // some parksips VERY EASY IMPLEMENTATION
- if (bufparams.paragraph_separation
- == BufferParams::PARSEP_SKIP
- && 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);
-
- // This is special code for the chapter, since the label of this
- // layout is printed in an extra row
- if (layout->counter == "chapter"
- && !par.params().labelString().empty()) {
- labeladdon = int(labelfont_metrics.maxHeight()
- * layout->spacing.getValue()
- * spacing(buffer, par));
- }
-
- // special code for the top label
- if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
- || layout->labeltype == LABEL_BIBLIO
- || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
- && isFirstInSequence(pit, paragraphs())
- && !par.getLabelstring().empty())
- {
- labeladdon = int(
- labelfont_metrics.maxHeight()
- * layout->spacing.getValue()
- * spacing(*bv.buffer(), 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 = depthHook(pit, pars_, par.getDepth());
- if (prev != pit
- && pars_[prev].layout() == layout
- && pars_[prev].getDepth() == par.getDepth()
- && pars_[prev].getLabelWidthString() == par.getLabelWidthString())
- {
- layoutasc = layout->itemsep * dh;
- } else if (pit != 0 || row.pos() != 0) {
- if (layout->topsep > 0)
- layoutasc = layout->topsep * dh;
- }
-
- prev = outerHook(pit, pars_);
- if (prev != pit_type(pars_.size())) {
- maxasc += int(pars_[prev].layout()->parsep * dh);
- } else if (pit != 0) {
- if (pars_[pit - 1].getDepth() != 0 ||
- pars_[pit - 1].layout() == layout) {
- maxasc += int(layout->parsep * dh);
- }
- }
- }
-
- // is it a bottom line?
- if (row.endpos() >= par.size()) {
- // 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;
- double usual = 0;
- double unusual = 0;
-
- if (pars_[cpit].getDepth() > pars_[nextpit].getDepth()) {
- usual = pars_[cpit].layout()->bottomsep * dh;
- cpit = depthHook(cpit, paragraphs(), 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()));
- maxdesc += 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 LyXText. The following test is thus bogus.
- LyXText const & text = buffer.text();
- // Top and bottom margin of the document (only at top-level)
- if (&text == this) {
- if (pit == 0 && row.pos() == 0)
- maxasc += 20;
- if (pit + 1 == pit_type(pars_.size()) &&
- row.endpos() == par.size())
- maxdesc += 20;
- }
-
- row.ascent(maxasc + labeladdon);
- row.descent(maxdesc);
-}
-
-