+#include <config.h>
+
#ifdef __GNUG__
#pragma implementation
#endif
-#include <vector>
-
#include "math_hullinset.h"
+#include "math_mathmlstream.h"
+#include "math_streamstr.h"
#include "math_support.h"
#include "debug.h"
#include "Painter.h"
+#include "textpainter.h"
+#include "Lsstream.h"
#include "LaTeXFeatures.h"
-#include "math_mathmlstream.h"
+#include "support/LAssert.h"
+#include <vector>
+
+using std::vector;
+using std::max;
+using std::endl;
namespace {
// returns position of first relation operator in the array
// used for "intelligent splitting"
- int firstRelOp(MathArray const & ar)
+ MathArray::size_type firstRelOp(MathArray const & ar)
{
for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
if ((*it)->isRelOp())
if (s == "multline") return LM_OT_MULTLINE;
if (s == "gather") return LM_OT_GATHER;
return LM_OT_SIMPLE;
- }
+ }
string normalName(MathInsetTypes t)
default: break;
}
return "unknown";
- }
+ }
} // end anon namespace
}
+MathHullInset::MathHullInset(MathInsetTypes t, MathGridInset const & grid)
+ : MathGridInset(grid), objtype_(t), nonum_(1), label_(1)
+{
+ setDefaults();
+}
+
+
MathHullInset::MathHullInset(MathInsetTypes t, col_type cols)
: MathGridInset(cols, 1), objtype_(t), nonum_(1), label_(1)
{
return (col & 1) ? 40 : 0;
default:;
}
- return 10;
+ return 0;
}
if (display()) {
ascent_ += 12;
descent_ += 12;
- }
+ }
if (numberedType()) {
+ whichFont(mi_.font, LM_TC_BF, mi_);
int l = 0;
for (row_type row = 0; row < nrows(); ++row)
- l = std::max(l, mathed_string_width(LM_TC_BF, mi_, nicelabel(row)));
+ l = max(l, mathed_string_width(mi_.font, nicelabel(row)));
if (l)
width_ += 30 + l;
// make it at least as high as the current font
int asc = 0;
int des = 0;
- math_font_max_dim(LM_TC_TEXTRM, mi_, asc, des);
- ascent_ = std::max(ascent_, asc);
- descent_ = std::max(descent_, des);
+ math_font_max_dim(mi_.font, asc, des);
+ ascent_ = max(ascent_, asc);
+ descent_ = max(descent_, des);
}
int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
for (row_type row = 0; row < nrows(); ++row) {
int const yy = y + rowinfo_[row].offset_;
- drawStr(pain, LM_TC_BF, mi_, xx, yy, nicelabel(row));
+ drawStr(pain, mi_.font, xx, yy, nicelabel(row));
}
}
}
+void MathHullInset::metricsT(TextMetricsInfo const &) const
+{
+#if 0
+ if (display()) {
+ MathGridInset::metricsT(mi);
+ } else
+#endif
+ {
+ ostringstream os;
+ WriteStream wi(os, false, true);
+ write(wi);
+ width_ = os.str().size();
+ ascent_ = 1;
+ descent_ = 0;
+ }
+}
+
+
+void MathHullInset::drawT(TextPainter & pain, int x, int y) const
+{
+#if 0
+ if (display()) {
+ MathGridInset::drawT(pain, x, y);
+ } else
+#endif
+ {
+ ostringstream os;
+ WriteStream wi(os, false, true);
+ write(wi);
+ pain.draw(x, y, os.str().c_str());
+ }
+}
+
+
string MathHullInset::label(row_type row) const
{
+ row_type n = nrows();
+ lyx::Assert(row < n);
return label_[row];
}
void MathHullInset::label(row_type row, string const & label)
{
- label_[row] = label;
+ label_[row] = label;
}
void MathHullInset::numbered(row_type row, bool num)
{
- nonum_[row] = !num;
+ nonum_[row] = !num;
}
bool MathHullInset::ams() const
{
return true;
-
- return
+/*
+ return
objtype_ == LM_OT_ALIGN ||
objtype_ == LM_OT_MULTLINE ||
objtype_ == LM_OT_GATHER ||
objtype_ == LM_OT_ALIGNAT ||
objtype_ == LM_OT_XALIGNAT ||
objtype_ == LM_OT_XXALIGNAT;
+*/
}
}
-std::vector<string> const MathHullInset::getLabelList() const
+vector<string> const MathHullInset::getLabelList() const
{
- std::vector<string> res;
+ vector<string> res;
for (row_type row = 0; row < nrows(); ++row)
if (!label_[row].empty() && nonum_[row] != 1)
res.push_back(label_[row]);
void MathHullInset::validate(LaTeXFeatures & features) const
{
if (ams())
- features.require("amsstyle");
+ features.require("amsmath");
// Validation is necessary only if not using AMS math.
case LM_OT_EQUATION:
if (n)
- os << "\\begin{equation" << star(n) << "}\n";
+ os << "\\begin{equation" << star(n) << "}\n";
else
- os << "\\[\n";
+ os << "\\[\n";
break;
case LM_OT_EQNARRAY:
break;
case LM_OT_XXALIGNAT:
- os << "\\begin{xxalignat}"
+ os << "\\begin{xxalignat}"
<< "{" << static_cast<unsigned int>(ncols()/2) << "}\n";
break;
case LM_OT_EQUATION:
if (n)
- os << "\\end{equation" << star(n) << "}\n";
+ os << "\\end{equation" << star(n) << "}\n";
else
- os << "\\]\n";
+ os << "\\]\n";
break;
case LM_OT_EQNARRAY:
}
-void MathHullInset::addRow(row_type row)
+void MathHullInset::addRow(row_type row)
{
nonum_.insert(nonum_.begin() + row + 1, !numberedType());
label_.insert(label_.begin() + row + 1, string());
}
-void MathHullInset::delRow(row_type row)
+void MathHullInset::delRow(row_type row)
{
MathGridInset::delRow(row);
nonum_.erase(nonum_.begin() + row);
setType(LM_OT_SIMPLE);
break;
- case LM_OT_ALIGN:
+ case LM_OT_ALIGN:
case LM_OT_ALIGNAT:
case LM_OT_XALIGNAT:
case LM_OT_XXALIGNAT: {
MathGridInset::addCol(1);
// split it "nicely"
- pos_type pos = firstRelOp(cell(0));
+ pos_type pos = firstRelOp(cell(0));
cell(1) = cell(0);
cell(0).erase(pos, cell(0).size());
cell(1).erase(0, pos);
MathGridInset::addCol(1);
// split it "nicely" on the firest relop
- pos_type pos = firstRelOp(cell(0));
+ pos_type pos = firstRelOp(cell(0));
cell(1) = MathArray(cell(0), pos, cell(0).size());
cell(0).erase(pos, cell(0).size());
setType(LM_OT_EQNARRAY);
mutate(newtype);
break;
-
+
case LM_OT_ALIGNAT:
case LM_OT_XALIGNAT:
case LM_OT_XXALIGNAT:
default:
lyxerr << "mutation from '" << getType()
- << "' to '" << newtype << "' not implemented\n";
+ << "' to '" << newtype << "' not implemented"
+ << endl;
break;
}
break;
break;
default:
lyxerr << "mutation from '" << getType()
- << "' to '" << newtype << "' not implemented\n";
+ << "' to '" << newtype << "' not implemented"
+ << endl;
break;
}
break;
default:
lyxerr << "mutation from '" << getType()
- << "' to '" << newtype << "' not implemented\n";
+ << "' to '" << newtype << "' not implemented"
+ << endl;
break;
}
default:
lyxerr << "mutation from '" << getType()
- << "' to '" << newtype << "' not implemented\n";
+ << "' to '" << newtype << "' not implemented"
+ << endl;
+ break;
}
}
void MathHullInset::write(WriteStream & os) const
{
- header_write(os);
+ header_write(os);
bool n = numberedType();
for (row_type row = 0; row < nrows(); ++row) {
- for (col_type col = 0; col < ncols(); ++col)
- os << cell(index(row, col)) << eocString(col).c_str();
+ for (col_type col = 0; col < ncols(); ++col)
+ os << cell(index(row, col)) << eocString(col);
if (n) {
if (!label_[row].empty())
- os << "\\label{" << label_[row].c_str() << "}";
+ os << "\\label{" << label_[row] << "}";
if (nonum_[row])
os << "\\nonumber ";
}
- os << eolString(row).c_str();
+ os << eolString(row);
}
- footer_write(os);
+ footer_write(os);
}
void MathHullInset::normalize(NormalStream & os) const
{
- os << "[formula " << normalName(getType()).c_str() << " ";
+ os << "[formula " << normalName(getType()) << " ";
MathGridInset::normalize(os);
os << "] ";
}
}
+void MathHullInset::check() const
+{
+ lyx::Assert(nonum_.size() == nrows());
+ lyx::Assert(label_.size() == nrows());
+}