]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
ctests: categorize #12708 test file as resolved
[lyx.git] / src / TextMetrics.cpp
index 2e5fd562153f749049c9e8554fe0e1e775656611..32768970bb66a2acd5275bc8dabc37257ebc6e41 100644 (file)
@@ -520,6 +520,7 @@ bool TextMetrics::redoParagraph(pit_type const pit, bool const align_rows)
                        displayFont(pit, e.pos) : bufferfont;
                MacroContext mc(&buffer, parPos);
                MetricsInfo mi(bv_, font.fontInfo(), w, mc, e.pos == 0, tight_);
+               mi.base.outer_font = displayFont(pit, e.pos).fontInfo();
                e.inset->metrics(mi, dim);
                /* FIXME: This is a kind of hack. This allows InsetMathHull to
                 * state that it needs some elbow room beyond its width, in
@@ -1150,7 +1151,7 @@ RowList TextMetrics::breakParagraph(Row const & bigrow) const
                // pile, or the place when we were in main row
                Row::Element elt = *fcit;
                Row::Elements tail;
-               elt.splitAt(width - rows.back().width(), next_width, false, tail);
+               elt.splitAt(width - rows.back().width(), next_width, Row::FIT, tail);
                Row & rb = rows.back();
                if (elt.type == Row::MARGINSPACE)
                        elt.dim.wid = max(elt.dim.wid, leftMargin(bigrow.pit()) - rb.width());
@@ -1175,6 +1176,9 @@ RowList TextMetrics::breakParagraph(Row const & bigrow) const
                // Last row in paragraph is flushed
                rows.back().flushed(true);
                cleanupRow(rows.back(), true);
+               // Is there an end-of-paragraph change?
+               if (bigrow.needsChangeBar())
+                       rows.back().needsChangeBar(true);
        }
 
        return rows;
@@ -1286,20 +1290,39 @@ void TextMetrics::setRowHeight(Row & row) const
 {
        Paragraph const & par = text_->getPar(row.pit());
        Layout const & layout = par.layout();
-       double const spacing_val = layout.spacing.getValue() * text_->spacing(par);
+       // leading space (line spacing) factor based on current paragraph
+       double spacing_val = layout.spacing.getValue() * text_->spacing(par);
+
+       // if this is the first row but not the first paragraph, take into
+       // account the spacing of the previous paragraph.
+       if (row.pos() == 0 && row.pit() > 0) {
+               // for the first row in the paragraph,
+               // use previous paragraphs line spacing if it is larger
+               Paragraph const & previousPar = text_->getPar(row.pit() - 1);
+               Layout const & previousLayout = previousPar.layout();
+               // leading space factor based on previous paragraph
+               double const previous_spacing_val
+                       = previousLayout.spacing.getValue() * text_->spacing(previousPar);
+               if (previous_spacing_val > spacing_val)
+                       spacing_val = previous_spacing_val;
+       }
 
        // Initial value for ascent (useful if row is empty).
        Font const font = displayFont(row.pit(), row.pos());
        FontMetrics const & fm = theFontMetrics(font);
-       int maxasc = int(fm.maxAscent() * spacing_val);
-       int maxdes = int(fm.maxDescent() * spacing_val);
+       int maxasc = int(fm.maxAscent()
+               // add leading space
+               + fm.maxHeight() * (spacing_val - 1));
+       int maxdes = int(fm.maxDescent());
 
        // Take label string into account (useful if labelfont is large)
        if (row.pos() == 0 && layout.labelIsInline()) {
                FontInfo const labelfont = text_->labelFont(par);
                FontMetrics const & lfm = theFontMetrics(labelfont);
-               maxasc = max(maxasc, int(lfm.maxAscent() * spacing_val));
-               maxdes = max(maxdes, int(lfm.maxDescent() * spacing_val));
+               maxasc = max(maxasc, int(lfm.maxAscent()
+                       // add leading space
+                       + lfm.maxHeight() * (spacing_val - 1)));
+               maxdes = max(maxdes, int(lfm.maxDescent()));
        }
 
        // Find the ascent/descent of the row contents
@@ -1309,8 +1332,10 @@ void TextMetrics::setRowHeight(Row & row) const
                        maxdes = max(maxdes, e.dim.descent());
                } else {
                        FontMetrics const & fm2 = theFontMetrics(e.font);
-                       maxasc = max(maxasc, int(fm2.maxAscent() * spacing_val));
-                       maxdes = max(maxdes, int(fm2.maxDescent() * spacing_val));
+                       maxasc = max(maxasc, int(fm2.maxAscent()
+                               // add leading space
+                               + fm2.maxHeight() * (spacing_val - 1)));
+                       maxdes = max(maxdes, int(fm2.maxDescent()));
                }
        }