InsetMath: match the screen display with the EnsureMath behaviour in output

This commit is contained in:
Guillaume Munch 2016-11-22 11:26:15 +01:00
parent b5af229208
commit eadc55b8b3
30 changed files with 85 additions and 12 deletions

View File

@ -77,6 +77,15 @@ Changer MetricsBase::changeFontSet(string const & name)
}
Changer MetricsBase::changeEnsureMath()
{
// FIXME:
// \textit{\ensuremath{\text{a}}}
// should appear in italics
return isTextFont(fontname) ? changeFontSet("mathnormal") : Changer();
}
/////////////////////////////////////////////////////////////////////////
//
// MetricsInfo

View File

@ -54,6 +54,8 @@ public:
/// Temporarily change a full font.
Changer changeFontSet(std::string const & font);
/// Temporarily change the font to math if needed.
Changer changeEnsureMath();
// Temporarily change to the style suitable for use in fractions
Changer changeFrac();
// Temporarily change to the style suitable for use in arrays

View File

@ -85,6 +85,7 @@ char const * InsetMathAMSArray::name_right() const
void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy2 = mi.base.changeEnsureMath();
Changer dummy = mi.base.changeArray();
InsetMathGrid::metrics(mi, dim);
}
@ -92,6 +93,7 @@ void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy2 = pi.base.changeEnsureMath();
Dimension const dim = dimension(*pi.base.bv);
int const yy = y - dim.ascent();
// Drawing the deco after changeStyle does not work

View File

@ -74,6 +74,7 @@ Inset * InsetMathArray::clone() const
void InsetMathArray::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy2 = mi.base.changeEnsureMath();
Changer dummy = mi.base.changeArray();
InsetMathGrid::metrics(mi, dim);
}
@ -82,6 +83,7 @@ void InsetMathArray::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathArray::draw(PainterInfo & pi, int x, int y) const
{
setPosCache(pi, x, y);
Changer dummy2 = pi.base.changeEnsureMath();
Changer dummy = pi.base.changeArray();
InsetMathGrid::draw(pi, x, y);
}

View File

@ -69,6 +69,7 @@ double InsetMathBig::increase() const
void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy = mi.base.changeEnsureMath();
double const h = theFontMetrics(mi.base.font).ascent('I');
double const f = increase();
dim.wid = 6;
@ -79,6 +80,7 @@ void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy = pi.base.changeEnsureMath();
Dimension const dim = dimension(*pi.base.bv);
// mathed_draw_deco does not use the leading backslash, so remove it
// (but don't use ltrim if this is the backslash delimiter).

View File

@ -14,6 +14,7 @@
#include "MathStream.h"
#include "MathData.h"
#include "MetricsInfo.h"
#include "LaTeXFeatures.h"
#include <ostream>
@ -49,6 +50,7 @@ docstring InsetMathBoldSymbol::name() const
void InsetMathBoldSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy = mi.base.changeEnsureMath();
//Changer dummy = mi.base.changeFontSet("mathbf");
cell(0).metrics(mi, dim);
metricsMarkers(mi, dim);
@ -58,6 +60,7 @@ void InsetMathBoldSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathBoldSymbol::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy = pi.base.changeEnsureMath();
//Changer dummy = pi.base.changeFontSet("mathbf");
cell(0).draw(pi, x + 1, y);
cell(0).draw(pi, x + 2, y);

View File

@ -37,6 +37,7 @@ Inset * InsetMathCancel::clone() const
void InsetMathCancel::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy = mi.base.changeEnsureMath();
cell(0).metrics(mi, dim);
metricsMarkers(mi, dim);
}
@ -44,6 +45,7 @@ void InsetMathCancel::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathCancel::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy = pi.base.changeEnsureMath();
// We first draw the text and then an arrow
ColorCode const origcol = pi.base.font.color();
cell(0).draw(pi, x + 1, y);

View File

@ -41,6 +41,7 @@ Inset * InsetMathCancelto::clone() const
void InsetMathCancelto::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy = mi.base.changeEnsureMath();
InsetMathNest::metrics(mi);
Dimension const & dim0 = cell(0).dimension(*mi.base.bv);
Dimension const & dim1 = cell(1).dimension(*mi.base.bv);
@ -53,6 +54,7 @@ void InsetMathCancelto::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathCancelto::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy = pi.base.changeEnsureMath();
ColorCode const origcol = pi.base.font.color();
// We first draw the text and then an arrow

View File

