]> git.lyx.org Git - features.git/commitdiff
Inherit outer font in text-in-math environments
authorEnrico Forestieri <forenr@lyx.org>
Thu, 2 Nov 2023 16:54:02 +0000 (17:54 +0100)
committerEnrico Forestieri <forenr@lyx.org>
Thu, 2 Nov 2023 16:54:02 +0000 (17:54 +0100)
Some text-in-math environments such as \text, \mbox, \fbox, and
\makebox, inherit the outer text font. This commit reflects this
in the on-screen representation.

Fixes #12950.

src/MetricsInfo.cpp
src/MetricsInfo.h
src/RowPainter.cpp
src/TextMetrics.cpp
src/mathed/InsetMathBox.cpp

index 8fe03ba441fbf4f8ae303b64168948def0fad6a8..ab55bb524d3f93d5e4b9f528188bb68ae82803ed 100644 (file)
@@ -61,7 +61,7 @@ Changer MetricsBase::changeFontSet(string const & name)
        string const oldname = fontname;
        fontname = name;
        if (isMathFont(name) || isMathFont(oldname))
-               font = sane_font;
+               font = isTextFont(name) ? outer_font : sane_font;
        augmentFont(font, name);
        font.setSize(rc->old.font.size());
        font.setStyle(rc->old.font.style());
index 09c5b6331b466849650ea029f9958ef079cfce17..29000034db6d1b1ec09fc298f4a26702dd238b82 100644 (file)
@@ -47,6 +47,8 @@ public:
        BufferView * bv;
        /// current font
        FontInfo font;
+       /// font of the containing inset
+       FontInfo outer_font;
        /// name of current font - mathed specific
        std::string fontname;
        /// This is the width available in pixels
index 6798d917ecc7b9d6acf6482d37bb2c78c3162127..d893fd01eb7736e6a99e4aa17e540efbb5cbcace 100644 (file)
@@ -104,6 +104,7 @@ void RowPainter::paintInset(Row::Element const & e) const
 
        pi_.base.font = e.inset->inheritFont() ? e.font.fontInfo() :
                pi_.base.bv->buffer().params().getFont().fontInfo();
+       pi_.base.outer_font = e.font.fontInfo();
        pi_.ltr_pos = !e.font.isVisibleRightToLeft();
        pi_.change = pi_.change.changed() ? pi_.change : e.change;
        pi_.do_spellcheck &= e.inset->allowSpellCheck();
index eb99de066b5f24beb60f8adf77fe3ef1692731ce..ba05519c677081cd0e818f7a1ac7915e15b847e6 100644 (file)
@@ -520,6 +520,7 @@ bool TextMetrics::redoParagraph(pit_type const pit, bool const align_rows)
                        displayFont(pit, e.pos) : bufferfont;
                MacroContext mc(&buffer, parPos);
                MetricsInfo mi(bv_, font.fontInfo(), w, mc, e.pos == 0, tight_);
+               mi.base.outer_font = displayFont(pit, e.pos).fontInfo();
                e.inset->metrics(mi, dim);
                /* FIXME: This is a kind of hack. This allows InsetMathHull to
                 * state that it needs some elbow room beyond its width, in
index afaadeb83a403094badf094b7098e1c76a36c033..6feddf9cdd269578707d04e6decd145550cb2b94 100644 (file)
@@ -146,14 +146,14 @@ void InsetMathBox::htmlize(HtmlStream & ms) const
 
 void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       Changer dummy = mi.base.changeFontSet("textnormal");
+       Changer dummy = mi.base.changeFontSet("text");
        cell(0).metrics(mi, dim);
 }
 
 
 void InsetMathBox::draw(PainterInfo & pi, int x, int y) const
 {
-       Changer dummy = pi.base.changeFontSet("textnormal");
+       Changer dummy = pi.base.changeFontSet("text");
        cell(0).draw(pi, x, y);
 }
 
@@ -196,7 +196,7 @@ InsetMathFBox::InsetMathFBox(Buffer * buf)
 
 void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       Changer dummy = mi.base.changeFontSet("textnormal");
+       Changer dummy = mi.base.changeFontSet("text");
        cell(0).metrics(mi, dim);
        // 1 pixel space, 1 frame, 1 space
        dim.wid += 2 * 3;
@@ -210,7 +210,7 @@ void InsetMathFBox::draw(PainterInfo & pi, int x, int y) const
        Dimension const dim = dimension(*pi.base.bv);
        pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
                dim.width() - 2, dim.height() - 2, Color_foreground);
-       Changer dummy = pi.base.changeFontSet("textnormal");
+       Changer dummy = pi.base.changeFontSet("text");
        cell(0).draw(pi, x + 3, y);
 }
 
@@ -281,7 +281,7 @@ InsetMathMakebox::InsetMathMakebox(Buffer * buf, bool framebox)
 
 void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
 {
-       Changer dummy = mi.base.changeFontSet("textnormal");
+       Changer dummy = mi.base.changeFontSet("text");
 
        Dimension wdim;
        static docstring bracket = from_ascii("[");
@@ -312,7 +312,7 @@ void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
 {
-       Changer dummy = pi.base.changeFontSet("textnormal");
+       Changer dummy = pi.base.changeFontSet("text");
        BufferView const & bv = *pi.base.bv;
        int w = mathed_char_width(pi.base.font, '[');