From: Jean-Marc Lasgouttes Date: Wed, 24 Mar 2021 19:25:50 +0000 (+0100) Subject: Move code responsible to set TextMetrics outer font to InsetText X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=06a77312749f679b0c81a8a4b7277c17bd684262;p=features.git 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. --- diff --git a/src/insets/InsetCollapsible.cpp b/src/insets/InsetCollapsible.cpp index db679652ac..84bb314f3c 100644 --- a/src/insets/InsetCollapsible.cpp +++ b/src/insets/InsetCollapsible.cpp @@ -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; } diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 2253ed6f0f..1867e8c43b 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -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). diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index 455f19dfbe..29457aad99 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -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; ///