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.
This commit is contained in:
Guillaume Munch 2016-12-12 01:17:41 +01:00
parent 2de30c62f8
commit e35fda62a7
4 changed files with 18 additions and 22 deletions

View File

@ -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();
}

View File

@ -20,6 +20,8 @@
#include "support/strfwd.h"
#include "support/Changer.h"
#include "insets/Inset.h"
#include <string>
@ -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

View File

@ -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);

View File

@ -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)