[LyX/master] Fixup 824d1c99: do not change the semantics of leftMargin(pit_type)

Jean-Marc Lasgouttes lasgouttes at lyx.org
Tue Feb 16 22:20:16 UTC 2021


commit 3f093dd10397de42b6a8ae74cc52147776debb73
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Tue Feb 16 20:22:46 2021 +0100

    Fixup 824d1c99: do not change the semantics of leftMargin(pit_type)
    
    In the row painter, when painting a centered label, one wants to get
    the left/right margin of the non-first rows (without indent). It was a
    bad idea to change leftMargin(pit) to do that, because its semantics
    are unclear and the the code depends on the fact that this function does
    strange things when the paragraph is empty...
    
    Fixes bug #12118.
---
 src/RowPainter.cpp  |   10 ++++++----
 src/TextMetrics.cpp |    7 ++++---
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/RowPainter.cpp b/src/RowPainter.cpp
index 309c0a4..2175e4f 100644
--- a/src/RowPainter.cpp
+++ b/src/RowPainter.cpp
@@ -457,14 +457,16 @@ void RowPainter::paintTopLevelLabel() const
 
 	double x = x_;
 	if (layout.labeltype == LABEL_CENTERED) {
+		// The 'size + 1' is weird, but it makes sure that we get the
+		// left margin of non-first row.
+		int leftm = tm_.leftMargin(row_.pit(), par_.size() + 1);
+		int rightm = tm_.rightMargin(row_.pit());
+		if (row_.isRTL())
+			swap(leftm, rightm);
 		/* Currently, x points at row_.left_margin (which contains the
 		 * indent). First remove that, and then center the title with
 		 * respect to the left and right margins.
 		 */
-		int const leftm = row_.isRTL() ? tm_.rightMargin(row_.pit())
-		                               : tm_.leftMargin(row_.pit());
-		int const rightm = row_.isRTL() ? tm_.leftMargin(row_.pit())
-			                            : tm_.rightMargin(row_.pit());
 		x += leftm - row_.left_margin + (tm_.width() - leftm -rightm) / 2
 			- fm.width(str) / 2;
 	} else if (row_.isRTL()) {
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index 57956bd..c312478 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -1621,8 +1621,9 @@ void TextMetrics::deleteLineForward(Cursor & cur)
 
 int TextMetrics::leftMargin(pit_type pit) const
 {
-	// the + 1 is useful when the paragraph is empty
-	return leftMargin(pit, text_->paragraphs()[pit].size() + 1);
+	// FIXME: what is the semantics? It depends on whether the
+	// paragraph is empty!
+	return leftMargin(pit, text_->paragraphs()[pit].size());
 }
 
 
@@ -1635,7 +1636,7 @@ int TextMetrics::leftMargin(pit_type const pit, pos_type const pos) const
 	Paragraph const & par = pars[pit];
 	LASSERT(pos >= 0, return 0);
 	// We do not really care whether pos > par.size(), since we do not
-	// access the data. It can be actially useful, when querying the
+	// access the data. It can be actually useful, when querying the
 	// margin without indentation (see leftMargin(pit_type).
 
 	Buffer const & buffer = bv_->buffer();


More information about the lyx-cvs mailing list