]> git.lyx.org Git - features.git/commitdiff
Center correctly top labels like Abstract.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 25 Aug 2020 08:25:14 +0000 (10:25 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 25 Aug 2020 08:30:34 +0000 (10:30 +0200)
They used to take the paragraph indentation into account.

Fixes bug #11939.

src/RowPainter.cpp
src/TextMetrics.h

index 6e4cf31ac10eed23dd7016d30067091ec4fd27b1..c8b9157f3c52dcb17389e98e10b861e4d39a78bd 100644 (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);
        }
index 353d28926cea72f7e6d1bd45753506d43c40f8b6..6484967fe08d840b96f1924fe7377a417e9a3701 100644 (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;