X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_matrixinset.C;h=4fa1ebd1f10c906d02d9809b933d45848cc59df9;hb=dff2911bda426ad439e6475f62183cedd7044801;hp=160f5c9bad4972b4041030f0c0f2536042819854;hpb=0f5ff99bc1918c68272b377b8eba663bc3915966;p=features.git diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index 160f5c9bad..4fa1ebd1f1 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -14,40 +14,71 @@ namespace { + int getCols(MathInsetTypes type) + { + switch (type) { + case LM_OT_EQNARRAY: + return 3; + case LM_OT_ALIGN: + case LM_OT_ALIGNAT: + case LM_OT_XALIGNAT: + case LM_OT_XXALIGNAT: + return 2; + default:; + } + return 1; + } -int getCols(MathInsetTypes type) -{ - switch (type) { - case LM_OT_EQNARRAY: - return 3; - case LM_OT_ALIGN: - case LM_OT_ALIGNAT: - case LM_OT_XALIGNAT: - case LM_OT_XXALIGNAT: - return 2; - default:; + + // returns position of first relation operator in the array + // used for "intelligent splitting" + int firstRelOp(MathArray const & ar) + { + for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) + if ((*it)->isRelOp()) + return it - ar.begin(); + return ar.size(); } - return 1; -} -// returns position of first relation operator in the array -// used for "intelligent splitting" -int firstRelOp(MathArray const & array) -{ - for (MathArray::const_iterator it = array.begin(); it != array.end(); ++it) - if (it->nucleus()->isRelOp()) - return it - array.begin(); - return array.size(); -} + char const * star(bool numbered) + { + return numbered ? "" : "*"; + } + MathInsetTypes typecode(string const & s) + { + if (s == "equation") return LM_OT_EQUATION; + if (s == "display") return LM_OT_EQUATION; + if (s == "eqnarray") return LM_OT_EQNARRAY; + if (s == "align") return LM_OT_ALIGN; + if (s == "alignat") return LM_OT_ALIGNAT; + if (s == "xalignat") return LM_OT_XALIGNAT; + if (s == "xxalignat") return LM_OT_XXALIGNAT; + if (s == "multline") return LM_OT_MULTLINE; + if (s == "gather") return LM_OT_GATHER; + return LM_OT_SIMPLE; + } -char const * star(bool numbered) -{ - return numbered ? "" : "*"; -} -} + string normalName(MathInsetTypes t) + { + switch (t) { + case LM_OT_EQUATION: return "equation"; + case LM_OT_EQNARRAY: return "eqnarray"; + case LM_OT_ALIGN: return "align"; + case LM_OT_ALIGNAT: return "alignat"; + case LM_OT_XALIGNAT: return "xalignat"; + case LM_OT_XXALIGNAT: return "xxalignat"; + case LM_OT_MULTLINE: return "multline"; + case LM_OT_GATHER: return "gather"; + case LM_OT_SIMPLE: return "simple"; + default: break; + } + return "unknown"; + } + +} // end anon namespace MathMatrixInset::MathMatrixInset() @@ -109,12 +140,13 @@ int MathMatrixInset::defaultColSpace(col_type col) } -void MathMatrixInset::metrics(MathStyles) const +void MathMatrixInset::metrics(MathMetricsInfo const & mi) const { - size_ = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY; + mi_ = mi; + mi_.style = (getType() == LM_OT_SIMPLE) ? LM_ST_TEXT : LM_ST_DISPLAY; // let the cells adjust themselves - MathGridInset::metrics(size_); + MathGridInset::metrics(mi_); if (display()) { ascent_ += 12; @@ -124,7 +156,7 @@ void MathMatrixInset::metrics(MathStyles) const if (numberedType()) { int l = 0; for (row_type row = 0; row < nrows(); ++row) - l = std::max(l, mathed_string_width(LM_TC_BF, size(), nicelabel(row))); + l = std::max(l, mathed_string_width(LM_TC_BF, mi_, nicelabel(row))); if (l) width_ += 30 + l; @@ -133,7 +165,7 @@ void MathMatrixInset::metrics(MathStyles) const // make it at least as high as the current font int asc = 0; int des = 0; - math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, des); + math_font_max_dim(LM_TC_TEXTRM, mi_, asc, des); ascent_ = std::max(ascent_, asc); descent_ = std::max(descent_, des); } @@ -141,32 +173,27 @@ void MathMatrixInset::metrics(MathStyles) const void MathMatrixInset::draw(Painter & pain, int x, int y) const { - xo(x); - yo(y); - MathGridInset::draw(pain, x, y); if (numberedType()) { - int xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20; + int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20; for (row_type row = 0; row < nrows(); ++row) { - int yy = y + rowinfo_[row].offset_; - drawStr(pain, LM_TC_BF, size(), xx, yy, nicelabel(row)); + int const yy = y + rowinfo_[row].offset_; + drawStr(pain, LM_TC_BF, mi_, xx, yy, nicelabel(row)); } } } -void MathMatrixInset::write(std::ostream & os, bool fragile) const +void MathMatrixInset::write(MathWriteInfo & os) const { - header_write(os); + header_write(os.os); bool n = numberedType(); for (row_type row = 0; row < nrows(); ++row) { - for (col_type col = 0; col < ncols(); ++col) { - cell(index(row, col)).write(os, fragile); - os << eocString(col); - } + 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] << "}"; @@ -176,10 +203,19 @@ void MathMatrixInset::write(std::ostream & os, bool fragile) const os << eolString(row); } - footer_write(os); + footer_write(os.os); +} + + +void MathMatrixInset::writeNormal(std::ostream & os) const +{ + os << "[formula " << normalName(getType()) << " "; + MathGridInset::writeNormal(os); + os << "] "; } + string MathMatrixInset::label(row_type row) const { return label_[row]; @@ -207,6 +243,14 @@ bool MathMatrixInset::numbered(row_type row) const bool MathMatrixInset::ams() const { return true; + + 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; } @@ -276,7 +320,7 @@ void MathMatrixInset::header_write(std::ostream & os) const break; case LM_OT_ALIGN: - os << "\\begin{align" << star(n) << "}"; + os << "\\begin{align" << star(n) << "}\n"; break; case LM_OT_ALIGNAT: @@ -322,31 +366,31 @@ void MathMatrixInset::footer_write(std::ostream & os) const break; case LM_OT_EQNARRAY: - os << "\\end{eqnarray" << star(n) << "}\n"; + os << "\n\\end{eqnarray" << star(n) << "}\n"; break; case LM_OT_ALIGN: - os << "\\end{align" << star(n) << "}\n"; + os << "\n\\end{align" << star(n) << "}\n"; break; case LM_OT_ALIGNAT: - os << "\\end{alignat" << star(n) << "}\n"; + os << "\n\\end{alignat" << star(n) << "}\n"; break; case LM_OT_XALIGNAT: - os << "\\end{xalignat" << star(n) << "}\n"; + os << "\n\\end{xalignat" << star(n) << "}\n"; break; case LM_OT_XXALIGNAT: - os << "\\end{xxalignat}\n"; + os << "\n\\end{xxalignat}\n"; break; case LM_OT_MULTLINE: - os << "\\end{multline}\n"; + os << "\n\\end{multline}\n"; break; case LM_OT_GATHER: - os << "\\end{gather}\n"; + os << "\n\\end{gather}\n"; break; default: @@ -434,32 +478,6 @@ string MathMatrixInset::nicelabel(row_type row) const } -namespace { - MathInsetTypes typecode(string const & s) - { - if (s == "equation") - return LM_OT_EQUATION; - if (s == "display") - return LM_OT_EQUATION; - if (s == "eqnarray") - return LM_OT_EQNARRAY; - if (s == "align") - return LM_OT_ALIGN; - if (s == "alignat") - return LM_OT_ALIGN; - if (s == "xalignat") - return LM_OT_XALIGNAT; - if (s == "xxalignat") - return LM_OT_XXALIGNAT; - if (s == "multline") - return LM_OT_MULTLINE; - if (s == "gather") - return LM_OT_GATHER; - return LM_OT_SIMPLE; - } -} - - void MathMatrixInset::mutate(string const & newtype) { if (newtype == "dump") {