@ -45,12 +45,14 @@ Inset * InsetMathCases::clone() const
void InsetMathCases::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy = mi.base.changeEnsureMath();
InsetMathGrid::metrics(mi, dim);
}
void InsetMathCases::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy = pi.base.changeEnsureMath();
Dimension const dim = dimension(*pi.base.bv);
mathed_draw_deco(pi, x + 1, y - dim.ascent(), 6, dim.height(), from_ascii("{"));
InsetMathGrid::draw(pi, x, y);

View File

@ -105,9 +105,9 @@ InsetMath::mode_type InsetMathDecoration::currentMode() const
void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
{
bool really_change_font = currentMode() == TEXT_MODE
&& isMathFont(mi.base.fontname);
Changer dummy = really_change_font ? mi.base.changeFontSet("textnormal")
Changer dummy =
(currentMode() == MATH_MODE) ? mi.base.changeEnsureMath() :
(isMathFont(mi.base.fontname)) ? mi.base.changeFontSet("textnormal")
: Changer();
cell(0).metrics(mi, dim);
@ -129,9 +129,9 @@ void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
{
bool really_change_font = currentMode() == TEXT_MODE
&& isMathFont(pi.base.fontname);
Changer dummy = really_change_font ? pi.base.changeFontSet("textnormal")
Changer dummy =
(currentMode() == MATH_MODE) ? pi.base.changeEnsureMath() :
(isMathFont(pi.base.fontname)) ? pi.base.changeFontSet("textnormal")
: Changer();
cell(0).draw(pi, x + 1, y);

View File

@ -104,6 +104,7 @@ void InsetMathDelim::normalize(NormalStream & os) const
void InsetMathDelim::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy = mi.base.changeEnsureMath();
Dimension dim0;
cell(0).metrics(mi, dim0);
Dimension t = theFontMetrics(mi.base.font).dimension('I');
@ -123,6 +124,7 @@ void InsetMathDelim::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathDelim::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy = pi.base.changeEnsureMath();
Dimension const dim = dimension(*pi.base.bv);
int const b = y - dim.asc;
cell(0).draw(pi, x + dw_, y);

View File

@ -48,6 +48,7 @@ int InsetMathDiagram::rowsep() const
void InsetMathDiagram::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy2 = mi.base.changeEnsureMath();
FontInfo & f = mi.base.font;
Changer dummy = (f.style() == LM_ST_DISPLAY) ? f.changeStyle(LM_ST_TEXT)
: Changer();
@ -58,6 +59,7 @@ void InsetMathDiagram::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathDiagram::draw(PainterInfo & pi, int x, int y) const
{
setPosCache(pi, x, y);
Changer dummy2 = pi.base.changeEnsureMath();
FontInfo & f = pi.base.font;
Changer dummy = (f.style() == LM_ST_DISPLAY) ? f.changeStyle(LM_ST_TEXT)
: Changer();

View File

@ -38,9 +38,7 @@ Inset * InsetMathEnsureMath::clone() const
void InsetMathEnsureMath::metrics(MetricsInfo & mi, Dimension & dim) const
{
bool really_change_font = isTextFont(mi.base.fontname);
Changer dummy = really_change_font ? mi.base.changeFontSet("mathnormal")
: Changer();
Changer dummy = mi.base.changeEnsureMath();
cell(0).metrics(mi, dim);
metricsMarkers(mi, dim);
}
@ -48,9 +46,7 @@ void InsetMathEnsureMath::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathEnsureMath::draw(PainterInfo & pi, int x, int y) const
{
bool really_change_font = isTextFont(pi.base.fontname);
Changer dummy = really_change_font ? pi.base.changeFontSet("mathnormal")
: Changer();
Changer dummy = pi.base.changeEnsureMath();
cell(0).draw(pi, x, y);
drawMarkers(pi, x, y);
}

View File

@ -16,6 +16,8 @@
#include "MathStream.h"
#include "MathStream.h"
#include "MetricsInfo.h"
#include "support/gettext.h"
#include "support/lstrings.h"
@ -38,6 +40,7 @@ Inset * InsetMathEnv::clone() const
void InsetMathEnv::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy = mi.base.changeEnsureMath();
cell(0).metrics(mi, dim);
metricsMarkers(mi, dim);
}
@ -45,6 +48,7 @@ void InsetMathEnv::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathEnv::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy = pi.base.changeEnsureMath();
cell(0).draw(pi, x + 1, y);
drawMarkers(pi, x, y);
}

View File

@ -186,6 +186,7 @@ latexkeys const * slash_symbol()
void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const
{
Dimension dim0, dim1, dim2;
Changer dummy3 = mi.base.changeEnsureMath();
switch (kind_) {
case UNIT: {
@ -259,6 +260,7 @@ void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const
|| kind_ == DFRAC) ? mi.base.font.changeStyle(LM_ST_DISPLAY) :
// all others
mi.base.changeFrac();
Changer dummy2 = mi.base.changeEnsureMath();
cell(0).metrics(mi, dim0);
cell(1).metrics(mi, dim1);
dim.wid = max(dim0.wid, dim1.wid) + 2;
@ -274,6 +276,7 @@ void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const
{
setPosCache(pi, x, y);
Changer dummy3 = pi.base.changeEnsureMath();
Dimension const dim = dimension(*pi.base.bv);
Dimension const dim0 = cell(0).dimension(*pi.base.bv);
switch (kind_) {
@ -654,6 +657,7 @@ int InsetMathBinom::dw(int height) const
void InsetMathBinom::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy2 = mi.base.changeEnsureMath();
Dimension dim0, dim1;
int const dy = dy_for_frac(mi.base);
Changer dummy =
@ -671,6 +675,7 @@ void InsetMathBinom::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy2 = pi.base.changeEnsureMath();
Dimension const dim = dimension(*pi.base.bv);
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
Dimension const & dim1 = cell(1).dimension(*pi.base.bv);

View File

@ -31,6 +31,7 @@ Inset * InsetMathOverset::clone() const
void InsetMathOverset::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy2 = mi.base.changeEnsureMath();
Dimension dim1;
cell(1).metrics(mi, dim1);
Changer dummy = mi.base.changeFrac();
@ -45,6 +46,7 @@ void InsetMathOverset::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathOverset::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy2 = pi.base.changeEnsureMath();
Dimension const dim = dimension(*pi.base.bv);
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
Dimension const & dim1 = cell(1).dimension(*pi.base.bv);

View File

@ -38,6 +38,7 @@ Inset * InsetMathPhantom::clone() const
void InsetMathPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy = mi.base.changeEnsureMath();
cell(0).metrics(mi, dim);
metricsMarkers(mi, dim);
}
@ -45,6 +46,7 @@ void InsetMathPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy = pi.base.changeEnsureMath();
static int const arrow_size = 4;
// We first draw the text and then an arrow

View File

@ -41,6 +41,7 @@ Inset * InsetMathRoot::clone() const
void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy = mi.base.changeEnsureMath();
InsetMathNest::metrics(mi);
Dimension const & dim0 = cell(0).dimension(*mi.base.bv);
Dimension const & dim1 = cell(1).dimension(*mi.base.bv);
@ -53,6 +54,7 @@ void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathRoot::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy = pi.base.changeEnsureMath();
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
int const w = dim0.width();
// the "exponent"

View File

@ -288,6 +288,7 @@ MathClass InsetMathScript::mathClass() const
void InsetMathScript::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy2 = mi.base.changeEnsureMath();
Dimension dim0;
Dimension dim1;
Dimension dim2;
@ -339,6 +340,7 @@ void InsetMathScript::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathScript::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy2 = pi.base.changeEnsureMath();
BufferView & bv = *pi.base.bv;
if (!nuc().empty())
nuc().draw(pi, x + dxx(bv), y);

View File

@ -185,6 +185,7 @@ int InsetMathSideset::nker(BufferView const * bv) const
void InsetMathSideset::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy2 = mi.base.changeEnsureMath();
Dimension dimn;
Dimension dimbl;
Dimension dimtl;
@ -227,6 +228,7 @@ void InsetMathSideset::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathSideset::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy2 = pi.base.changeEnsureMath();
BufferView & bv = *pi.base.bv;
nuc().draw(pi, x + dxn(bv), y);
if (!scriptl_)

View File

@ -44,6 +44,7 @@ Inset * InsetMathSize::clone() const
void InsetMathSize::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy2 = mi.base.changeEnsureMath();
Changer dummy = mi.base.font.changeStyle(style_);
cell(0).metrics(mi, dim);
metricsMarkers(mi, dim);
@ -52,6 +53,7 @@ void InsetMathSize::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathSize::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy2 = pi.base.changeEnsureMath();
Changer dummy = pi.base.font.changeStyle(style_);
cell(0).draw(pi, x + 1, y);
drawMarkers(pi, x, y);

View File

@ -121,6 +121,7 @@ Inset * InsetMathSpace::clone() const
void InsetMathSpace::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy = mi.base.changeEnsureMath();
dim.asc = 4;
dim.des = 0;
if (space_info[space_].custom)
@ -132,6 +133,7 @@ void InsetMathSpace::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathSpace::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy = pi.base.changeEnsureMath();
// Sadly, HP-UX CC can't handle that kind of initialization.
// XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
if (!space_info[space_].visible)

View File

@ -20,6 +20,7 @@
#include "FuncStatus.h"
#include "support/gettext.h"
#include "LaTeXFeatures.h"
#include "MetricsInfo.h"
#include "support/lstrings.h"
@ -93,8 +94,17 @@ int InsetMathSplit::displayColSpace(col_type col) const
void InsetMathSplit::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy = mi.base.changeEnsureMath();
InsetMathGrid::metrics(mi, dim);
}
void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy = pi.base.changeEnsureMath();
InsetMathGrid::draw(pi, x, y);
setPosCache(pi, x, y);
}

View File

@ -24,6 +24,8 @@ public:
explicit InsetMathSplit(Buffer * buf, docstring const & name,
char valign = 'c', bool numbered = false);
///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
void draw(PainterInfo & pi, int x, int y) const;
///
bool getStatus(Cursor & cur, FuncRequest const & cmd,

View File

@ -37,6 +37,7 @@ Inset * InsetMathSqrt::clone() const
void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy = mi.base.changeEnsureMath();
cell(0).metrics(mi, dim);
dim.asc += 4;
dim.des += 2;
@ -47,6 +48,7 @@ void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathSqrt::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy = pi.base.changeEnsureMath();
cell(0).draw(pi, x + 10, y);
Dimension const dim = dimension(*pi.base.bv);
int const a = dim.ascent();

View File

@ -61,6 +61,7 @@ MathClass InsetMathStackrel::mathClass() const
void InsetMathStackrel::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy2 = mi.base.changeEnsureMath();
Dimension dim1;
cell(1).metrics(mi, dim1);
Changer dummy = mi.base.changeFrac();
@ -83,6 +84,7 @@ void InsetMathStackrel::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathStackrel::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy2 = pi.base.changeEnsureMath();
Dimension const dim = dimension(*pi.base.bv);
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
Dimension const & dim1 = cell(1).dimension(*pi.base.bv);

View File

@ -45,6 +45,7 @@ Inset * InsetMathSubstack::clone() const
void InsetMathSubstack::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy2 = mi.base.changeEnsureMath();
Changer dummy = mi.base.changeArray();
InsetMathGrid::metrics(mi, dim);
}
@ -52,6 +53,7 @@ void InsetMathSubstack::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathSubstack::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy2 = pi.base.changeEnsureMath();
Changer dummy = pi.base.changeArray();
InsetMathGrid::draw(pi, x + 1, y);
}

View File

@ -32,6 +32,7 @@ Inset * InsetMathUnderset::clone() const
void InsetMathUnderset::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy2 = mi.base.changeEnsureMath();
Dimension dim1;
cell(1).metrics(mi, dim1);
Changer dummy = mi.base.changeFrac();
@ -46,6 +47,7 @@ void InsetMathUnderset::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathUnderset::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy2 = pi.base.changeEnsureMath();
Dimension const dim = dimension(*pi.base.bv);
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
Dimension const & dim1 = cell(1).dimension(*pi.base.bv);

View File

@ -43,6 +43,7 @@ Inset * InsetMathXArrow::clone() const
void InsetMathXArrow::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy2 = mi.base.changeEnsureMath();
Changer dummy = mi.base.changeScript();
Dimension dim0;
cell(0).metrics(mi, dim0);
@ -57,6 +58,7 @@ void InsetMathXArrow::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathXArrow::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy2 = pi.base.changeEnsureMath();
Changer dummy = pi.base.changeScript();
Dimension const dim = dimension(*pi.base.bv);
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);

View File

@ -49,6 +49,7 @@ int InsetMathXYMatrix::rowsep() const
void InsetMathXYMatrix::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy2 = mi.base.changeEnsureMath();
Changer dummy = mi.base.changeArray();
InsetMathGrid::metrics(mi, dim);
}
@ -57,6 +58,7 @@ void InsetMathXYMatrix::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathXYMatrix::draw(PainterInfo & pi, int x, int y) const
{
setPosCache(pi, x, y);
Changer dummy2 = pi.base.changeEnsureMath();
Changer dummy = pi.base.changeArray();
InsetMathGrid::draw(pi, x, y);
}