From e35fda62a7f69e3278a2df5cfa4ec9fa103c5c65 Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Mon, 12 Dec 2016 01:17:41 +0100 Subject: [PATCH] Some code factoring for changing mode. About removing the changeEnsureMath in MathMacro::{metrics,draw} : as it is only called in edition mode, it only happened for user macros for which no ensureMath is needed anyway. ChangeEnsureMath should indeed be applied for global macros, but since they are linearized there is no obvious place to call it. --- src/MetricsInfo.cpp | 18 +++++++++++++----- src/MetricsInfo.h | 5 +++-- src/mathed/InsetMathDecoration.cpp | 10 ++-------- src/mathed/MathMacro.cpp | 7 ------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/MetricsInfo.cpp b/src/MetricsInfo.cpp index ef9803d831..b2f9974504 100644 --- a/src/MetricsInfo.cpp +++ b/src/MetricsInfo.cpp @@ -77,12 +77,20 @@ Changer MetricsBase::changeFontSet(string const & name) } -Changer MetricsBase::changeEnsureMath() +Changer MetricsBase::changeEnsureMath(Inset::mode_type mode) { - // FIXME: - // \textit{\ensuremath{\text{a}}} - // should appear in italics - return isTextFont(fontname) ? changeFontSet("mathnormal") : Changer(); + switch (mode) { + case Inset::UNDECIDED_MODE: + return Changer(); + case Inset::TEXT_MODE: + return isMathFont(fontname) ? changeFontSet("textnormal") : Changer(); + case Inset::MATH_MODE: + // FIXME: + // \textit{\ensuremath{\text{a}}} + // should appear in italics + return isTextFont(fontname) ? changeFontSet("mathnormal"): Changer(); + } + return Changer(); } diff --git a/src/MetricsInfo.h b/src/MetricsInfo.h index 1dbeae249a..7534a8e7ca 100644 --- a/src/MetricsInfo.h +++ b/src/MetricsInfo.h @@ -20,6 +20,8 @@ #include "support/strfwd.h" #include "support/Changer.h" +#include "insets/Inset.h" + #include @@ -28,7 +30,6 @@ namespace lyx { namespace frontend { class Painter; } class BufferView; -class Inset; class MacroContext; @@ -55,7 +56,7 @@ public: /// Temporarily change a full font. Changer changeFontSet(std::string const & font); /// Temporarily change the font to math if needed. - Changer changeEnsureMath(); + Changer changeEnsureMath(Inset::mode_type mode = Inset::MATH_MODE); // Temporarily change to the style suitable for use in fractions Changer changeFrac(); // Temporarily change to the style suitable for use in arrays diff --git a/src/mathed/InsetMathDecoration.cpp b/src/mathed/InsetMathDecoration.cpp index f7fd6ea2aa..e4cb25a1c3 100644 --- a/src/mathed/InsetMathDecoration.cpp +++ b/src/mathed/InsetMathDecoration.cpp @@ -105,10 +105,7 @@ InsetMath::mode_type InsetMathDecoration::currentMode() const void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const { - Changer dummy = - (currentMode() == MATH_MODE) ? mi.base.changeEnsureMath() : - (isMathFont(mi.base.fontname)) ? mi.base.changeFontSet("textnormal") - : Changer(); + Changer dummy = mi.base.changeEnsureMath(currentMode()); cell(0).metrics(mi, dim); @@ -129,10 +126,7 @@ void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const { - Changer dummy = - (currentMode() == MATH_MODE) ? pi.base.changeEnsureMath() : - (isMathFont(pi.base.fontname)) ? pi.base.changeFontSet("textnormal") - : Changer(); + Changer dummy = pi.base.changeEnsureMath(currentMode()); cell(0).draw(pi, x + 1, y); Dimension const & dim0 = cell(0).dimension(*pi.base.bv); diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp index 6a5c904df7..7862962bfe 100644 --- a/src/mathed/MathMacro.cpp +++ b/src/mathed/MathMacro.cpp @@ -484,10 +484,6 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const } else { LBUFERR(d->macro_); - Changer dummy = (currentMode() == TEXT_MODE) - ? mi.base.font.changeShape(UP_SHAPE) - : Changer(); - // calculate metrics, hoping that all cells are seen d->macro_->lock(); d->expanded_.metrics(mi, dim); @@ -690,9 +686,6 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const drawMarkers2(pi, expx, expy); } else { bool drawBox = lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_INLINE_BOX; - Changer dummy = (currentMode() == TEXT_MODE) - ? pi.base.font.changeShape(UP_SHAPE) - : Changer(); // warm up cells for (size_t i = 0; i < nargs(); ++i) -- 2.39.5