From c93e9dcbc59d0b404561dbc7c373716f11fc13f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 9 Nov 2001 08:35:57 +0000 Subject: [PATCH] some support for matrix operations with maple ('M-x math-extern maple evalm') further cosmetics git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2991 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/Makefile.am | 4 + src/mathed/formula.C | 16 +-- src/mathed/formulamacro.C | 6 +- src/mathed/math_arrayinset.C | 28 +++-- src/mathed/math_arrayinset.h | 11 +- src/mathed/math_atom.C | 8 ++ src/mathed/math_atom.h | 2 + src/mathed/math_binaryopinset.C | 4 +- src/mathed/math_binaryopinset.h | 4 +- src/mathed/math_binominset.C | 10 +- src/mathed/math_binominset.h | 4 +- src/mathed/math_boxinset.C | 4 +- src/mathed/math_boxinset.h | 4 +- src/mathed/math_braceinset.C | 28 ++--- src/mathed/math_braceinset.h | 4 +- src/mathed/math_charinset.C | 4 +- src/mathed/math_charinset.h | 4 +- src/mathed/math_cursor.C | 12 +-- src/mathed/math_data.C | 164 +---------------------------- src/mathed/math_data.h | 26 ----- src/mathed/math_decorationinset.C | 4 +- src/mathed/math_decorationinset.h | 4 +- src/mathed/math_deliminset.C | 18 ++-- src/mathed/math_deliminset.h | 19 ++-- src/mathed/math_dotsinset.C | 4 +- src/mathed/math_dotsinset.h | 4 +- src/mathed/math_exfuncinset.C | 4 +- src/mathed/math_exfuncinset.h | 4 +- src/mathed/math_exintinset.C | 4 +- src/mathed/math_exintinset.h | 4 +- src/mathed/math_fracinset.C | 9 +- src/mathed/math_fracinset.h | 9 +- src/mathed/math_funcinset.C | 4 +- src/mathed/math_funcinset.h | 4 +- src/mathed/math_funcliminset.C | 4 +- src/mathed/math_funcliminset.h | 4 +- src/mathed/math_gridinset.C | 49 +-------- src/mathed/math_gridinset.h | 10 +- src/mathed/math_hullinset.C | 6 +- src/mathed/math_hullinset.h | 10 +- src/mathed/math_inset.C | 16 +-- src/mathed/math_inset.h | 31 ++++-- src/mathed/math_kerninset.C | 4 +- src/mathed/math_kerninset.h | 4 +- src/mathed/math_lefteqninset.C | 11 +- src/mathed/math_lefteqninset.h | 4 +- src/mathed/math_macro.C | 14 ++- src/mathed/math_macro.h | 4 +- src/mathed/math_macroarg.C | 4 +- src/mathed/math_macroarg.h | 4 +- src/mathed/math_macrotemplate.C | 2 +- src/mathed/math_macrotemplate.h | 2 +- src/mathed/math_mathmlstream.C | 31 +++--- src/mathed/math_mathmlstream.h | 16 +-- src/mathed/math_matrixinset.C | 71 +++++++++++++ src/mathed/math_matrixinset.h | 38 +++++++ src/mathed/math_nestinset.C | 2 +- src/mathed/math_notinset.C | 4 +- src/mathed/math_notinset.h | 4 +- src/mathed/math_parser.C | 8 +- src/mathed/math_rootinset.C | 12 +-- src/mathed/math_rootinset.h | 13 +-- src/mathed/math_scriptinset.C | 12 +-- src/mathed/math_scriptinset.h | 8 +- src/mathed/math_sizeinset.C | 4 +- src/mathed/math_sizeinset.h | 4 +- src/mathed/math_spaceinset.C | 4 +- src/mathed/math_spaceinset.h | 4 +- src/mathed/math_specialcharinset.C | 4 +- src/mathed/math_specialcharinset.h | 4 +- src/mathed/math_splitinset.C | 2 +- src/mathed/math_splitinset.h | 2 +- src/mathed/math_sqrtinset.C | 10 +- src/mathed/math_sqrtinset.h | 7 +- src/mathed/math_stackrelinset.C | 10 +- src/mathed/math_stackrelinset.h | 9 +- src/mathed/math_stringinset.C | 4 +- src/mathed/math_stringinset.h | 4 +- src/mathed/math_symbolinset.C | 4 +- src/mathed/math_symbolinset.h | 4 +- src/mathed/math_xdata.C | 19 ++-- 81 files changed, 427 insertions(+), 516 deletions(-) create mode 100644 src/mathed/math_matrixinset.C create mode 100644 src/mathed/math_matrixinset.h diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index e3962acf03..a1a379d661 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -41,6 +41,8 @@ libmathed_la_SOURCES = \ math_diminset.h \ math_dotsinset.C \ math_dotsinset.h \ + math_extern.C \ + math_extern.h \ math_exfuncinset.C \ math_exfuncinset.h \ math_exintinset.C \ @@ -76,6 +78,8 @@ libmathed_la_SOURCES = \ math_macrotable.h \ math_mathmlstream.C \ math_mathmlstream.h \ + math_matrixinset.C \ + math_matrixinset.h \ math_metricsinfo.h \ math_metricsinfo.C \ math_nestinset.C \ diff --git a/src/mathed/formula.C b/src/mathed/formula.C index d08d005784..2e808ab513 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -87,7 +87,7 @@ namespace { "subs(`\\,`=`\\cdot `," "eval(`latex/latex/*`)):\n"; - // replace spurious \\noalign{\\medskip} in table output + // remove spurious \\noalign{\\medskip} in matrix output header += "`latex/latex/matrix`:= " "subs(`\\\\\\\\\\\\noalign{\\\\medskip}` = `\\\\\\\\`," @@ -226,7 +226,7 @@ namespace { ostringstream os; NormalStream ns(os); os << "[" << extra << ' '; - ar.writeNormal(ns); + ns << ar; os << "]"; string data = os.str().c_str(); @@ -290,7 +290,7 @@ void InsetFormula::write(Buffer const * buf, ostream & os) const int InsetFormula::latex(Buffer const * buf, ostream & os, bool fragil, bool) const { - MathWriteInfo wi(buf, os, fragil); + WriteStream wi(buf, os, fragil); par_->write(wi); return 1; } @@ -298,7 +298,7 @@ int InsetFormula::latex(Buffer const * buf, ostream & os, bool fragil, bool) int InsetFormula::ascii(Buffer const * buf, ostream & os, int) const { - MathWriteInfo wi(buf, os, false); + WriteStream wi(buf, os, false); par_->write(wi); return 1; } @@ -539,15 +539,15 @@ bool InsetFormula::display() const MathHullInset const * InsetFormula::mat() const { - lyx::Assert(par_->asMatrixInset()); - return par_->asMatrixInset(); + lyx::Assert(par_->asHullInset()); + return par_->asHullInset(); } MathHullInset * InsetFormula::mat() { - lyx::Assert(par_->asMatrixInset()); - return par_->asMatrixInset(); + lyx::Assert(par_->asHullInset()); + return par_->asHullInset(); } diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index bd50d8c087..7740c47da6 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -78,7 +78,7 @@ Inset * InsetFormulaMacro::clone(Buffer const &, bool) const void InsetFormulaMacro::write(Buffer const * buf, ostream & os) const { os << "FormulaMacro "; - MathWriteInfo wi(buf, os, false); + WriteStream wi(buf, os, false); par()->write(wi); } @@ -86,7 +86,7 @@ void InsetFormulaMacro::write(Buffer const * buf, ostream & os) const int InsetFormulaMacro::latex(Buffer const * buf, ostream & os, bool fragile, bool /*free_spacing*/) const { - MathWriteInfo wi(buf, os, fragile); + WriteStream wi(buf, os, fragile); par()->write(wi); return 2; } @@ -94,7 +94,7 @@ int InsetFormulaMacro::latex(Buffer const * buf, ostream & os, bool fragile, int InsetFormulaMacro::ascii(Buffer const * buf, ostream & os, int) const { - MathWriteInfo wi(buf, os, false); + WriteStream wi(buf, os, false); par()->write(wi); return 0; } diff --git a/src/mathed/math_arrayinset.C b/src/mathed/math_arrayinset.C index ff252ee435..97240cb67c 100644 --- a/src/mathed/math_arrayinset.C +++ b/src/mathed/math_arrayinset.C @@ -4,11 +4,11 @@ #include "math_arrayinset.h" #include "math_parser.h" -#include "support/LOstream.h" -#include "Lsstream.h" #include "math_mathmlstream.h" +#include "Lsstream.h" using std::vector; +using std::istringstream; MathArrayInset::MathArrayInset(int m, int n) @@ -52,7 +52,16 @@ MathInset * MathArrayInset::clone() const } -void MathArrayInset::write(MathWriteInfo & os) const +void MathArrayInset::metrics(MathMetricsInfo const & st) const +{ + MathMetricsInfo mi = st; + if (mi.style == LM_ST_DISPLAY) + mi.style = LM_ST_TEXT; + MathGridInset::metrics(mi); +} + + +void MathArrayInset::write(WriteStream & os) const { if (os.fragile) os << "\\protect"; @@ -74,18 +83,17 @@ void MathArrayInset::write(MathWriteInfo & os) const } -void MathArrayInset::writeNormal(NormalStream & os) const +void MathArrayInset::normalize(NormalStream & os) const { os << "[array "; - MathGridInset::writeNormal(os); + MathGridInset::normalize(os); os << "]"; } -void MathArrayInset::metrics(MathMetricsInfo const & st) const +void MathArrayInset::maplize(MapleStream & os) const { - MathMetricsInfo mi = st; - if (mi.style == LM_ST_DISPLAY) - mi.style = LM_ST_TEXT; - MathGridInset::metrics(mi); + os << "array("; + MathGridInset::maplize(os); + os << ")"; } diff --git a/src/mathed/math_arrayinset.h b/src/mathed/math_arrayinset.h index 06d092e413..89f34545c3 100644 --- a/src/mathed/math_arrayinset.h +++ b/src/mathed/math_arrayinset.h @@ -20,13 +20,16 @@ public: /// MathInset * clone() const; /// - void write(MathWriteInfo & os) const; - /// - void writeNormal(NormalStream &) const; - /// void metrics(MathMetricsInfo const & st) const; /// MathArrayInset * asArrayInset() { return this; } + + /// + void write(WriteStream & os) const; + /// + void normalize(NormalStream &) const; + /// + void maplize(MapleStream &) const; }; #endif diff --git a/src/mathed/math_atom.C b/src/mathed/math_atom.C index 57acb4a0a7..cfb2e9bbff 100644 --- a/src/mathed/math_atom.C +++ b/src/mathed/math_atom.C @@ -55,6 +55,14 @@ MathAtom::~MathAtom() } +void MathAtom::reset(MathInset * p) +{ + done(); + nucleus_ = p; +} + + + void MathAtom::done() { delete nucleus_; diff --git a/src/mathed/math_atom.h b/src/mathed/math_atom.h index 938d1170ec..8713c4113b 100644 --- a/src/mathed/math_atom.h +++ b/src/mathed/math_atom.h @@ -41,6 +41,8 @@ public: /// void operator=(MathAtom const &); /// + void reset(MathInset * p); + /// MathInset * nucleus() const; /// MathInset * operator->() const; diff --git a/src/mathed/math_binaryopinset.C b/src/mathed/math_binaryopinset.C index e27de8034d..5106d17052 100644 --- a/src/mathed/math_binaryopinset.C +++ b/src/mathed/math_binaryopinset.C @@ -45,13 +45,13 @@ void MathBinaryOpInset::draw(Painter & pain, int x, int y) const } -void MathBinaryOpInset::write(MathWriteInfo & os) const +void MathBinaryOpInset::write(WriteStream & os) const { os << '{' << cell(0) << op_ << cell(1) << '}'; } -void MathBinaryOpInset::writeNormal(NormalStream & os) const +void MathBinaryOpInset::normalize(NormalStream & os) const { os << "[binop " << op_ << ' ' << cell(0) << ' ' << cell(1) << ']'; } diff --git a/src/mathed/math_binaryopinset.h b/src/mathed/math_binaryopinset.h index 2eca9519da..cdd4db1573 100644 --- a/src/mathed/math_binaryopinset.h +++ b/src/mathed/math_binaryopinset.h @@ -21,9 +21,9 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// void metrics(MathMetricsInfo const & st) const; private: diff --git a/src/mathed/math_binominset.C b/src/mathed/math_binominset.C index 58b1acafa2..342492c8ab 100644 --- a/src/mathed/math_binominset.C +++ b/src/mathed/math_binominset.C @@ -51,17 +51,13 @@ void MathBinomInset::draw(Painter & pain, int x, int y) const } -void MathBinomInset::write(MathWriteInfo & os) const +void MathBinomInset::write(WriteStream & os) const { os << '{' << cell(0) << " \\choose " << cell(1) << '}'; } -void MathBinomInset::writeNormal(NormalStream & os) const +void MathBinomInset::normalize(NormalStream & os) const { - os << "[binom "; - cell(0).writeNormal(os); - os << " "; - cell(1).writeNormal(os); - os << "] "; + os << "[binom " << cell(0) << ' ' << cell(1) << ']'; } diff --git a/src/mathed/math_binominset.h b/src/mathed/math_binominset.h index 35f5933c0b..213d19a074 100644 --- a/src/mathed/math_binominset.h +++ b/src/mathed/math_binominset.h @@ -18,9 +18,9 @@ public: /// MathInset * clone() const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// void metrics(MathMetricsInfo const & st) const; /// diff --git a/src/mathed/math_boxinset.C b/src/mathed/math_boxinset.C index 7eb163fe98..ba4ab6b2b3 100644 --- a/src/mathed/math_boxinset.C +++ b/src/mathed/math_boxinset.C @@ -45,13 +45,13 @@ UpdatableInset * MathBoxInset::asHyperActiveInset() const } -void MathBoxInset::write(MathWriteInfo & os) const +void MathBoxInset::write(WriteStream & os) const { os << "\\" << name_.c_str() << "{" << cell(0) << "}"; } -void MathBoxInset::writeNormal(NormalStream & os) const +void MathBoxInset::normalize(NormalStream & os) const { os << "[mbox "; //text_->write(buffer(), os); diff --git a/src/mathed/math_boxinset.h b/src/mathed/math_boxinset.h index 8812296605..f67fa168f6 100644 --- a/src/mathed/math_boxinset.h +++ b/src/mathed/math_boxinset.h @@ -30,9 +30,9 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// void metrics(MathMetricsInfo const &) const; /// identifies BoxInsets diff --git a/src/mathed/math_braceinset.C b/src/mathed/math_braceinset.C index ff1c469651..65970370c4 100644 --- a/src/mathed/math_braceinset.C +++ b/src/mathed/math_braceinset.C @@ -21,20 +21,6 @@ MathInset * MathBraceInset::clone() const } -void MathBraceInset::write(MathWriteInfo & os) const -{ - os << '{' << cell(0) << '}'; -} - - -void MathBraceInset::writeNormal(NormalStream & os) const -{ - os << "[block "; - cell(0).writeNormal(os); - os << "]"; -} - - void MathBraceInset::metrics(MathMetricsInfo const & mi) const { xcell(0).metrics(mi); @@ -52,3 +38,17 @@ void MathBraceInset::draw(Painter & pain, int x, int y) const xcell(0).draw(pain, x + wid_, y); drawChar(pain, LM_TC_TEX, mi_, x + width_ - wid_, y, '}'); } + + +void MathBraceInset::write(WriteStream & os) const +{ + os << '{' << cell(0) << '}'; +} + + +void MathBraceInset::normalize(NormalStream & os) const +{ + os << "[block " << cell(0) << ']'; +} + + diff --git a/src/mathed/math_braceinset.h b/src/mathed/math_braceinset.h index 960f674b82..6a9c086575 100644 --- a/src/mathed/math_braceinset.h +++ b/src/mathed/math_braceinset.h @@ -22,9 +22,9 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// write normalized content - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// void metrics(MathMetricsInfo const & st) const; diff --git a/src/mathed/math_charinset.C b/src/mathed/math_charinset.C index cc3bb1dbb3..a19d79aef6 100644 --- a/src/mathed/math_charinset.C +++ b/src/mathed/math_charinset.C @@ -94,7 +94,7 @@ void MathCharInset::writeRaw(std::ostream & os) const } -void MathCharInset::write(MathWriteInfo & os) const +void MathCharInset::write(WriteStream & os) const { writeHeader(os.os); writeRaw(os.os); @@ -102,7 +102,7 @@ void MathCharInset::write(MathWriteInfo & os) const } -void MathCharInset::writeNormal(NormalStream & os) const +void MathCharInset::normalize(NormalStream & os) const { os << "[char " << char_ << " " << "mathalpha" << "]"; } diff --git a/src/mathed/math_charinset.h b/src/mathed/math_charinset.h index 790453440a..4f4978793e 100644 --- a/src/mathed/math_charinset.h +++ b/src/mathed/math_charinset.h @@ -27,7 +27,7 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// void writeHeader(std::ostream &) const; /// @@ -35,7 +35,7 @@ public: /// void writeRaw(std::ostream &) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// int ascent() const; /// diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index a19c107275..d43f118cb0 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -974,7 +974,7 @@ void MathCursor::normalize() const lyxerr << "this should not really happen - 2: " << pos() << " " << size() << " in idx: " << it->idx() << " in atom: '"; - MathWriteInfo wi(0, lyxerr, false); + WriteStream wi(0, lyxerr, false); it->par()->write(wi); lyxerr << "\n"; dump("error 4"); @@ -1091,7 +1091,7 @@ void MathCursor::breakLine() while (popRight()) ; - MathHullInset * p = formula()->par()->asMatrixInset(); + MathHullInset * p = formula()->par()->asHullInset(); if (!p) return; @@ -1104,12 +1104,8 @@ void MathCursor::breakLine() // split line const row_type r = row(); - for (col_type c = col() + 1; c < p->ncols(); ++c) { - const MathHullInset::idx_type i1 = p->index(r, c); - const MathHullInset::idx_type i2 = p->index(r + 1, c); - //lyxerr << "swapping cells " << i1 << " and " << i2 << "\n"; - p->cell(i1).swap(p->cell(i2)); - } + for (col_type c = col() + 1; c < p->ncols(); ++c) + p->cell(p->index(r, c)).swap(p->cell(p->index(r + 1, c))); // split cell splitCell(); diff --git a/src/mathed/math_data.C b/src/mathed/math_data.C index 30821404d1..170ae41491 100644 --- a/src/mathed/math_data.C +++ b/src/mathed/math_data.C @@ -3,9 +3,11 @@ #endif #include "math_inset.h" +#include "math_deliminset.h" #include "math_charinset.h" #include "math_scriptinset.h" #include "math_stringinset.h" +#include "math_matrixinset.h" #include "math_mathmlstream.h" #include "math_support.h" #include "math_data.h" @@ -29,19 +31,6 @@ void MathArray::substitute(MathMacro const & m) } -MathScriptInset const * MathArray::asScript(const_iterator it) const -{ - if (it->nucleus()->asScriptInset()) - return 0; - const_iterator jt = it + 1; - if (jt == end()) - return 0; - if (!jt->nucleus()) - return 0; - return jt->nucleus()->asScriptInset(); -} - - MathAtom & MathArray::at(size_type pos) { lyx::Assert(pos < size()); @@ -146,147 +135,6 @@ void MathArray::dump() const } -// returns sequence of char with same code starting at it up to end -// it might be less, though... -string charSequence(MathArray::const_iterator it, MathArray::const_iterator end) -{ - string s; - MathCharInset const * p = it->nucleus()->asCharInset(); - if (!p) - return s; - - for (MathTextCodes c = p->code(); it != end; ++it) { - if (!it->nucleus()) - break; - p = it->nucleus()->asCharInset(); - if (!p || p->code() != c) - break; - s += p->getChar(); - } - return s; -} - - -MathArray MathArray::glueChars() const -{ - MathArray ar; - const_iterator it = begin(); - while (it != end()) { - if (it->nucleus() && it->nucleus()->asCharInset()) { - string s = charSequence(it, end()); - MathTextCodes c = it->nucleus()->asCharInset()->code(); - ar.push_back(MathAtom(new MathStringInset(s, c))); - it += s.size(); - } else { - ar.push_back(*it); - ++it; - } - } - return ar; -} - - -bool needAsterisk(MathAtom const &, MathAtom const &) -{ - return false; -} - - -MathArray MathArray::guessAsterisks() const -{ - if (size() <= 1) - return *this; - MathArray ar; - ar.push_back(*begin()); - for (const_iterator it = begin(), jt = begin()+1 ; jt != end(); ++it, ++jt) { - if (needAsterisk(*it, *jt)) - ar.push_back(MathAtom(new MathCharInset('*'))); - ar.push_back(*it); - } - ar.push_back(*end()); - return ar; -} - - -void MathArray::write(MathWriteInfo & wi) const -{ - MathArray ar = glueChars(); - for (const_iterator it = ar.begin(); it != ar.end(); ++it) { - MathInset const * p = it->nucleus(); - if (MathScriptInset const * q = ar.asScript(it)) { - q->write(p, wi); - ++it; - } else { - p->write(wi); - } - } -} - - -void MathArray::writeNormal(NormalStream & os) const -{ - MathArray ar = glueChars(); - for (const_iterator it = ar.begin(); it != ar.end(); ++it) { - MathInset const * p = it->nucleus(); - if (MathScriptInset const * q = ar.asScript(it)) { - q->writeNormal(p, os); - ++it; - } else - p->writeNormal(os); - } -} - - -void MathArray::octavize(OctaveStream & os) const -{ - MathArray ar = glueChars(); - for (const_iterator it = ar.begin(); it != ar.end(); ++it) { - MathInset const * p = it->nucleus(); - if (MathScriptInset const * q = ar.asScript(it)) { - q->octavize(p, os); - ++it; - } else - p->octavize(os); - } -} - - -void MathArray::maplize(MapleStream & os) const -{ - MathArray ar = glueChars(); - for (const_iterator it = ar.begin(); it != ar.end(); ++it) { - MathInset const * p = it->nucleus(); - if (MathScriptInset const * q = ar.asScript(it)) { - q->maplize(p, os); - ++it; - } else - p->maplize(os); - } -} - - -void MathArray::mathmlize(MathMLStream & os) const -{ - MathArray ar = glueChars(); - if (ar.size() == 0) - os << ""; - else if (ar.size() == 1) - os << ar.begin()->nucleus(); - else { - os << MTag("mrow"); - for (const_iterator it = ar.begin(); it != ar.end(); ++it) { - MathInset const * p = it->nucleus(); - if (MathScriptInset const * q = ar.asScript(it)) { - q->mathmlize(p, os); - ++it; - } else - p->mathmlize(os); - } - os << ETag("mrow"); - } -} - - void MathArray::validate(LaTeXFeatures & features) const { for (const_iterator it = begin(); it != end(); ++it) @@ -327,11 +175,3 @@ MathArray::iterator MathArray::end() { return bf_.end(); } - - -bool MathArray::isMatrix() const -{ - return size() == 1 && begin()->nucleus() && begin()->nucleus()->isMatrix(); -} - - diff --git a/src/mathed/math_data.h b/src/mathed/math_data.h index 007d75850e..eaca3d61eb 100644 --- a/src/mathed/math_data.h +++ b/src/mathed/math_data.h @@ -23,13 +23,7 @@ class MathScriptInset; class MathMacro; -class MathWriteInfo; -class MathMetricsInfo; class LaTeXFeatures; -class NormalStream; -class MapleStream; -class MathMLStream; -class OctaveStream; #ifdef __GNUG__ @@ -104,10 +98,6 @@ public: MathAtom & at(size_type pos); /// MathAtom const & at(size_type pos) const; - /// glue chars if necessary - void write(MathWriteInfo & os) const; - /// - void writeNormal(NormalStream &) const; /// void validate(LaTeXFeatures &) const; /// @@ -118,22 +108,6 @@ public: iterator begin(); /// iterator end(); - /// - MathScriptInset const * asScript(const_iterator it) const; - /// glues chars with the same attributes into MathStringInsets - MathArray glueChars() const; - /// insert asterisks in "suitable" places - MathArray guessAsterisks() const; - - /// interface to Octave - void octavize(OctaveStream &) const; - /// interface to Maple - void maplize(MapleStream &) const; - /// interface to MathML - void mathmlize(MathMLStream &) const; - - /// - bool isMatrix() const; private: /// Buffer diff --git a/src/mathed/math_decorationinset.C b/src/mathed/math_decorationinset.C index 49d0f923b9..08762d17b7 100644 --- a/src/mathed/math_decorationinset.C +++ b/src/mathed/math_decorationinset.C @@ -91,7 +91,7 @@ void MathDecorationInset::draw(Painter & pain, int x, int y) const } -void MathDecorationInset::write(MathWriteInfo & os) const +void MathDecorationInset::write(WriteStream & os) const { if (os.fragile && protect()) os << "\\protect"; @@ -99,7 +99,7 @@ void MathDecorationInset::write(MathWriteInfo & os) const } -void MathDecorationInset::writeNormal(NormalStream & os) const +void MathDecorationInset::normalize(NormalStream & os) const { os << "[deco " << name_.c_str() << ' ' << cell(0) << ']'; } diff --git a/src/mathed/math_decorationinset.h b/src/mathed/math_decorationinset.h index 5a18067de5..a0ff67b805 100644 --- a/src/mathed/math_decorationinset.h +++ b/src/mathed/math_decorationinset.h @@ -22,11 +22,11 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// void metrics(MathMetricsInfo const & st) const; /// - void writeNormal(NormalStream & os) const; + void normalize(NormalStream & os) const; /// bool isScriptable() const; diff --git a/src/mathed/math_deliminset.C b/src/mathed/math_deliminset.C index 4ada1f77cc..435b33f1f0 100644 --- a/src/mathed/math_deliminset.C +++ b/src/mathed/math_deliminset.C @@ -7,8 +7,8 @@ #include "math_deliminset.h" #include "math_parser.h" #include "math_support.h" -#include "support/LOstream.h" #include "math_mathmlstream.h" +#include "math_extern.h" MathDelimInset::MathDelimInset(string const & l, string const & r) @@ -42,14 +42,14 @@ string MathDelimInset::latexName(string const & name) } -void MathDelimInset::write(MathWriteInfo & os) const +void MathDelimInset::write(WriteStream & os) const { os << "\\left" << latexName(left_).c_str() << cell(0) << "\\right" << latexName(right_).c_str(); } -void MathDelimInset::writeNormal(NormalStream & os) const +void MathDelimInset::normalize(NormalStream & os) const { os << "[delim " << latexName(left_).c_str() << ' ' << latexName(right_).c_str() << ' ' << cell(0) << ']'; @@ -91,17 +91,13 @@ void MathDelimInset::draw(Painter & pain, int x, int y) const } -bool MathDelimInset::isMatrix() const -{ - return left_ == "(" && right_ == ")" && cell(0).size() == 1 && - cell(0).begin()->nucleus() && cell(0).begin()->nucleus()->asArrayInset(); -} - - void MathDelimInset::maplize(MapleStream & os) const { if (left_ == "|" && right_ == "|") { - if (cell(0).isMatrix()) + bool mat = + cell(0).size() == 1 && cell(0).begin()->nucleus() + && cell(0).begin()->nucleus()->asMatrixInset(); + if (mat) os << "linalg[det](" << cell(0) << ")"; else os << "abs(" << cell(0) << ")"; diff --git a/src/mathed/math_deliminset.h b/src/mathed/math_deliminset.h index e0a00d9b57..c896ee7ca3 100644 --- a/src/mathed/math_deliminset.h +++ b/src/mathed/math_deliminset.h @@ -20,28 +20,31 @@ public: /// MathInset * clone() const; /// - void draw(Painter &, int x, int y) const; + MathDelimInset * asDelimInset() { return this; } /// - void write(MathWriteInfo & os) const; - /// write normalized content - void writeNormal(NormalStream &) const; + MathDelimInset const * asDelimInset() const { return this; } /// void metrics(MathMetricsInfo const & st) const; /// - bool isMatrix() const; + void draw(Painter &, int x, int y) const; + + /// + void write(WriteStream & os) const; + /// write normalized content + void normalize(NormalStream &) const; /// void maplize(MapleStream &) const; /// void mathmlize(MathMLStream &) const; /// void octavize(OctaveStream &) const; -private: - /// - int dw() const; /// string left_; /// string right_; +private: + /// + int dw() const; /// static string latexName(string const & name); }; diff --git a/src/mathed/math_dotsinset.C b/src/mathed/math_dotsinset.C index 2fad8b4082..70e8de37b8 100644 --- a/src/mathed/math_dotsinset.C +++ b/src/mathed/math_dotsinset.C @@ -42,13 +42,13 @@ void MathDotsInset::metrics(MathMetricsInfo const & mi) const } -void MathDotsInset::write(MathWriteInfo & os) const +void MathDotsInset::write(WriteStream & os) const { os << '\\' << name_.c_str() << ' '; } -void MathDotsInset::writeNormal(NormalStream & os) const +void MathDotsInset::normalize(NormalStream & os) const { os << "[" << name_.c_str() << "] "; } diff --git a/src/mathed/math_dotsinset.h b/src/mathed/math_dotsinset.h index c13943d5ae..87869a8421 100644 --- a/src/mathed/math_dotsinset.h +++ b/src/mathed/math_dotsinset.h @@ -19,9 +19,9 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// void metrics(MathMetricsInfo const & st) const; protected: diff --git a/src/mathed/math_exfuncinset.C b/src/mathed/math_exfuncinset.C index 4be96200cb..8b08428c1e 100644 --- a/src/mathed/math_exfuncinset.C +++ b/src/mathed/math_exfuncinset.C @@ -17,13 +17,13 @@ MathInset * MathExFuncInset::clone() const } -void MathExFuncInset::write(MathWriteInfo & os) const +void MathExFuncInset::write(WriteStream & os) const { os << '\\' << name_.c_str() << '{' << cell(0) << '}'; } -void MathExFuncInset::writeNormal(NormalStream & os) const +void MathExFuncInset::normalize(NormalStream & os) const { os << '[' << name_.c_str() << ' ' << cell(0) << ']'; } diff --git a/src/mathed/math_exfuncinset.h b/src/mathed/math_exfuncinset.h index 951449673f..0c71ad57ec 100644 --- a/src/mathed/math_exfuncinset.h +++ b/src/mathed/math_exfuncinset.h @@ -14,9 +14,9 @@ public: /// MathInset * clone() const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// void metrics(MathMetricsInfo const & st) const; /// diff --git a/src/mathed/math_exintinset.C b/src/mathed/math_exintinset.C index edd8343c0b..2ad11b39df 100644 --- a/src/mathed/math_exintinset.C +++ b/src/mathed/math_exintinset.C @@ -18,14 +18,14 @@ MathInset * MathExIntInset::clone() const } -void MathExIntInset::write(MathWriteInfo & os) const +void MathExIntInset::write(WriteStream & os) const { scripts_.write(int_.nucleus(), os); os << core_ << "d" << diff_; } -void MathExIntInset::writeNormal(NormalStream & os) const +void MathExIntInset::normalize(NormalStream & os) const { //os << "[int " << scripts_ << ' ' << core_ << ' ' << diff_ << ']' } diff --git a/src/mathed/math_exintinset.h b/src/mathed/math_exintinset.h index 0d1214e985..c92497a3b9 100644 --- a/src/mathed/math_exintinset.h +++ b/src/mathed/math_exintinset.h @@ -18,9 +18,9 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// void maplize(MapleStream &) const; /// diff --git a/src/mathed/math_fracinset.C b/src/mathed/math_fracinset.C index 6577510700..f5c90d775c 100644 --- a/src/mathed/math_fracinset.C +++ b/src/mathed/math_fracinset.C @@ -41,7 +41,7 @@ void MathFracInset::draw(Painter & pain, int x, int y) const } -void MathFracInset::write(MathWriteInfo & os) const +void MathFracInset::write(WriteStream & os) const { if (atop_) os << '{' << cell(0) << "\\atop " << cell(1) << '}'; @@ -50,16 +50,13 @@ void MathFracInset::write(MathWriteInfo & os) const } -void MathFracInset::writeNormal(NormalStream & os) const +void MathFracInset::normalize(NormalStream & os) const { if (atop_) os << "[atop "; else os << "[frac "; - cell(0).writeNormal(os); - os << " "; - cell(1).writeNormal(os); - os << "] "; + os << cell(0) << ' ' << cell(1) << ']'; } diff --git a/src/mathed/math_fracinset.h b/src/mathed/math_fracinset.h index c66e9fb2f4..2068de0cd9 100644 --- a/src/mathed/math_fracinset.h +++ b/src/mathed/math_fracinset.h @@ -18,13 +18,14 @@ public: /// MathInset * clone() const; /// - void write(MathWriteInfo & os) const; - /// - void writeNormal(NormalStream &) const; - /// void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; + + /// + void write(WriteStream & os) const; + /// + void normalize(NormalStream &) const; /// void maplize(MapleStream &) const; /// diff --git a/src/mathed/math_funcinset.C b/src/mathed/math_funcinset.C index 6318a817b3..c2bf78c277 100644 --- a/src/mathed/math_funcinset.C +++ b/src/mathed/math_funcinset.C @@ -36,13 +36,13 @@ void MathFuncInset::setName(string const & n) } -void MathFuncInset::write(MathWriteInfo & os) const +void MathFuncInset::write(WriteStream & os) const { os << "\\" << name_.c_str() << ' '; } -void MathFuncInset::writeNormal(NormalStream & os) const +void MathFuncInset::normalize(NormalStream & os) const { os << "[func " << name_.c_str() << ']'; } diff --git a/src/mathed/math_funcinset.h b/src/mathed/math_funcinset.h index 4196e73d7b..42d4a2e055 100644 --- a/src/mathed/math_funcinset.h +++ b/src/mathed/math_funcinset.h @@ -23,9 +23,9 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(MathWriteInfo &) const; + void write(WriteStream &) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// string const & name() const; /// diff --git a/src/mathed/math_funcliminset.C b/src/mathed/math_funcliminset.C index 903a7697ed..79760d029e 100644 --- a/src/mathed/math_funcliminset.C +++ b/src/mathed/math_funcliminset.C @@ -20,13 +20,13 @@ bool MathFuncLimInset::isScriptable() const } -void MathFuncLimInset::write(MathWriteInfo & os) const +void MathFuncLimInset::write(WriteStream & os) const { os << '\\' << name_.c_str() << ' '; } -void MathFuncLimInset::writeNormal(NormalStream & os) const +void MathFuncLimInset::normalize(NormalStream & os) const { os << "[funclim " << name_.c_str() << ']'; } diff --git a/src/mathed/math_funcliminset.h b/src/mathed/math_funcliminset.h index 02c533e853..e36f417238 100644 --- a/src/mathed/math_funcliminset.h +++ b/src/mathed/math_funcliminset.h @@ -14,9 +14,9 @@ public: /// MathInset * clone() const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// void metrics(MathMetricsInfo const & st) const; /// diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index c9c5546d02..dac3caa54d 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -262,7 +262,7 @@ void MathGridInset::draw(Painter & pain, int x, int y) const } -void MathGridInset::write(MathWriteInfo & os) const +void MathGridInset::write(WriteStream & os) const { for (row_type row = 0; row < nrows(); ++row) { for (col_type col = 0; col < ncols(); ++col) @@ -272,7 +272,7 @@ void MathGridInset::write(MathWriteInfo & os) const } -void MathGridInset::writeNormal(NormalStream & os) const +void MathGridInset::normalize(NormalStream & os) const { os << "[grid "; for (row_type row = 0; row < nrows(); ++row) { @@ -583,48 +583,3 @@ std::vector return res; } - -void MathGridInset::maplize(MapleStream & os) const -{ - os << "array(["; - for (row_type row = 0; row < nrows(); ++row) { - if (row) - os << ','; - os << '['; - for (col_type col = 0; col < ncols(); ++col) { - if (col) - os << ','; - os << cell(index(row, col)); - } - os << ']'; - } - os << "])"; -} - - -void MathGridInset::mathmlize(MathMLStream & os) const -{ - os << MTag("mtable"); - for (row_type row = 0; row < nrows(); ++row) { - os << MTag("mtr"); - for (col_type col = 0; col < ncols(); ++col) - os << cell(index(row, col)); - os << ETag("mtr"); - } - os << ETag("mtable"); -} - - -void MathGridInset::octavize(OctaveStream & os) const -{ - os << '['; - for (row_type row = 0; row < nrows(); ++row) { - if (row) - os << ';'; - os << '['; - for (col_type col = 0; col < ncols(); ++col) - os << cell(index(row, col)) << ' '; - os << ']'; - } - os << ']'; -} diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index cc2414f42e..687b3fec03 100644 --- a/src/mathed/math_gridinset.h +++ b/src/mathed/math_gridinset.h @@ -64,10 +64,6 @@ public: /// MathGridInset(int m, int n, char valign, string const & halign); /// - void write(MathWriteInfo & os) const; - /// - void writeNormal(NormalStream &) const; - /// void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; @@ -149,12 +145,18 @@ public: /// void setDefaults(); + /// + void write(WriteStream & os) const; + /// + void normalize(NormalStream &) const; +/* /// void maplize(MapleStream &) const; /// void mathmlize(MathMLStream &) const; /// void octavize(OctaveStream &) const; +*/ protected: /// returns proper 'end of line' code for LaTeX diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index d6aea7975a..8cb6fc62c3 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -645,7 +645,7 @@ void MathHullInset::mutate(MathInsetTypes newtype) } -void MathHullInset::write(MathWriteInfo & os) const +void MathHullInset::write(WriteStream & os) const { header_write(os.os); @@ -667,10 +667,10 @@ void MathHullInset::write(MathWriteInfo & os) const } -void MathHullInset::writeNormal(NormalStream & os) const +void MathHullInset::normalize(NormalStream & os) const { os << "[formula " << normalName(getType()).c_str() << " "; - MathGridInset::writeNormal(os); + MathGridInset::normalize(os); os << "] "; } diff --git a/src/mathed/math_hullinset.h b/src/mathed/math_hullinset.h index 47a6bbeb8d..af063231ce 100644 --- a/src/mathed/math_hullinset.h +++ b/src/mathed/math_hullinset.h @@ -25,9 +25,9 @@ public: /// MathInset * clone() const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// void metrics(MathMetricsInfo const & st) const; /// @@ -51,9 +51,9 @@ public: /// void validate(LaTeXFeatures & features) const; /// identifies MatrixInsets - virtual MathHullInset const * asMatrixInset() const { return this; } - /// identifies MatrixInsets - virtual MathHullInset * asMatrixInset() { return this; } + virtual MathHullInset const * asHullInset() const { return this; } + /// identifies HullInset + virtual MathHullInset * asHullInset() { return this; } /// void addRow(row_type); diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index c5dfea37d9..37000b2583 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -44,7 +44,7 @@ int MathInset::height() const std::ostream & operator<<(std::ostream & os, MathInset const & inset) { - MathWriteInfo wi(0, os, false); + WriteStream wi(0, os, false); inset.write(wi); return os; } @@ -161,10 +161,10 @@ void MathInset::idxDeleteRange(idx_type, idx_type) {} -void MathInset::writeNormal(NormalStream & os) const +void MathInset::normalize(NormalStream & os) const { os << "[unknown "; - MathWriteInfo wi(0, os.os_, false); + WriteStream wi(0, os.os_, false); write(wi); os << "] "; } @@ -173,7 +173,7 @@ void MathInset::writeNormal(NormalStream & os) const void MathInset::dump() const { lyxerr << "---------------------------------------------\n"; - MathWriteInfo wi(0, lyxerr, false); + WriteStream wi(0, lyxerr, false); write(wi); lyxerr << "\n---------------------------------------------\n"; } @@ -212,7 +212,7 @@ void MathInset::draw(Painter &, int, int) const } -void MathInset::write(MathWriteInfo &) const +void MathInset::write(WriteStream &) const { lyxerr << "MathInset::write() called directly!\n"; } @@ -221,19 +221,19 @@ void MathInset::write(MathWriteInfo &) const void MathInset::octavize(OctaveStream & os) const { NormalStream ns(os.os_); - writeNormal(ns); + normalize(ns); } void MathInset::maplize(MapleStream & os) const { NormalStream ns(os.os_); - writeNormal(ns); + normalize(ns); } void MathInset::mathmlize(MathMLStream & os) const { NormalStream ns(os.os_); - writeNormal(ns); + normalize(ns); } diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index a710af65d7..315af30e24 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -41,13 +41,22 @@ class MathArrayInset; class MathBoxInset; class MathCharInset; +class MathDelimInset; class MathGridInset; -class MathNestInset; class MathHullInset; +class MathMatrixInset; +class MathNestInset; class MathScriptInset; class MathSpaceInset; class MathMacroTemplate; +class NormalStream; +class OctaveStream; +class MapleStream; +class MathMLStream; +class WriteStream; +class MathArray; + class LaTeXFeatures; class BufferView; class UpdatableInset; @@ -74,7 +83,7 @@ public: /// draw the object virtual void draw(Painter &, int x, int y) const; /// write LaTeX and Lyx code - virtual void write(MathWriteInfo & os) const; + virtual void write(WriteStream & os) const; /// reproduce itself virtual MathInset * clone() const = 0; ///substitutes macro arguments if necessary @@ -168,18 +177,24 @@ public: virtual MathScriptInset const * asScriptInset() const { return 0; } /// identifies ScriptInsets virtual MathScriptInset * asScriptInset() { return 0; } - /// identifies MatrixInsets - virtual MathHullInset const * asMatrixInset() const { return 0; } - /// identifies MatrixInsets - virtual MathHullInset * asMatrixInset() { return 0; } + /// identifies HullInsets + virtual MathHullInset const * asHullInset() const { return 0; } + /// identifies HullInsets + virtual MathHullInset * asHullInset() { return 0; } /// identifies SpaceInset virtual MathSpaceInset * asSpaceInset() { return 0; } /// identifies GridInset virtual MathGridInset * asGridInset() { return 0; } /// identifies ArrayInsets virtual MathArrayInset * asArrayInset() { return 0; } + /// identifies MatrixInsets + virtual MathMatrixInset const * asMatrixInset() const { return 0; } /// identifies BoxInsets virtual MathBoxInset * asBoxInset() { return 0; } + /// identifies DelimInsets + virtual MathDelimInset * asDelimInset() { return 0; } + /// identifies DelimInsets + virtual MathDelimInset const * asDelimInset() const { return 0; } /// identifies macro templates virtual MathMacroTemplate * asMacroTemplate() { return 0; } /// identifies hyperactive insets @@ -195,8 +210,6 @@ public: virtual bool isRelOp() const { return false; } /// virtual bool isMacro() const { return false; } - /// is this a matrix or matrix expression? - virtual bool isMatrix() const { return false; } /// virtual char getChar() const { return 0; } @@ -216,7 +229,7 @@ public: virtual void handleFont(MathTextCodes) {} /// write normalized content - virtual void writeNormal(NormalStream &) const; + virtual void normalize(NormalStream &) const; /// virtual void maplize(MapleStream &) const; /// diff --git a/src/mathed/math_kerninset.C b/src/mathed/math_kerninset.C index 4df5f78d77..cedf71ca34 100644 --- a/src/mathed/math_kerninset.C +++ b/src/mathed/math_kerninset.C @@ -44,13 +44,13 @@ void MathKernInset::metrics(MathMetricsInfo const &) const } -void MathKernInset::write(MathWriteInfo & os) const +void MathKernInset::write(WriteStream & os) const { os << "\\kern" << wid_.asLatexString().c_str() << " "; } -void MathKernInset::writeNormal(NormalStream & os) const +void MathKernInset::normalize(NormalStream & os) const { os << "[kern " << wid_.asLatexString().c_str() << "]"; } diff --git a/src/mathed/math_kerninset.h b/src/mathed/math_kerninset.h index d2b7aabe60..d6c65e4213 100644 --- a/src/mathed/math_kerninset.h +++ b/src/mathed/math_kerninset.h @@ -25,9 +25,9 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// void metrics(MathMetricsInfo const & st) const; private: diff --git a/src/mathed/math_lefteqninset.C b/src/mathed/math_lefteqninset.C index 8628abce06..99eb3159a2 100644 --- a/src/mathed/math_lefteqninset.C +++ b/src/mathed/math_lefteqninset.C @@ -39,16 +39,13 @@ void MathLefteqnInset::draw(Painter & pain, int x, int y) const } -void MathLefteqnInset::write(MathWriteInfo & os) const +void MathLefteqnInset::write(WriteStream & os) const { - os << "\\lefteqn{" << cell(0) << "}"; + os << "\\lefteqn{" << cell(0) << '}'; } -void MathLefteqnInset::writeNormal(NormalStream & os) const +void MathLefteqnInset::normalize(NormalStream & os) const { - os << "[lefteqn "; - MathWriteInfo wi(os.os_); - cell(0).write(wi); - os << "]"; + os << "[lefteqn " << cell(0) << ']'; } diff --git a/src/mathed/math_lefteqninset.h b/src/mathed/math_lefteqninset.h index 78525d8663..3c75e612a8 100644 --- a/src/mathed/math_lefteqninset.h +++ b/src/mathed/math_lefteqninset.h @@ -19,9 +19,9 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// void metrics(MathMetricsInfo const & st) const; }; diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index 707548ec2d..3d89fbad0b 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -155,13 +155,13 @@ void MathMacro::dump() const lyxerr << "\n macro: '" << this << "'\n"; lyxerr << " name: '" << name() << "'\n"; lyxerr << " template: '"; - MathWriteInfo wi(lyxerr); + WriteStream wi(lyxerr); tmplate_->write(wi); lyxerr << "'\n"; } -void MathMacro::write(MathWriteInfo & os) const +void MathMacro::write(WriteStream & os) const { os << '\\' << name(); for (idx_type i = 0; i < nargs(); ++i) @@ -171,14 +171,12 @@ void MathMacro::write(MathWriteInfo & os) const } -void MathMacro::writeNormal(NormalStream & os) const +void MathMacro::normalize(NormalStream & os) const { os << "[macro " << name() << " "; - for (idx_type i = 0; i < nargs(); ++i) { - cell(i).writeNormal(os); - os << ' '; - } - os << "] "; + for (idx_type i = 0; i < nargs(); ++i) + os << cell(i) << ' '; + os << ']'; } diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index ce9e3b928f..f80c18c561 100644 --- a/src/mathed/math_macro.h +++ b/src/mathed/math_macro.h @@ -48,9 +48,9 @@ public: /// MathInset * clone() const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// void dump() const; diff --git a/src/mathed/math_macroarg.C b/src/mathed/math_macroarg.C index 4a9bf76ce1..f28b77ab03 100644 --- a/src/mathed/math_macroarg.C +++ b/src/mathed/math_macroarg.C @@ -30,7 +30,7 @@ MathInset * MathMacroArgument::clone() const } -void MathMacroArgument::write(MathWriteInfo & os) const +void MathMacroArgument::write(WriteStream & os) const { os << '#' << number_; } @@ -58,7 +58,7 @@ void MathMacroArgument::draw(Painter & pain, int x, int y) const } -void MathMacroArgument::writeNormal(NormalStream & os) const +void MathMacroArgument::normalize(NormalStream & os) const { os << "[macroarg " << number_ << "] "; } diff --git a/src/mathed/math_macroarg.h b/src/mathed/math_macroarg.h index f001f21b3b..d0b4591966 100644 --- a/src/mathed/math_macroarg.h +++ b/src/mathed/math_macroarg.h @@ -22,9 +22,9 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// void substitute(MathMacro const & macro); /// diff --git a/src/mathed/math_macrotemplate.C b/src/mathed/math_macrotemplate.C index d179159284..0f1281f9e9 100644 --- a/src/mathed/math_macrotemplate.C +++ b/src/mathed/math_macrotemplate.C @@ -64,7 +64,7 @@ void MathMacroTemplate::draw(Painter & pain, int x, int y) const } -void MathMacroTemplate::write(MathWriteInfo & os) const +void MathMacroTemplate::write(WriteStream & os) const { os << "\n\\newcommand{\\" << name_.c_str() << '}'; if (numargs_ > 0) diff --git a/src/mathed/math_macrotemplate.h b/src/mathed/math_macrotemplate.h index 4cbe5106ee..bab64d1500 100644 --- a/src/mathed/math_macrotemplate.h +++ b/src/mathed/math_macrotemplate.h @@ -25,7 +25,7 @@ public: /// MathInset * clone() const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// Number of arguments int numargs() const; /// diff --git a/src/mathed/math_mathmlstream.C b/src/mathed/math_mathmlstream.C index 3f87f143b0..5e5dccd145 100644 --- a/src/mathed/math_mathmlstream.C +++ b/src/mathed/math_mathmlstream.C @@ -1,6 +1,7 @@ #include "math_inset.h" #include "math_mathmlstream.h" +#include "math_extern.h" MathMLStream::MathMLStream(std::ostream & os) @@ -17,7 +18,7 @@ MathMLStream & MathMLStream::operator<<(MathInset const * p) MathMLStream & MathMLStream::operator<<(MathArray const & ar) { - ar.mathmlize(*this); + mathmlize(ar, *this); return *this; } @@ -76,7 +77,7 @@ MapleStream & MapleStream::operator<<(MathInset const * p) MapleStream & MapleStream::operator<<(MathArray const & ar) { - ar.maplize(*this); + maplize(ar, *this); return *this; } @@ -95,6 +96,12 @@ MapleStream & MapleStream::operator<<(char c) } +MapleStream & MapleStream::operator<<(int i) +{ + os_ << i; + return *this; +} + ////////////////////////////////////////////////////////////////////// @@ -108,7 +115,7 @@ OctaveStream & OctaveStream::operator<<(MathInset const * p) OctaveStream & OctaveStream::operator<<(MathArray const & ar) { - ar.octavize(*this); + octavize(ar, *this); return *this; } @@ -132,14 +139,14 @@ OctaveStream & OctaveStream::operator<<(char c) NormalStream & NormalStream::operator<<(MathInset const * p) { - p->writeNormal(*this); + p->normalize(*this); return *this; } NormalStream & NormalStream::operator<<(MathArray const & ar) { - ar.writeNormal(*this); + normalize(ar, *this); return *this; } @@ -162,39 +169,39 @@ NormalStream & NormalStream::operator<<(char c) ////////////////////////////////////////////////////////////////////// -MathWriteInfo::MathWriteInfo +WriteStream::WriteStream (Buffer const * buffer_, std::ostream & os_, bool fragile_) : buffer(buffer_), os(os_), fragile(fragile_) {} -MathWriteInfo::MathWriteInfo(std::ostream & os_) +WriteStream::WriteStream(std::ostream & os_) : buffer(0), os(os_), fragile(false) {} -MathWriteInfo & MathWriteInfo::operator<<(MathInset const * p) +WriteStream & WriteStream::operator<<(MathInset const * p) { p->write(*this); return *this; } -MathWriteInfo & MathWriteInfo::operator<<(MathArray const & ar) +WriteStream & WriteStream::operator<<(MathArray const & ar) { - ar.write(*this); + write(ar, *this); return *this; } -MathWriteInfo & MathWriteInfo::operator<<(char const * s) +WriteStream & WriteStream::operator<<(char const * s) { os << s; return *this; } -MathWriteInfo & MathWriteInfo::operator<<(char c) +WriteStream & WriteStream::operator<<(char c) { os << c; return *this; diff --git a/src/mathed/math_mathmlstream.h b/src/mathed/math_mathmlstream.h index 1d1839359c..1af4f9ec77 100644 --- a/src/mathed/math_mathmlstream.h +++ b/src/mathed/math_mathmlstream.h @@ -78,6 +78,8 @@ struct MapleStream { MapleStream & operator<<(char const *); /// MapleStream & operator<<(char); + /// + MapleStream & operator<<(int); }; @@ -97,20 +99,20 @@ struct OctaveStream { }; -struct MathWriteInfo { +struct WriteStream { /// - MathWriteInfo(Buffer const * buffer_, std::ostream & os_, bool fragile_); + WriteStream(Buffer const * buffer_, std::ostream & os_, bool fragile_); /// - explicit MathWriteInfo(std::ostream & os_); + explicit WriteStream(std::ostream & os_); /// - MathWriteInfo & operator<<(MathInset const *); + WriteStream & operator<<(MathInset const *); /// - MathWriteInfo & operator<<(MathArray const &); + WriteStream & operator<<(MathArray const &); /// - MathWriteInfo & operator<<(char const *); + WriteStream & operator<<(char const *); /// - MathWriteInfo & operator<<(char); + WriteStream & operator<<(char); /// Buffer const * buffer; diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C new file mode 100644 index 0000000000..d8a02da555 --- /dev/null +++ b/src/mathed/math_matrixinset.C @@ -0,0 +1,71 @@ +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "math_matrixinset.h" +#include "math_parser.h" +#include "math_mathmlstream.h" +#include "Lsstream.h" + + +MathMatrixInset::MathMatrixInset(MathArrayInset const & p) + : MathArrayInset(p) +{} + + +MathInset * MathMatrixInset::clone() const +{ + return new MathMatrixInset(*this); +} + + +void MathMatrixInset::write(WriteStream & os) const +{ + MathArrayInset::write(os); +} + + +void MathMatrixInset::normalize(NormalStream & os) const +{ + MathArrayInset::normalize(os); +} + + +void MathMatrixInset::maplize(MapleStream & os) const +{ + os << "matrix(" << int(nrows()) << ',' << int(ncols()) << ",["; + for (idx_type idx = 0; idx < nargs(); ++idx) { + if (idx) + os << ','; + os << cell(idx); + } + os << "])"; +} + + +void MathMatrixInset::mathmlize(MathMLStream & os) const +{ + os << MTag("mtable"); + for (row_type row = 0; row < nrows(); ++row) { + os << MTag("mtr"); + for (col_type col = 0; col < ncols(); ++col) + os << cell(index(row, col)); + os << ETag("mtr"); + } + os << ETag("mtable"); +} + + +void MathMatrixInset::octavize(OctaveStream & os) const +{ + os << '['; + for (row_type row = 0; row < nrows(); ++row) { + if (row) + os << ';'; + os << '['; + for (col_type col = 0; col < ncols(); ++col) + os << cell(index(row, col)) << ' '; + os << ']'; + } + os << ']'; +} diff --git a/src/mathed/math_matrixinset.h b/src/mathed/math_matrixinset.h new file mode 100644 index 0000000000..f4f2a0aceb --- /dev/null +++ b/src/mathed/math_matrixinset.h @@ -0,0 +1,38 @@ +// -*- C++ -*- +#ifndef MATH_MATRIXINSET_H +#define MATH_MATRIXINSET_H + +#include "math_arrayinset.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +// "shortcut" for DelimInset("(",ArrayInset,")") + +class MathMatrixInset : public MathArrayInset { +public: + /// + MathMatrixInset(MathArrayInset const &); + /// + MathMatrixInset(string const & str); + /// + MathInset * clone() const; + /// + void metrics(MathMetricsInfo const &) const {} + /// identifies MatrixInsets + MathMatrixInset const * asMatrixInset() const { return this; } + + /// + void write(WriteStream & os) const; + /// + void normalize(NormalStream &) const; + /// + void maplize(MapleStream &) const; + /// + void mathmlize(MathMLStream &) const; + /// + void octavize(OctaveStream &) const; +}; + +#endif diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 5738458776..03c1c2f04e 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -136,7 +136,7 @@ bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const void MathNestInset::dump() const { - MathWriteInfo os(lyxerr); + WriteStream os(lyxerr); os << "---------------------------------------------\n"; write(os); os << "\n"; diff --git a/src/mathed/math_notinset.C b/src/mathed/math_notinset.C index bedef35dab..1929286e12 100644 --- a/src/mathed/math_notinset.C +++ b/src/mathed/math_notinset.C @@ -14,13 +14,13 @@ MathInset * MathNotInset::clone() const } -void MathNotInset::write(MathWriteInfo & os) const +void MathNotInset::write(WriteStream & os) const { os << "\\not "; } -void MathNotInset::writeNormal(NormalStream & os) const +void MathNotInset::normalize(NormalStream & os) const { os << "[not] "; } diff --git a/src/mathed/math_notinset.h b/src/mathed/math_notinset.h index faf1e731fb..70470764b3 100644 --- a/src/mathed/math_notinset.h +++ b/src/mathed/math_notinset.h @@ -13,9 +13,9 @@ public: /// MathInset * clone() const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// void metrics(MathMetricsInfo const & st) const; /// diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 5384cb5625..b9bc7e43e3 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -492,7 +492,7 @@ bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost) } if (outmost) { - MathHullInset * m = t->asMatrixInset(); + MathHullInset * m = t->asHullInset(); if (!m) { lyxerr << "error in Parser::parse_lines() 2\n"; return false; @@ -579,7 +579,7 @@ bool Parser::parse_normal(MathAtom & matrix) if (n.cat() == catMath) { // TeX's $$...$$ syntax for displayed math matrix = MathAtom(new MathHullInset(LM_OT_EQUATION)); - MathHullInset * p = matrix->asMatrixInset(); + MathHullInset * p = matrix->asHullInset(); parse_into(p->cell(0), 0); p->numbered(0, curr_num_); p->label(0, curr_label_); @@ -603,7 +603,7 @@ bool Parser::parse_normal(MathAtom & matrix) curr_num_ = 0; curr_label_.erase(); matrix = MathAtom(new MathHullInset(LM_OT_EQUATION)); - MathHullInset * p = matrix->asMatrixInset(); + MathHullInset * p = matrix->asHullInset(); parse_into(p->cell(0), 0); p->numbered(0, curr_num_); p->label(0, curr_label_); @@ -621,7 +621,7 @@ bool Parser::parse_normal(MathAtom & matrix) curr_num_ = (name == "equation"); curr_label_.erase(); matrix = MathAtom(new MathHullInset(LM_OT_EQUATION)); - MathHullInset * p = matrix->asMatrixInset(); + MathHullInset * p = matrix->asHullInset(); parse_into(p->cell(0), FLAG_END); p->numbered(0, curr_num_); p->label(0, curr_label_); diff --git a/src/mathed/math_rootinset.C b/src/mathed/math_rootinset.C index 187a9529e3..edd10dadf4 100644 --- a/src/mathed/math_rootinset.C +++ b/src/mathed/math_rootinset.C @@ -58,19 +58,15 @@ void MathRootInset::draw(Painter & pain, int x, int y) const } -void MathRootInset::write(MathWriteInfo & os) const +void MathRootInset::write(WriteStream & os) const { os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}'; } -void MathRootInset::writeNormal(NormalStream & os) const +void MathRootInset::normalize(NormalStream & os) const { - os << "[root "; - cell(1).writeNormal(os); - os << " "; - cell(0).writeNormal(os); - os << "]"; + os << "[root " << cell(1) << ' ' << cell(1) << ']'; } @@ -102,5 +98,5 @@ void MathRootInset::octavize(OctaveStream & os) const void MathRootInset::mathmlize(MathMLStream & os) const { - os << "" << cell(1) << cell(0) << ""; + os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot"); } diff --git a/src/mathed/math_rootinset.h b/src/mathed/math_rootinset.h index 200ddc7cc7..209b9720f2 100644 --- a/src/mathed/math_rootinset.h +++ b/src/mathed/math_rootinset.h @@ -32,17 +32,18 @@ public: /// MathInset * clone() const; /// - void draw(Painter &, int x, int y) const; - /// - void write(MathWriteInfo & os) const; + bool idxUp(int & idx, int & pos) const; /// - void writeNormal(NormalStream &) const; + bool idxDown(int & idx, int & pos) const; /// void metrics(MathMetricsInfo const & st) const; /// - bool idxUp(int & idx, int & pos) const; + void draw(Painter &, int x, int y) const; + /// - bool idxDown(int & idx, int & pos) const; + void write(WriteStream & os) const; + /// + void normalize(NormalStream &) const; /// void mathmlize(MathMLStream &) const; /// diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index e675d75a84..cb7eed1f1c 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -272,14 +272,14 @@ bool MathScriptInset::idxLeft(MathInset::idx_type &, } -void MathScriptInset::write(MathWriteInfo & os) const +void MathScriptInset::write(WriteStream & os) const { //lyxerr << "unexpected call to MathScriptInset::write()\n"; write(0, os); } -void MathScriptInset::write(MathInset const * nuc, MathWriteInfo & os) const +void MathScriptInset::write(MathInset const * nuc, WriteStream & os) const { if (nuc) { os << nuc; @@ -301,14 +301,14 @@ void MathScriptInset::write(MathInset const * nuc, MathWriteInfo & os) const } -void MathScriptInset::writeNormal(NormalStream & os) const +void MathScriptInset::normalize(NormalStream & os) const { - //lyxerr << "unexpected call to MathScriptInset::writeNormal()\n"; - writeNormal(0, os); + //lyxerr << "unexpected call to MathScriptInset::normalize()\n"; + normalize(0, os); } -void MathScriptInset::writeNormal(MathInset const * nuc, NormalStream & os) const +void MathScriptInset::normalize(MathInset const * nuc, NormalStream & os) const { bool d = hasDown() && down().data_.size(); bool u = hasUp() && up().data_.size(); diff --git a/src/mathed/math_scriptinset.h b/src/mathed/math_scriptinset.h index 904cbe0c2e..fe9630a518 100644 --- a/src/mathed/math_scriptinset.h +++ b/src/mathed/math_scriptinset.h @@ -21,9 +21,9 @@ public: /// MathInset * clone() const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream & os) const; + void normalize(NormalStream & os) const; /// void metrics(MathMetricsInfo const & st) const; /// @@ -78,9 +78,9 @@ public: void ensure(bool up); /// - void write(MathInset const * nuc, MathWriteInfo & os) const; + void write(MathInset const * nuc, WriteStream & os) const; /// - void writeNormal(MathInset const * nuc, NormalStream & os) const; + void normalize(MathInset const * nuc, NormalStream & os) const; /// void octavize(MathInset const * nuc, OctaveStream & os) const; /// diff --git a/src/mathed/math_sizeinset.C b/src/mathed/math_sizeinset.C index 68219334bf..86edc28163 100644 --- a/src/mathed/math_sizeinset.C +++ b/src/mathed/math_sizeinset.C @@ -35,13 +35,13 @@ void MathSizeInset::metrics(MathMetricsInfo const & mi) const } -void MathSizeInset::write(MathWriteInfo & os) const +void MathSizeInset::write(WriteStream & os) const { os << "{\\" << key_->name.c_str() << ' ' << cell(0) << '}'; } -void MathSizeInset::writeNormal(NormalStream & os) const +void MathSizeInset::normalize(NormalStream & os) const { os << "[" << key_->name.c_str() << ' ' << cell(0) << ']'; } diff --git a/src/mathed/math_sizeinset.h b/src/mathed/math_sizeinset.h index e1b0e50fcf..9fefc55db0 100644 --- a/src/mathed/math_sizeinset.h +++ b/src/mathed/math_sizeinset.h @@ -26,9 +26,9 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; private: /// diff --git a/src/mathed/math_spaceinset.C b/src/mathed/math_spaceinset.C index 2355e3c05b..8e32f7c8b3 100644 --- a/src/mathed/math_spaceinset.C +++ b/src/mathed/math_spaceinset.C @@ -21,14 +21,14 @@ MathInset * MathSpaceInset::clone() const } -void MathSpaceInset::write(MathWriteInfo & os) const +void MathSpaceInset::write(WriteStream & os) const { if (space_ >= 0 && space_ < 6) os << '\\' << latex_mathspace[space_] << ' '; } -void MathSpaceInset::writeNormal(NormalStream & os) const +void MathSpaceInset::normalize(NormalStream & os) const { os << "[space " << space_ << "] "; } diff --git a/src/mathed/math_spaceinset.h b/src/mathed/math_spaceinset.h index 21fee9249c..b9554ee4d4 100644 --- a/src/mathed/math_spaceinset.h +++ b/src/mathed/math_spaceinset.h @@ -19,9 +19,9 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// void metrics(MathMetricsInfo const & st) const; /// diff --git a/src/mathed/math_specialcharinset.C b/src/mathed/math_specialcharinset.C index 0dbe004b41..fe66cfa69b 100644 --- a/src/mathed/math_specialcharinset.C +++ b/src/mathed/math_specialcharinset.C @@ -48,13 +48,13 @@ void MathSpecialCharInset::draw(Painter & pain, int x, int y) const } -void MathSpecialCharInset::write(MathWriteInfo & os) const +void MathSpecialCharInset::write(WriteStream & os) const { os << "\\" << char_; } -void MathSpecialCharInset::writeNormal(NormalStream & os) const +void MathSpecialCharInset::normalize(NormalStream & os) const { os << "\\" << char_; } diff --git a/src/mathed/math_specialcharinset.h b/src/mathed/math_specialcharinset.h index 0adb5267ae..0b5a72be42 100644 --- a/src/mathed/math_specialcharinset.h +++ b/src/mathed/math_specialcharinset.h @@ -24,9 +24,9 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// int ascent() const; /// diff --git a/src/mathed/math_splitinset.C b/src/mathed/math_splitinset.C index 6f9d9c8e9b..02a0d567b5 100644 --- a/src/mathed/math_splitinset.C +++ b/src/mathed/math_splitinset.C @@ -19,7 +19,7 @@ MathInset * MathSplitInset::clone() const } -void MathSplitInset::write(MathWriteInfo & os) const +void MathSplitInset::write(WriteStream & os) const { if (os.fragile) os << "\\protect"; diff --git a/src/mathed/math_splitinset.h b/src/mathed/math_splitinset.h index 7c188eca93..8704d37429 100644 --- a/src/mathed/math_splitinset.h +++ b/src/mathed/math_splitinset.h @@ -16,7 +16,7 @@ public: /// MathInset * clone() const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// int defaultColSpace(int) { return 0; } /// diff --git a/src/mathed/math_sqrtinset.C b/src/mathed/math_sqrtinset.C index 65337dc5c6..65023a12b4 100644 --- a/src/mathed/math_sqrtinset.C +++ b/src/mathed/math_sqrtinset.C @@ -43,17 +43,15 @@ void MathSqrtInset::draw(Painter & pain, int x, int y) const } -void MathSqrtInset::write(MathWriteInfo & os) const +void MathSqrtInset::write(WriteStream & os) const { os << "\\sqrt{" << cell(0) << '}'; } -void MathSqrtInset::writeNormal(NormalStream & os) const +void MathSqrtInset::normalize(NormalStream & os) const { - os << "[sqrt "; - cell(0).writeNormal(os); - os << "]"; + os << "[sqrt " << cell(0) << ']'; } @@ -65,5 +63,5 @@ void MathSqrtInset::maplize(MapleStream & os) const void MathSqrtInset::mathmlize(MathMLStream & os) const { - os << "" << cell(0) << ""; + os << MTag("msqrt") << cell(0) << ETag("msqrt"); } diff --git a/src/mathed/math_sqrtinset.h b/src/mathed/math_sqrtinset.h index ac774cbe7b..57517e4959 100644 --- a/src/mathed/math_sqrtinset.h +++ b/src/mathed/math_sqrtinset.h @@ -20,11 +20,12 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(MathWriteInfo & os) const; + void metrics(MathMetricsInfo const & st) const; + /// - void writeNormal(NormalStream &) const; + void write(WriteStream & os) const; /// - void metrics(MathMetricsInfo const & st) const; + void normalize(NormalStream &) const; /// void maplize(MapleStream &) const; /// diff --git a/src/mathed/math_stackrelinset.C b/src/mathed/math_stackrelinset.C index 72f7b981b7..75ccb8710a 100644 --- a/src/mathed/math_stackrelinset.C +++ b/src/mathed/math_stackrelinset.C @@ -37,17 +37,13 @@ void MathStackrelInset::draw(Painter & pain, int x, int y) const } -void MathStackrelInset::write(MathWriteInfo & os) const +void MathStackrelInset::write(WriteStream & os) const { os << "\\stackrel{" << cell(0) << "}{" << cell(1) << '}'; } -void MathStackrelInset::writeNormal(NormalStream & os) const +void MathStackrelInset::normalize(NormalStream & os) const { - os << "[stackrel "; - cell(0).writeNormal(os); - os << " "; - cell(1).writeNormal(os); - os << "] "; + os << "[stackrel " << cell(0) << ' ' << cell(1) << ']'; } diff --git a/src/mathed/math_stackrelinset.h b/src/mathed/math_stackrelinset.h index e1122bfa81..699dffe402 100644 --- a/src/mathed/math_stackrelinset.h +++ b/src/mathed/math_stackrelinset.h @@ -18,13 +18,14 @@ public: /// MathInset * clone() const; /// - void write(MathWriteInfo & os) const; - /// - void writeNormal(NormalStream &) const; - /// void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; + + /// + void write(WriteStream & os) const; + /// + void normalize(NormalStream &) const; }; #endif diff --git a/src/mathed/math_stringinset.C b/src/mathed/math_stringinset.C index 68c4dab16e..b36639e0ba 100644 --- a/src/mathed/math_stringinset.C +++ b/src/mathed/math_stringinset.C @@ -55,7 +55,7 @@ void MathStringInset::draw(Painter & pain, int x, int y) const } -void MathStringInset::write(MathWriteInfo & os) const +void MathStringInset::write(WriteStream & os) const { if (math_font_name(code_)) os << '\\' << math_font_name(code_) << '{' << str_.c_str() << '}'; @@ -64,7 +64,7 @@ void MathStringInset::write(MathWriteInfo & os) const } -void MathStringInset::writeNormal(NormalStream & os) const +void MathStringInset::normalize(NormalStream & os) const { os << "[string " << str_.c_str() << ' ' << "mathalpha" << "]"; } diff --git a/src/mathed/math_stringinset.h b/src/mathed/math_stringinset.h index 1d4e28f095..79774ff757 100644 --- a/src/mathed/math_stringinset.h +++ b/src/mathed/math_stringinset.h @@ -23,9 +23,9 @@ public: /// void draw(Painter &, int x, int y) const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// int ascent() const; /// diff --git a/src/mathed/math_symbolinset.C b/src/mathed/math_symbolinset.C index b9e84c9c80..e7f000f64c 100644 --- a/src/mathed/math_symbolinset.C +++ b/src/mathed/math_symbolinset.C @@ -16,13 +16,13 @@ MathInset * MathSymbolInset::clone() const } -void MathSymbolInset::write(MathWriteInfo & os) const +void MathSymbolInset::write(WriteStream & os) const { os << '\\' << sym_->name.c_str() << ' '; } -void MathSymbolInset::writeNormal(NormalStream & os) const +void MathSymbolInset::normalize(NormalStream & os) const { os << "[symbol " << sym_->name.c_str() << "]"; } diff --git a/src/mathed/math_symbolinset.h b/src/mathed/math_symbolinset.h index 7514c0a7be..5c1a6a348d 100644 --- a/src/mathed/math_symbolinset.h +++ b/src/mathed/math_symbolinset.h @@ -18,9 +18,9 @@ public: /// MathInset * clone() const; /// - void write(MathWriteInfo & os) const; + void write(WriteStream & os) const; /// - void writeNormal(NormalStream &) const; + void normalize(NormalStream &) const; /// void metrics(MathMetricsInfo const & st) const; /// diff --git a/src/mathed/math_xdata.C b/src/mathed/math_xdata.C index f0deef476e..cffec88712 100644 --- a/src/mathed/math_xdata.C +++ b/src/mathed/math_xdata.C @@ -4,14 +4,15 @@ #pragma implementation #endif -#include "math_inset.h" #include "math_scriptinset.h" #include "math_support.h" -#include "math_defs.h" #include "Painter.h" #include "debug.h" +extern MathScriptInset const * asScript(MathArray::const_iterator it); + + MathXArray::MathXArray() : width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), size_() {} @@ -32,7 +33,8 @@ void MathXArray::metrics(MathMetricsInfo const & st) const for (const_iterator it = begin(); it != end(); ++it) { MathInset const * p = it->nucleus(); - if (MathScriptInset const * q = data_.asScript(it)) { + MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it); + if (q) { q->metrics(p, st); ascent_ = std::max(ascent_, q->ascent(p)); descent_ = std::max(descent_, q->descent(p)); @@ -62,7 +64,8 @@ void MathXArray::draw(Painter & pain, int x, int y) const for (const_iterator it = begin(); it != end(); ++it) { MathInset const * p = it->nucleus(); - if (MathScriptInset const * q = data_.asScript(it)) { + MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it); + if (q) { q->draw(p, pain, x, y); x += q->width(p); ++it; @@ -80,7 +83,8 @@ int MathXArray::pos2x(size_type targetpos) const const_iterator target = std::min(begin() + targetpos, end()); for (const_iterator it = begin(); it < target; ++it) { MathInset const * p = it->nucleus(); - if (MathScriptInset const * q = data_.asScript(it)) { + MathScriptInset const * q = (it + 1 == end()) ? 0 : asScript(it); + if (q) { ++it; if (it < target) x += q->width(p); @@ -103,7 +107,10 @@ MathArray::size_type MathXArray::x2pos(int targetx) const int wid = 0; MathInset const * p = it->nucleus(); - if (MathScriptInset const * q = data_.asScript(it)) { + MathScriptInset const * q = 0; + if (it + 1 != end()) + q = asScript(it); + if (q) { wid = q->width(p); ++it; } else -- 2.39.2