From defe8051ab83f9a728c78ae1d183466c8b8b5396 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 28 Apr 2003 08:44:56 +0000 Subject: [PATCH] fix random crashes git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6867 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 1 + src/mathed/formula.C | 29 +++++++++++------- src/mathed/formula.h | 4 +-- src/mathed/math_gridinset.C | 45 +++++++++++++--------------- src/mathed/math_hullinset.C | 59 +++++++++++++++++++++++++------------ src/mathed/math_hullinset.h | 2 ++ src/mathed/math_inset.C | 7 ++++- src/mathed/math_inset.h | 2 +- src/mathed/math_parser.C | 4 +-- 9 files changed, 93 insertions(+), 60 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 899cf2c1c8..b465c713f2 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,4 @@ + 2003-04-14 Angus Leeming * math_fboxinset.C: diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 1d7119fc13..4154cb80ca 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -47,16 +47,9 @@ #include "graphics/PreviewedInset.h" #include "graphics/PreviewImage.h" -#include - using std::ostream; -using std::ifstream; -using std::istream; -using std::pair; -using std::endl; using std::vector; -using std::getline; class InsetFormula::PreviewImpl : public grfx::PreviewedInset { @@ -78,10 +71,13 @@ private: -InsetFormula::InsetFormula() +InsetFormula::InsetFormula(bool chemistry) : par_(MathAtom(new MathHullInset)), preview_(new PreviewImpl(*this)) -{} +{ + if (chemistry) + mutate("chemistry"); +} InsetFormula::InsetFormula(InsetFormula const & other) @@ -182,6 +178,19 @@ int InsetFormula::docbook(Buffer const * buf, ostream & os, bool) const void InsetFormula::read(Buffer const *, LyXLex & lex) { mathed_parse_normal(par_, lex); + // remove extra 'mathrm' for chemistry stuff. + // will be re-added on write + if (par_->asHullInset()->getType() =="chemistry") { + lyxerr << "this is chemistry\n"; + if (par_->cell(0).size() == 1) { + lyxerr << "this is size 1\n"; + if (par_->cell(0)[0]->asFontInset()) { + lyxerr << "this is a font inset \n"; + lyxerr << "replacing " << par_.nucleus()->cell(0) << + " with " << par_->cell(0)[0]->cell(0) << "\n"; + } + } + } metrics(); } @@ -293,12 +302,10 @@ int InsetFormula::width(BufferView * bv, LyXFont const & font) const } -/* void InsetFormula::mutate(string const & type) { par_.nucleus()->mutate(type); } -*/ // diff --git a/src/mathed/formula.h b/src/mathed/formula.h index 3c7381ee24..cf45606dad 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -25,7 +25,7 @@ class InsetFormula : public InsetFormulaBase { public: /// - InsetFormula(); + InsetFormula(bool chemistry = false); /// explicit InsetFormula(BufferView *); /// @@ -75,7 +75,7 @@ public: /// void addPreview(grfx::PreviewLoader &) const; /// - //void mutate(string const & type); + void mutate(string const & type); private: /// available in AMS only? diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index ccf1c7b486..8f1a72a1e1 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -211,13 +211,13 @@ char MathGridInset::valign() const MathGridInset::col_type MathGridInset::ncols() const { - return colinfo_.size() - 1; + return colinfo_.size(); } MathGridInset::row_type MathGridInset::nrows() const { - return rowinfo_.size() - 1; + return rowinfo_.size(); } @@ -263,12 +263,10 @@ void MathGridInset::metrics(MetricsInfo & mi) const rowinfo_[row].descent_ = desc; } rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_; - rowinfo_[nrows()].ascent_ = 0; - rowinfo_[nrows()].descent_ = 0; // compute vertical offsets rowinfo_[0].offset_ = 0; - for (row_type row = 1; row <= nrows(); ++row) { + for (row_type row = 1; row < nrows(); ++row) { rowinfo_[row].offset_ = rowinfo_[row - 1].offset_ + rowinfo_[row - 1].descent_ + @@ -290,7 +288,7 @@ void MathGridInset::metrics(MetricsInfo & mi) const default: h = rowinfo_[nrows() - 1].offset_ / 2; } - for (row_type row = 0; row <= nrows(); ++row) + for (row_type row = 0; row < nrows(); ++row) rowinfo_[row].offset_ -= h; @@ -301,11 +299,10 @@ void MathGridInset::metrics(MetricsInfo & mi) const wid = max(wid, cell(index(row, col)).width()); colinfo_[col].width_ = wid; } - colinfo_[ncols()].width_ = 0; // compute horizontal offsets colinfo_[0].offset_ = border(); - for (col_type col = 1; col <= ncols(); ++col) { + for (col_type col = 1; col < ncols(); ++col) { colinfo_[col].offset_ = colinfo_[col - 1].offset_ + colinfo_[col - 1].width_ + @@ -315,19 +312,19 @@ void MathGridInset::metrics(MetricsInfo & mi) const } - dim_.w = colinfo_[ncols() - 1].offset_ + dim_.w = colinfo_[ncols() - 1].offset_ + colinfo_[ncols() - 1].width_ - + vlinesep() * colinfo_[ncols()].lines_ + //+ vlinesep() * colinfo_[ncols()].lines_ + border(); - dim_.a = - rowinfo_[0].offset_ + dim_.a = - rowinfo_[0].offset_ + rowinfo_[0].ascent_ - + hlinesep() * rowinfo_[0].lines_ + + hlinesep() * rowinfo_[0].lines_ + border(); dim_.d = rowinfo_[nrows() - 1].offset_ + rowinfo_[nrows() - 1].descent_ - + hlinesep() * rowinfo_[nrows()].lines_ + //+ hlinesep() * rowinfo_[nrows()].lines_ + border(); @@ -389,14 +386,14 @@ void MathGridInset::draw(PainterInfo & pi, int x, int y) const for (idx_type idx = 0; idx < nargs(); ++idx) cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx)); - for (row_type row = 0; row <= nrows(); ++row) + for (row_type row = 0; row < nrows(); ++row) for (int i = 0; i < rowinfo_[row].lines_; ++i) { int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_ - i * hlinesep() - hlinesep()/2 - rowsep()/2; pi.pain.line(x + 1, yy, x + width() - 1, yy); } - for (col_type col = 0; col <= ncols(); ++col) + for (col_type col = 0; col < ncols(); ++col) for (int i = 0; i < colinfo_[col].lines_; ++i) { int xx = x + colinfo_[col].offset_ - i * vlinesep() - vlinesep()/2 - colsep()/2; @@ -430,7 +427,7 @@ void MathGridInset::metricsT(TextMetricsInfo const & mi) const // compute vertical offsets rowinfo_[0].offset_ = 0; - for (row_type row = 1; row <= nrows(); ++row) { + for (row_type row = 1; row < nrows(); ++row) { rowinfo_[row].offset_ = rowinfo_[row - 1].offset_ + rowinfo_[row - 1].descent_ + @@ -452,7 +449,7 @@ void MathGridInset::metricsT(TextMetricsInfo const & mi) const default: h = rowinfo_[nrows() - 1].offset_ / 2; } - for (row_type row = 0; row <= nrows(); ++row) + for (row_type row = 0; row < nrows(); ++row) rowinfo_[row].offset_ -= h; @@ -467,7 +464,7 @@ void MathGridInset::metricsT(TextMetricsInfo const & mi) const // compute horizontal offsets colinfo_[0].offset_ = border(); - for (col_type col = 1; col <= ncols(); ++col) { + for (col_type col = 1; col < ncols(); ++col) { colinfo_[col].offset_ = colinfo_[col - 1].offset_ + colinfo_[col - 1].width_ + @@ -908,12 +905,12 @@ void MathGridInset::write(WriteStream & os) const if (!emptyline && row + 1 < nrows()) os << "\n"; } - string const s = verboseHLine(rowinfo_[nrows()].lines_); - if (!s.empty() && s != " ") { - if (os.fragile()) - os << "\\protect"; - os << "\\\\" << s; - } + //string const s = verboseHLine(rowinfo_[nrows()].lines_); + //if (!s.empty() && s != " ") { + // if (os.fragile()) + // os << "\\protect"; + // os << "\\\\" << s; + //} } diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index c127190139..ad5080ffc0 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -69,15 +69,16 @@ namespace { { if (s == "none") return 0; if (s == "simple") return 1; - if (s == "equation") return 2; - if (s == "eqnarray") return 3; - if (s == "align") return 4; - if (s == "alignat") return 5; - if (s == "xalignat") return 6; - if (s == "xxalignat") return 7; - if (s == "multline") return 8; - if (s == "gather") return 9; - if (s == "flalign") return 10; + if (s == "chemistry") return 2; + if (s == "equation") return 3; + if (s == "eqnarray") return 4; + if (s == "align") return 5; + if (s == "alignat") return 6; + if (s == "xalignat") return 7; + if (s == "xxalignat") return 8; + if (s == "multline") return 9; + if (s == "gather") return 10; + if (s == "flalign") return 11; lyxerr << "unknown hull type '" << s << "'\n"; return 0; } @@ -162,6 +163,8 @@ char const * MathHullInset::standardFont() const { if (type_ == "none") return "lyxnochange"; + if (type_ == "chemistry") + return "mathrm"; return "mathnormal"; } @@ -290,7 +293,7 @@ bool MathHullInset::ams() const bool MathHullInset::display() const { - return type_ != "simple" && type_ != "none"; + return type_ != "simple" && type_ != "none" && type_ != "chemistry"; } @@ -306,6 +309,8 @@ bool MathHullInset::numberedType() const { if (type_ == "none") return false; + if (type_ == "chemistry") + return false; if (type_ == "simple") return false; if (type_ == "xxalignat") @@ -348,6 +353,9 @@ void MathHullInset::header_write(WriteStream & os) const os << ' '; } + else if (type_ == "chemistry") + os << "$\\mathrm{"; + else if (type_ == "equation") { if (n) os << "\\begin{equation" << star(n) << "}\n"; @@ -382,6 +390,9 @@ void MathHullInset::footer_write(WriteStream & os) const else if (type_ == "simple") os << '$'; + else if (type_ == "chemistry") + os << "}$"; + else if (type_ == "equation") if (n) os << "\\end{equation" << star(n) << "}\n"; @@ -495,22 +506,22 @@ void MathHullInset::mutate(string const & newtype) // done } - else if (type_ == "none") { - setType("simple"); + else if (newtype == "none" || newtype == "chemistry") { + mutate("simple"); numbered(0, false); - mutate(newtype); } - else if (type_ == "simple") { - if (newtype == "none") { - setType("none"); - } else { - setType("equation"); + else if (newtype == "simple") { + if (type_ != "none" && type_ != "chemistry") { + mutate("equation"); numbered(0, false); - mutate(newtype); } } + else if (newtype == "equation" && smaller(type_, newtype)) { + numbered(0, false); + } + else if (type_ == "equation") { if (smaller(newtype, type_)) { setType("simple"); @@ -614,6 +625,8 @@ void MathHullInset::mutate(string const & newtype) lyxerr << "mutation from '" << type_ << "' to '" << newtype << "' not implemented" << endl; } + + setType(newtype); } @@ -842,3 +855,11 @@ dispatch_result MathHullInset::dispatch } return UNDISPATCHED; } + + +string MathHullInset::fileInsetLabel() const +{ + if (type_ == "chemistry") + return "Chemistry"; + return "Formula"; +} diff --git a/src/mathed/math_hullinset.h b/src/mathed/math_hullinset.h index 3beaa30e4f..7b3e407e42 100644 --- a/src/mathed/math_hullinset.h +++ b/src/mathed/math_hullinset.h @@ -79,6 +79,8 @@ public: /// bool idxLast(idx_type &, pos_type &) const; + /// + string fileInsetLabel() const; /// void write(WriteStream & os) const; /// diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 7b4fd1fdb8..aa4493987b 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -276,7 +276,7 @@ int MathInset::docbook(std::ostream &, bool) const string const & MathInset::getType() const { - static string t("none"); + static string const t("none"); return t; } @@ -311,3 +311,8 @@ ostream & operator<<(ostream & os, MathAtom const & at) return os; } + +string MathInset::fileInsetLabel() const +{ + return "Formula"; +} diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 2bd1a23233..19ebb970c8 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -299,7 +299,7 @@ public: /// change type virtual void mutate(string const &) {} /// how is the inset called in the .lyx file? - virtual string fileInsetLabel() const { return "Formula"; } + virtual string fileInsetLabel() const; /// usually the latex name virtual string name() const; diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 57d04f882e..b7601e448e 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -1213,10 +1213,10 @@ void Parser::parse1(MathGridInset & grid, unsigned flags, MathAtom at = createMathInset(t.cs()); MathInset::mode_type m = mode; //if (m == MathInset::UNDECIDED_MODE) - lyxerr << "default creation: m1: " << m << "\n"; + //lyxerr << "default creation: m1: " << m << "\n"; if (at->currentMode() != MathInset::UNDECIDED_MODE) m = at->currentMode(); - lyxerr << "default creation: m2: " << m << "\n"; + //lyxerr << "default creation: m2: " << m << "\n"; MathInset::idx_type start = 0; // this fails on \bigg[...\bigg] //MathArray opt; -- 2.39.2