[LyX/master] Center correctly top labels like Abstract.
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Tue Aug 25 08:05:49 UTC 2020
commit 294e4884ee29585d311177406cd31499e6d81877
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date: Tue Aug 25 10:25:14 2020 +0200
Center correctly top labels like Abstract.
They used to take the paragraph indentation into account.
Fixes bug #11939.
---
src/RowPainter.cpp | 12 ++++++++++--
src/TextMetrics.h | 18 +++++++++---------
2 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/src/RowPainter.cpp b/src/RowPainter.cpp
index 6e4cf31..c8b9157 100644
--- a/src/RowPainter.cpp
+++ b/src/RowPainter.cpp
@@ -458,8 +458,16 @@ void RowPainter::paintTopLevelLabel() const
double x = x_;
if (layout.labeltype == LABEL_CENTERED) {
- x += (tm_.width() - row_.left_margin - row_.right_margin) / 2;
- x -= fm.width(str) / 2;
+ /* 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()) {
x = xo_ + tm_.width() - row_.right_margin - fm.width(str);
}
diff --git a/src/TextMetrics.h b/src/TextMetrics.h
index 353d289..6484967 100644
--- a/src/TextMetrics.h
+++ b/src/TextMetrics.h
@@ -123,6 +123,15 @@ public:
/// current text height.
int height() const { return dim_.height(); }
+ /**
+ * Returns the left beginning of the text.
+ * This information cannot be taken from the layout object, because
+ * in LaTeX the beginning of the text fits in some cases
+ * (for example sections) exactly the label-width.
+ */
+ int leftMargin(pit_type pit, pos_type pos) const;
+ int leftMargin(pit_type pit) const;
+
///
int rightMargin(ParagraphMetrics const & pm) const;
int rightMargin(pit_type const pit) const;
@@ -136,15 +145,6 @@ private:
///
ParagraphMetrics & parMetrics(pit_type, bool redo_paragraph);
- /**
- * Returns the left beginning of the text.
- * This information cannot be taken from the layout object, because
- * in LaTeX the beginning of the text fits in some cases
- * (for example sections) exactly the label-width.
- */
- int leftMargin(pit_type pit, pos_type pos) const;
- int leftMargin(pit_type pit) const;
-
/// the minimum space a manual label needs on the screen in pixels
int labelFill(Row const & row) const;
More information about the lyx-cvs
mailing list