Center correctly top labels like Abstract.

They used to take the paragraph indentation into account.

Fixes bug #11939.
This commit is contained in:
Jean-Marc Lasgouttes 2020-08-25 10:25:14 +02:00
parent 4a9bbe61df
commit 294e4884ee
2 changed files with 19 additions and 11 deletions

View File

@ -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);
}

View File

@ -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;