[LyX/master] Move code responsible to set TextMetrics outer font to InsetText
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Wed Mar 24 19:22:33 UTC 2021
commit 06a77312749f679b0c81a8a4b7277c17bd684262
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date: Wed Mar 24 20:25:50 2021 +0100
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.
---
src/insets/InsetCollapsible.cpp | 6 ------
src/insets/InsetText.cpp | 17 ++++++++++++++---
src/insets/InsetText.h | 2 ++
3 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/src/insets/InsetCollapsible.cpp b/src/insets/InsetCollapsible.cpp
index db67965..84bb314 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 2253ed6..1867e8c 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 455f19d..29457aa 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;
///
More information about the lyx-cvs
mailing list