From 294e4884ee29585d311177406cd31499e6d81877 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 25 Aug 2020 10:25:14 +0200 Subject: [PATCH] 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 6e4cf31ac1..c8b9157f3c 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 353d28926c..6484967fe0 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; -- 2.39.2