]> git.lyx.org Git - features.git/commitdiff
Fixup 294e4884: center correctly Abstract label when paragraph is empty
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 14:21:04 +0000 (15:21 +0100)
When a paragraph is empty, it was not possible to query what the left
margin would be for an hypothetical second row.

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/TextMetrics.cpp
src/TextMetrics.h

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 214fe89238d5868d7051ba943a4db59903415cc5..89e8699077734a3f66a7da24428354290b55b302 100644 (file)
@@ -1598,7 +1598,8 @@ void TextMetrics::deleteLineForward(Cursor & cur)
 
 int TextMetrics::leftMargin(pit_type pit) const
 {
-       return leftMargin(pit, text_->paragraphs()[pit].size());
+       // the + 1 is useful when the paragraph is empty
+       return leftMargin(pit, text_->paragraphs()[pit].size() + 1);
 }
 
 
@@ -1610,7 +1611,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 leftMargin(pit_type).
+
        Buffer const & buffer = bv_->buffer();
        //lyxerr << "TextMetrics::leftMargin: pit: " << pit << " pos: " << pos << endl;
        DocumentClass const & tclass = buffer.params().documentClass();
@@ -1764,8 +1768,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
index d65618fc0cbf5401dc1d0a183079fc61738ba401..0ae802aca5f11392edeaa1f4302c9b6b44e727be 100644 (file)
@@ -123,12 +123,14 @@ public:
        int height() const { return dim_.height(); }
 
        /**
-        * Returns the left beginning of the text.
+        * Returns the left beginning of a row starting at \c pos.
         * 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;
+       /// Return the left beginning of a row which is not the first one.
+       /// This is the left margin when there is no indentation.
        int leftMargin(pit_type pit) const;
 
        ///