]> git.lyx.org Git - features.git/commitdiff
Center correctly centered top labels (e.g. abstract)
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 5 Jan 2021 13:53:15 +0000 (14:53 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 5 Jan 2021 13:53:15 +0000 (14:53 +0100)
Since the first row may be indented, it is necessary to find out what
the left margin would be on the next row (even if this next row does
not exst.

To this end, modify TextMetrics::leftMargin so that it does not test
whether position is after the last position of the paragraph.

Cosmetics: set the size of label to "small" for Abstract layout in
standard classes and reduce the spacing between label and text.

Fixes remainder of #11939.

lib/layouts/stdstruct.inc
src/RowPainter.cpp
src/TextMetrics.cpp

index b611b53da187a2bb751da654381e3a7ae2e3c886..a0a9750711480e80574bc9ebeaae62f910bdf624 100644 (file)
@@ -27,13 +27,12 @@ Style Abstract
        Align                 Block
        LabelType             Centered
        LabelString           "Abstract"
-       LabelBottomSep        0.5
+       LabelBottomSep        0.2
        Font
          Size                Small
        EndFont
        LabelFont
          Series              Bold
-         Size                Large
        EndFont
        HTMLLabelFirst        1
        HTMLForceCSS          1
index e378f433e8ebc6d09b8d3c3012f9fd861d365dc4..9f9f51eb221639aae433ed702c4517822bde1700 100644 (file)
@@ -462,8 +462,8 @@ void RowPainter::paintTopLevelLabel() const
                 * 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_.leftMargin(row_.pit(), 1);
+               int const rightm = row_.isRTL() ? tm_.leftMargin(row_.pit(), 1)
                                                    : tm_.rightMargin(row_.pit());
                x += leftm - row_.left_margin + (tm_.width() - leftm -rightm) / 2
                        - fm.width(str) / 2;
index 214fe89238d5868d7051ba943a4db59903415cc5..56d312f6a580695410404558c3edfa172b1a113b 100644 (file)
@@ -1610,7 +1610,10 @@ int TextMetrics::leftMargin(pit_type const pit, pos_type const pos) const
        LASSERT(pit < int(pars.size()), return 0);
        Paragraph const & par = pars[pit];
        LASSERT(pos >= 0, return 0);
-       LASSERT(pos <= par.size(), 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
+       // margin without indentation (see RowPainter::paintTopLevelLabel).
+
        Buffer const & buffer = bv_->buffer();
        //lyxerr << "TextMetrics::leftMargin: pit: " << pit << " pos: " << pos << endl;
        DocumentClass const & tclass = buffer.params().documentClass();
@@ -1764,8 +1767,8 @@ int TextMetrics::leftMargin(pit_type const pit, pos_type const pos) const
            && !text_->inset().neverIndent()
            // display style insets do not need indentation
            && !(!par.empty()
-                && par.isInset(pos)
-                && par.getInset(pos)->rowFlags() & Inset::Display)
+                && par.isInset(0)
+                && par.getInset(0)->rowFlags() & Inset::Display)
            && (!(tclass.isDefaultLayout(par.layout())
                || tclass.isPlainLayout(par.layout()))
                || buffer.params().paragraph_separation