]> git.lyx.org Git - features.git/commitdiff
Move code responsible to set TextMetrics outer font to InsetText
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 24 Mar 2021 19:25:50 +0000 (20:25 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 24 Mar 2021 19:28:19 +0000 (20:28 +0100)
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.

src/insets/InsetCollapsible.cpp
src/insets/InsetText.cpp
src/insets/InsetText.h

index db679652ac8aa23ce1a02baa7906ad6d58da5591..84bb314f3c667e619149d23e6c2f63ab68faa67f 100644 (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;
 }
 
 
index 2253ed6f0f9f2ac5816a04b305bd43688991fc9c..1867e8c43bf8e12a8928166b819798f27574ea7c 100644 (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).
index 455f19dfbef99dc17bda2a3593e48a7c286ff676..29457aad990ad610185263d2649095b2e4f364df 100644 (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;
        ///