The rewrite of macro_nesting done at
0f15dcc6 was faulty, in
particular since the information should be available also at draw
time. To this end, we revert the patch of the said commit that removes
macro nesting information from MathRow::Element. In the next commit,
we will change the marker code so that MathRow::draw does not need the
nesting information.
Actually the code is now cleaner since the macro nesting stack of
MathRow::metrics can be removed.
-bool InsetMath::addToMathRow(MathRow & mrow, MetricsInfo & ) const
+bool InsetMath::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
- MathRow::Element e(MathRow::INSET, mathClass());
+ MathRow::Element e(mi, MathRow::INSET, mathClass());
e.inset = this;
mrow.push_back(e);
return true;
e.inset = this;
mrow.push_back(e);
return true;
Changer chg = make_change(mi.base.macro_nesting,
mathMacro_->nesting() == 1 ? 0 : mathMacro_->nesting());
Changer chg = make_change(mi.base.macro_nesting,
mathMacro_->nesting() == 1 ? 0 : mathMacro_->nesting());
- MathRow::Element e_beg(MathRow::BEG_ARG);
+ MathRow::Element e_beg(mi, MathRow::BEG_ARG);
e_beg.macro = mathMacro_;
e_beg.ar = &mathMacro_->cell(idx_);
mrow.push_back(e_beg);
e_beg.macro = mathMacro_;
e_beg.ar = &mathMacro_->cell(idx_);
mrow.push_back(e_beg);
// then we insert a box instead.
if (!has_contents && mathMacro_->nesting() == 1) {
// mathclass is ord because it should be spaced as a normal atom
// then we insert a box instead.
if (!has_contents && mathMacro_->nesting() == 1) {
// mathclass is ord because it should be spaced as a normal atom
- MathRow::Element e(MathRow::BOX, MC_ORD);
+ MathRow::Element e(mi, MathRow::BOX, MC_ORD);
e.color = Color_mathline;
mrow.push_back(e);
has_contents = true;
}
e.color = Color_mathline;
mrow.push_back(e);
has_contents = true;
}
- MathRow::Element e_end(MathRow::END_ARG);
+ MathRow::Element e_end(mi, MathRow::END_ARG);
e_end.macro = mathMacro_;
e_end.ar = &mathMacro_->cell(idx_);
e_end.macro = mathMacro_;
e_end.ar = &mathMacro_->cell(idx_);
|| d->editing_[mi.base.bv])
return InsetMath::addToMathRow(mrow, mi);
|| d->editing_[mi.base.bv])
return InsetMath::addToMathRow(mrow, mi);
- MathRow::Element e_beg(MathRow::BEG_MACRO);
+ MathRow::Element e_beg(mi, MathRow::BEG_MACRO);
e_beg.macro = this;
mrow.push_back(e_beg);
e_beg.macro = this;
mrow.push_back(e_beg);
// insert a grey box instead.
if (!has_contents && mi.base.macro_nesting == 1) {
// mathclass is unknown because it is irrelevant for spacing
// insert a grey box instead.
if (!has_contents && mi.base.macro_nesting == 1) {
// mathclass is unknown because it is irrelevant for spacing
- MathRow::Element e(MathRow::BOX);
+ MathRow::Element e(mi, MathRow::BOX);
e.color = Color_mathmacroblend;
mrow.push_back(e);
has_contents = true;
}
e.color = Color_mathmacroblend;
mrow.push_back(e);
has_contents = true;
}
- MathRow::Element e_end(MathRow::END_MACRO);
+ MathRow::Element e_end(mi, MathRow::END_MACRO);
e_end.macro = this;
mrow.push_back(e_end);
e_end.macro = this;
mrow.push_back(e_end);
-MathRow::Element::Element(Type t, MathClass mc)
- : type(t), mclass(mc), before(0), after(0), inset(0),
- compl_unique_to(0), macro(0), color(Color_red)
+MathRow::Element::Element(MetricsInfo const & mi, Type t, MathClass mc)
+ : type(t), mclass(mc), before(0), after(0), macro_nesting(mi.base.macro_nesting),
+ inset(0), compl_unique_to(0), macro(0), color(Color_red)
{}
MathRow::MathRow(MetricsInfo & mi, MathData const * ar)
{
// First there is a dummy element of type "open"
{}
MathRow::MathRow(MetricsInfo & mi, MathData const * ar)
{
// First there is a dummy element of type "open"
- push_back(Element(DUMMY, MC_OPEN));
+ push_back(Element(mi, DUMMY, MC_OPEN));
// Then insert the MathData argument
bool const has_contents = ar->addToMathRow(*this, mi);
// Then insert the MathData argument
bool const has_contents = ar->addToMathRow(*this, mi);
// empty arrays are visible when they are editable
// we reserve the necessary space anyway (even if nothing gets drawn)
if (!has_contents) {
// empty arrays are visible when they are editable
// we reserve the necessary space anyway (even if nothing gets drawn)
if (!has_contents) {
- Element e(BOX, MC_ORD);
+ Element e(mi, BOX, MC_ORD);
e.color = mi.base.macro_nesting == 0 ? Color_mathline : Color_none;
push_back(e);
}
// Finally there is a dummy element of type "close"
e.color = mi.base.macro_nesting == 0 ? Color_mathline : Color_none;
push_back(e);
}
// Finally there is a dummy element of type "close"
- push_back(Element(DUMMY, MC_CLOSE));
+ push_back(Element(mi, DUMMY, MC_CLOSE));
/* Do spacing only in math mode. This test is a bit clumsy,
* but it is used in other places for guessing the current mode.
/* Do spacing only in math mode. This test is a bit clumsy,
* but it is used in other places for guessing the current mode.
// arguments, it is necessary to keep track of them.
map<MathMacro const *, Dimension> dim_macros;
map<MathData const *, Dimension> dim_arrays;
// arguments, it is necessary to keep track of them.
map<MathMacro const *, Dimension> dim_macros;
map<MathData const *, Dimension> dim_arrays;
- // this vector remembers the stack of macro nesting values
- vector<int> macro_nesting;
- macro_nesting.push_back(mi.base.macro_nesting);
CoordCache & coords = mi.base.bv->coordCache();
for (Element const & e : elements_) {
CoordCache & coords = mi.base.bv->coordCache();
for (Element const & e : elements_) {
- mi.base.macro_nesting = macro_nesting.back();
+ mi.base.macro_nesting = e.macro_nesting;
Dimension d;
switch (e.type) {
case DUMMY:
Dimension d;
switch (e.type) {
case DUMMY:
coords.insets().add(e.inset, d);
break;
case BEG_MACRO:
coords.insets().add(e.inset, d);
break;
case BEG_MACRO:
- macro_nesting.push_back(e.macro->nesting());
e.macro->macro()->lock();
// Add a macro to current list
dim_macros[e.macro] = Dimension();
break;
case END_MACRO:
LATTEST(dim_macros.find(e.macro) != dim_macros.end());
e.macro->macro()->lock();
// Add a macro to current list
dim_macros[e.macro] = Dimension();
break;
case END_MACRO:
LATTEST(dim_macros.find(e.macro) != dim_macros.end());
- macro_nesting.pop_back();
e.macro->macro()->unlock();
// Cache the dimension of the macro and remove it from
// tracking map.
e.macro->macro()->unlock();
// Cache the dimension of the macro and remove it from
// tracking map.
break;
// This is basically like macros
case BEG_ARG:
break;
// This is basically like macros
case BEG_ARG:
- if (e.macro) {
- macro_nesting.push_back(e.macro->nesting());
e.macro->macro()->unlock();
e.macro->macro()->unlock();
dim_arrays[e.ar] = Dimension();
break;
case END_ARG:
LATTEST(dim_arrays.find(e.ar) != dim_arrays.end());
dim_arrays[e.ar] = Dimension();
break;
case END_ARG:
LATTEST(dim_arrays.find(e.ar) != dim_arrays.end());
- if (e.macro) {
- macro_nesting.pop_back();
e.macro->macro()->lock();
e.macro->macro()->lock();
coords.arrays().add(e.ar, dim_arrays[e.ar]);
dim_arrays.erase(e.ar);
break;
coords.arrays().add(e.ar, dim_arrays[e.ar]);
dim_arrays.erase(e.ar);
break;
- Element(Type t, MathClass mc = MC_UNKNOWN);
+ Element(MetricsInfo const & mi, Type t, MathClass mc = MC_UNKNOWN);
/// Classifies the contents of the object
Type type;
/// Classifies the contents of the object
Type type;
MathClass mclass;
/// the spacing around the element
int before, after;
MathClass mclass;
/// the spacing around the element
int before, after;
+ /// count wether the current mathdata is nested in macro(s)
+ int macro_nesting;
/// When type is INSET
/// the math inset
/// When type is INSET
/// the math inset