Put end label on own row after display inset

This corresponds to what is done on display. The same should be done
for start label too (e.g. beginning of a proof), but this requires more
work.

This required to move the static function getEndLabel to Text.

Fixes bug #11536.
This commit is contained in:
Jean-Marc Lasgouttes 2019-04-03 11:06:43 +02:00
parent caf9db6936
commit 283ac91aa7
4 changed files with 41 additions and 36 deletions

View File

@ -472,41 +472,9 @@ void RowPainter::paintTopLevelLabel() const
}
/** Check if the current paragraph is the last paragraph in a
proof environment */
static int getEndLabel(pit_type p, Text const & text)
{
ParagraphList const & pars = text.paragraphs();
pit_type pit = p;
depth_type par_depth = pars[p].getDepth();
while (pit != pit_type(pars.size())) {
Layout const & layout = pars[pit].layout();
int const endlabeltype = layout.endlabeltype;
if (endlabeltype != END_LABEL_NO_LABEL) {
if (p + 1 == pit_type(pars.size()))
return endlabeltype;
depth_type const next_depth =
pars[p + 1].getDepth();
if (par_depth > next_depth ||
(par_depth == next_depth && layout != pars[p + 1].layout()))
return endlabeltype;
break;
}
if (par_depth == 0)
break;
pit = text.outerHook(pit);
if (pit != pit_type(pars.size()))
par_depth = pars[pit].getDepth();
}
return END_LABEL_NO_LABEL;
}
void RowPainter::paintLast() const
{
int const endlabel = getEndLabel(row_.pit(), text_);
int const endlabel = text_.getEndLabel(row_.pit());
switch (endlabel) {
case END_LABEL_BOX:
case END_LABEL_FILLED_BOX: {

View File

@ -288,6 +288,35 @@ Font const Text::outerFont(pit_type par_offset) const
}
int Text::getEndLabel(pit_type p) const
{
pit_type pit = p;
depth_type par_depth = pars_[p].getDepth();
while (pit != pit_type(pars_.size())) {
Layout const & layout = pars_[pit].layout();
int const endlabeltype = layout.endlabeltype;
if (endlabeltype != END_LABEL_NO_LABEL) {
if (p + 1 == pit_type(pars_.size()))
return endlabeltype;
depth_type const next_depth =
pars_[p + 1].getDepth();
if (par_depth > next_depth ||
(par_depth == next_depth && layout != pars_[p + 1].layout()))
return endlabeltype;
break;
}
if (par_depth == 0)
break;
pit = outerHook(pit);
if (pit != pit_type(pars_.size()))
par_depth = pars_[pit].getDepth();
}
return END_LABEL_NO_LABEL;
}
static void acceptOrRejectChanges(ParagraphList & pars,
BufferParams const & bparams, Text::ChangeOp op)
{

View File

@ -345,6 +345,8 @@ public:
/// Get the font of the "environment" of paragraph \p par_offset in \p pars.
/// All font changes of the paragraph are relative to this font.
Font const outerFont(pit_type pit_offset) const;
/// Return the label type at the end of paragraph \c pit.
int getEndLabel(pit_type pit) const;
private:
/// The InsetText owner shall have access to everything.

View File

@ -983,11 +983,17 @@ bool TextMetrics::breakRow(Row & row, int const right_margin) const
Inset const * inset = 0;
if (par.isNewline(i) || par.isEnvSeparator(i)
|| (i + 1 < end && (inset = par.getInset(i + 1))
&& inset->display())
&& inset->display())
|| (!row.empty() && row.back().inset
&& row.back().inset->display())) {
&& row.back().inset->display())) {
row.flushed(true);
need_new_row = par.isNewline(i);
// We will force a row creation after either
// - a newline;
// - a display inset followed by a end label.
need_new_row =
par.isNewline(i)
|| (inset->display() && i + 1 == end
&& text_->getEndLabel(row.pit()) != END_LABEL_NO_LABEL);
++i;
break;
}