Move code responsible to set TextMetrics outer font to InsetText

This code was previously in InsetCollapsible for no good reason.

Move it to a new function InsetText::setOuterFont, which can now be
called for other purposes.

Part of investigation of bug #12204.
This commit is contained in:
Jean-Marc Lasgouttes 2021-03-24 20:25:50 +01:00
parent 56bd50ea6c
commit 06a7731274
3 changed files with 16 additions and 9 deletions

View File

@ -201,10 +201,6 @@ void InsetCollapsible::metrics(MetricsInfo & mi, Dimension & dim) const
{
view_[mi.base.bv].auto_open_ = mi.base.bv->cursor().isInside(this);
FontInfo tmpfont = mi.base.font;
mi.base.font = getFont();
mi.base.font.realize(tmpfont);
BufferView const & bv = *mi.base.bv;
switch (geometry(bv)) {
@ -254,8 +250,6 @@ void InsetCollapsible::metrics(MetricsInfo & mi, Dimension & dim) const
}
break;
}
mi.base.font = tmpfont;
}

View File

@ -184,6 +184,15 @@ void InsetText::read(Lexer & lex)
}
void InsetText::setOuterFont(BufferView & bv, FontInfo const & outer) const
{
TextMetrics & tm = bv.textMetrics(&text_);
FontInfo tmpfont = getFont();
tmpfont.realize(outer);
tm.font_.fontInfo() = tmpfont;
}
void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
{
TextMetrics & tm = mi.base.bv->textMetrics(&text_);
@ -191,11 +200,13 @@ void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
//lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl;
int const horiz_offset = leftOffset(mi.base.bv) + rightOffset(mi.base.bv);
// Hand font through to contained lyxtext:
tm.font_.fontInfo() = mi.base.font;
mi.base.textwidth -= horiz_offset;
// Remember the full outer font
setOuterFont(*mi.base.bv, mi.base.font);
// and use it in these metrics computation.
mi.base.font = tm.font_.fontInfo();
// This can happen when a layout has a left and right margin,
// and the view is made very narrow. We can't do better than
// to draw it partly out of view (bug 5890).

View File

@ -54,6 +54,8 @@ public:
void read(Lexer & lex) override;
///
void write(std::ostream & os) const override;
/// Let the inset compute and store its reference font from \c outer.
void setOuterFont(BufferView & bv, FontInfo const & outer) const;
///
void metrics(MetricsInfo & mi, Dimension & dim) const override;
///