[LyX/master] More consistent line spacing/leading

Pavel Sanda sanda at lyx.org
Thu Jul 27 07:33:43 UTC 2023


commit 9361bf56a3cd1a738ce0650083175a8a452610e3
Author: Daniel Ramoeller <d.lyx at web.de>
Date:   Tue Sep 22 06:28:06 2020 +0200

    More consistent line spacing/leading
    
    Uses maxHeight (= maxAscent + maxDescent) as leading.
    
    Fix for bug #11818.
---
 src/TextMetrics.cpp |   35 ++++++++++++++++++++++++++++-------
 1 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index 2e5fd56..51f73fd 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -1286,20 +1286,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 +1328,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()));
 		}
 	}
 


More information about the lyx-cvs mailing list