From 824d1c993a138d051c79149fc4b27e1c002736a4 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 5 Jan 2021 14:53:15 +0100 Subject: [PATCH] Fixup 294e4884: center correctly Abstract label when paragraph is empty 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 | 3 +-- src/TextMetrics.cpp | 12 ++++++++---- src/TextMetrics.h | 4 +++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/layouts/stdstruct.inc b/lib/layouts/stdstruct.inc index b611b53da1..a0a9750711 100644 --- a/lib/layouts/stdstruct.inc +++ b/lib/layouts/stdstruct.inc @@ -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 diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 214fe89238..89e8699077 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -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 diff --git a/src/TextMetrics.h b/src/TextMetrics.h index d65618fc0c..0ae802aca5 100644 --- a/src/TextMetrics.h +++ b/src/TextMetrics.h @@ -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; /// -- 2.39.2