From c649284611c4198c9d70be8a16d153cdf1ec0700 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 25 Jun 2002 13:19:50 +0000 Subject: [PATCH] several smallish changes/bugfixes/left overs from Porto git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4474 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formulabase.C | 2 +- src/mathed/math_atom.C | 16 ++++-- src/mathed/math_atom.h | 2 + src/mathed/math_cursor.C | 5 +- src/mathed/math_deliminset.C | 32 +++++++++++ src/mathed/math_deliminset.h | 2 + src/mathed/math_exfuncinset.C | 7 +++ src/mathed/math_exfuncinset.h | 2 + src/mathed/math_extern.C | 32 +++++++---- src/mathed/math_factory.C | 4 +- src/mathed/math_funcinset.C | 87 ------------------------------ src/mathed/math_funcinset.h | 49 ----------------- src/mathed/math_parser.C | 3 +- src/mathed/math_spaceinset.C | 19 +++++-- src/mathed/math_spaceinset.h | 2 + src/mathed/math_specialcharinset.C | 44 --------------- src/mathed/math_specialcharinset.h | 35 ------------ src/mathed/math_stringinset.C | 4 +- src/mathed/math_support.C | 22 -------- src/mathed/math_support.h | 2 - src/mathed/math_symbolinset.C | 2 + 21 files changed, 108 insertions(+), 265 deletions(-) delete mode 100644 src/mathed/math_funcinset.C delete mode 100644 src/mathed/math_funcinset.h delete mode 100644 src/mathed/math_specialcharinset.C delete mode 100644 src/mathed/math_specialcharinset.h diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 00df0bec99..dd2e3ddc3e 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -675,7 +675,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, case LFUN_PROTECTEDSPACE: case LFUN_MATH_SPACE: bv->lockedInsetStoreUndo(Undo::EDIT); - mathcursor->insert(MathAtom(new MathSpaceInset(1))); + mathcursor->insert(MathAtom(new MathSpaceInset(","))); updateLocal(bv, true); break; diff --git a/src/mathed/math_atom.C b/src/mathed/math_atom.C index 76fc538851..a8e2815a0f 100644 --- a/src/mathed/math_atom.C +++ b/src/mathed/math_atom.C @@ -34,20 +34,26 @@ MathAtom::MathAtom(MathInset * p) {} -MathAtom::MathAtom(MathAtom const & p) - : nucleus_(p.nucleus_ ? p.nucleus_->clone() : 0) +MathAtom::MathAtom(MathAtom const & at) + : nucleus_(at.nucleus_ ? at.nucleus_->clone() : 0) {} -void MathAtom::operator=(MathAtom const & p) +void MathAtom::operator=(MathAtom const & at) { - if (&p == this) + if (&at == this) return; - MathAtom tmp(p); + MathAtom tmp(at); std::swap(tmp.nucleus_, nucleus_); } +void MathAtom::operator=(MathInset * p) +{ + reset(p); +} + + MathAtom::~MathAtom() { delete nucleus_; diff --git a/src/mathed/math_atom.h b/src/mathed/math_atom.h index 69d8b47c8d..04cf2a391d 100644 --- a/src/mathed/math_atom.h +++ b/src/mathed/math_atom.h @@ -46,6 +46,8 @@ public: /// assignment invokes nucleus_->clone() void operator=(MathAtom const &); /// change inset under the hood + void operator=(MathInset * p); + /// change inset under the hood void reset(MathInset * p); /// access to the inset (checked with gprof) MathInset * nucleus() const { return nucleus_; } diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 33ce2d78b7..32d6876b65 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -1419,9 +1419,10 @@ bool MathCursor::interpret(char c) return true; } - // leave macro mode and try again + // leave macro mode and try again if necessary macroModeClose(); - interpret(c); + if (c != ' ') + interpret(c); return true; } diff --git a/src/mathed/math_deliminset.C b/src/mathed/math_deliminset.C index 6fa100606c..5882a0cd05 100644 --- a/src/mathed/math_deliminset.C +++ b/src/mathed/math_deliminset.C @@ -14,12 +14,44 @@ using std::max; +namespace { + +string convertDelimToLatexName(string const & name) +{ + if (name == "(") + return name; + if (name == "[") + return name; + if (name == ".") + return name; + if (name == ")") + return name; + if (name == "]") + return name; + if (name == "/") + return name; + if (name == "|") + return name; + return "\\" + name + " "; +} + +} + + MathDelimInset::MathDelimInset(string const & l, string const & r) : MathNestInset(1), left_(l), right_(r) {} +MathDelimInset::MathDelimInset + (string const & l, string const & r, MathArray const & ar) + : MathNestInset(1), left_(l), right_(r) +{ + cell(0) = ar; +} + + MathInset * MathDelimInset::clone() const { return new MathDelimInset(*this); diff --git a/src/mathed/math_deliminset.h b/src/mathed/math_deliminset.h index 2f8b7047cb..d2c0d4d5ea 100644 --- a/src/mathed/math_deliminset.h +++ b/src/mathed/math_deliminset.h @@ -18,6 +18,8 @@ public: /// MathDelimInset(string const & left, string const & right); /// + MathDelimInset(string const & left, string const & right, MathArray const &); + /// MathInset * clone() const; /// MathDelimInset * asDelimInset() { return this; } diff --git a/src/mathed/math_exfuncinset.C b/src/mathed/math_exfuncinset.C index ceb4d621fb..0238540a82 100644 --- a/src/mathed/math_exfuncinset.C +++ b/src/mathed/math_exfuncinset.C @@ -11,6 +11,13 @@ MathExFuncInset::MathExFuncInset(string const & name) {} +MathExFuncInset::MathExFuncInset(string const & name, MathArray const & ar) + : MathNestInset(1), name_(name) +{ + cell(0) = ar; +} + + MathInset * MathExFuncInset::clone() const { return new MathExFuncInset(*this); diff --git a/src/mathed/math_exfuncinset.h b/src/mathed/math_exfuncinset.h index 08d4a94620..afc15927c9 100644 --- a/src/mathed/math_exfuncinset.h +++ b/src/mathed/math_exfuncinset.h @@ -12,6 +12,8 @@ public: /// explicit MathExFuncInset(string const & name); /// + MathExFuncInset(string const & name, MathArray const & ar); + /// MathInset * clone() const; /// void metrics(MathMetricsInfo & st) const; diff --git a/src/mathed/math_extern.C b/src/mathed/math_extern.C index be0a463790..f595b1b168 100644 --- a/src/mathed/math_extern.C +++ b/src/mathed/math_extern.C @@ -331,18 +331,32 @@ void extractExps(MathArray & ar) if (!sup || sup->hasDown()) continue; - // create a proper exp-inset as replacement - MathExFuncInset * func = new MathExFuncInset("exp"); - func->cell(0) = sup->cell(1); - - // clean up - (*it).reset(func); + // create a proper exp-inset as replacement + *it = new MathExFuncInset("exp", sup->cell(1)); ar.erase(it + 1); } //lyxerr << "\nExps to: " << ar << "\n"; } +// +// extract det(...) from |matrix| +// +void extractDets(MathArray & ar) +{ + //lyxerr << "\ndet from: " << ar << "\n"; + for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) { + MathDelimInset * del = (*it)->asDelimInset(); + if (!del) + continue; + if (!del->isAbs()) + continue; + *it = new MathExFuncInset("det", del->cell(0)); + } + //lyxerr << "\ndet to: " << ar << "\n"; +} + + // // search numbers // @@ -404,9 +418,7 @@ bool testCloseParan(MathInset * p) MathInset * replaceDelims(const MathArray & ar) { - MathDelimInset * del = new MathDelimInset("(", ")"); - del->cell(0) = ar; - return del; + return new MathDelimInset("(", ")", ar); } @@ -761,6 +773,7 @@ void extractStructure(MathArray & ar) extractMatrices(ar); extractDelims(ar); extractFunctions(ar); + extractDets(ar); extractIntegrals(ar); extractSums(ar); extractDiff(ar); @@ -911,6 +924,7 @@ namespace { ms << ar; string expr = os.str().c_str(); lyxerr << "ar: '" << ar << "'\n"; + lyxerr << "ms: '" << os.str() << "'\n"; for (int i = 0; i < 100; ++i) { // at most 100 attempts // try to fix missing '*' the hard way by using mint diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index bf37981bf7..7b6f49e5e7 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -321,8 +321,8 @@ MathAtom createMathInset(string const & s) return MathAtom(new MathUndersetInset); if (inset == "decoration") return MathAtom(new MathDecorationInset(l->name)); - //if (inset == "space") - // return MathAtom(new MathSpaceInset(l->id)); + if (inset == "space") + return MathAtom(new MathSpaceInset(l->name)); if (inset == "dots") return MathAtom(new MathDotsInset(l->name)); if (inset == "box") diff --git a/src/mathed/math_funcinset.C b/src/mathed/math_funcinset.C deleted file mode 100644 index e687e48720..0000000000 --- a/src/mathed/math_funcinset.C +++ /dev/null @@ -1,87 +0,0 @@ -#include - -#ifdef __GNUG__ -#pragma implementation -#endif - -#include "math_funcinset.h" -#include "frontends/font_metrics.h" -#include "frontends/Painter.h" -#include "math_support.h" -#include "math_mathmlstream.h" -#include "math_streamstr.h" - - -extern LyXFont WhichFont(short type, int size); - - -MathFuncInset::MathFuncInset(string const & nm) - : name_(nm) -{} - - -MathInset * MathFuncInset::clone() const -{ - return new MathFuncInset(*this); -} - - -string const & MathFuncInset::name() const -{ - return name_; -} - - -void MathFuncInset::setName(string const & n) -{ - name_ = n; -} - - -void MathFuncInset::metrics(MathMetricsInfo & mi) const -{ - mathed_string_dim(mi.font_, name_, ascent_, descent_, width_); -} - - -void MathFuncInset::draw(Painter & pain, int x, int y) const -{ - drawStr(pain, mi.font_, x, y, name_); -} - - -bool MathFuncInset::match(MathInset * p) const -{ - MathFuncInset const * q = p->asFuncInset(); - return q && name_ == q->name_; -} - - -void MathFuncInset::maplize(MapleStream & os) const -{ - os << ' ' << name_; -} - - -void MathFuncInset::mathmlize(MathMLStream & os) const -{ - os << MTag("mi") << name_ << ETag("mi"); -} - - -void MathFuncInset::octavize(OctaveStream & os) const -{ - os << ' ' << name_; -} - - -void MathFuncInset::normalize(NormalStream & os) const -{ - os << "[func " << name_ << ']'; -} - - -void MathFuncInset::write(WriteStream & os) const -{ - os << "\\" << name_ << ' '; -} diff --git a/src/mathed/math_funcinset.h b/src/mathed/math_funcinset.h deleted file mode 100644 index 8256479c8f..0000000000 --- a/src/mathed/math_funcinset.h +++ /dev/null @@ -1,49 +0,0 @@ -// -*- C++ -*- -#ifndef MATH_FUNCINSET_H -#define MATH_FUNCINSET_H - -#include "math_diminset.h" - -#ifdef __GNUG__ -#pragma interface -#endif - -/** - Functions or LaTeX names for objects that I don't know how to draw. - */ -class MathFuncInset : public MathDimInset { -public: - /// - explicit MathFuncInset(string const & nm); - /// - MathInset * clone() const; - /// - void metrics(MathMetricsInfo & st) const; - /// - void draw(Painter &, int x, int y) const; - /// - string const & name() const; - /// identifies FuncInsets - MathFuncInset * asFuncInset() { return this; } - /// - void setName(string const &); - /// - bool match(MathInset * p) const; - - /// - void normalize(NormalStream &) const; - /// - void maplize(MapleStream &) const; - /// - void mathmlize(MathMLStream &) const; - /// - void octavize(OctaveStream &) const; - /// - void write(WriteStream &) const; -private: - /// - string name_; - /// - mutable LyXFont font_; -}; -#endif diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index e9bb698caa..5cbab860cb 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -881,8 +881,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags, MathArray ar; parse_into(ar, FLAG_RIGHT, mathmode); string r = getToken().asString(); - cell->push_back(MathAtom(new MathDelimInset(l, r))); - cell->back()->cell(0) = ar; + cell->push_back(MathAtom(new MathDelimInset(l, r, ar))); } else if (t.cs() == "right") { diff --git a/src/mathed/math_spaceinset.C b/src/mathed/math_spaceinset.C index c41de6bf80..9bd15cbd13 100644 --- a/src/mathed/math_spaceinset.C +++ b/src/mathed/math_spaceinset.C @@ -9,17 +9,29 @@ #include "math_mathmlstream.h" + char const * latex_mathspace[] = { - "!", ",", ":", ";", "quad", "qquad", "lyxnegspace" + "!", ",", ";", ":", "quad", "qquad", "lyxnegspace", "lyxposspace" }; + MathSpaceInset::MathSpaceInset(int sp) : space_(sp) {} +MathSpaceInset::MathSpaceInset(string const & name) + : space_(1) +{ + for (int i = 0; i < 8; ++i) + if (latex_mathspace[i] == name) + space_ = i; +} + + + MathInset * MathSpaceInset::clone() const { return new MathSpaceInset(*this); @@ -36,6 +48,7 @@ void MathSpaceInset::metrics(MathMetricsInfo &) const case 4: width_ = 20; break; case 5: width_ = 40; break; case 6: width_ = -2; break; + case 7: width_ = 2; break; default: width_ = 6; break; } ascent_ = 4; @@ -48,7 +61,7 @@ void MathSpaceInset::draw(MathPainterInfo & pain, int x, int y) const // Sadly, HP-UX CC can't handle that kind of initialization. // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}}; - if (space_ == 6) + if (space_ > 6) return; int xp[4]; @@ -89,6 +102,6 @@ void MathSpaceInset::normalize(NormalStream & os) const void MathSpaceInset::write(WriteStream & os) const { - if (space_ >= 0 && space_ < 7) + if (space_ >= 0 && space_ < 8) os << '\\' << latex_mathspace[space_] << ' '; } diff --git a/src/mathed/math_spaceinset.h b/src/mathed/math_spaceinset.h index 84ba58fb8d..f25d049a04 100644 --- a/src/mathed/math_spaceinset.h +++ b/src/mathed/math_spaceinset.h @@ -14,6 +14,8 @@ public: /// explicit MathSpaceInset(int sp); /// + explicit MathSpaceInset(string const & name); + /// MathInset * clone() const; /// MathSpaceInset const * asSpaceInset() const { return this; } diff --git a/src/mathed/math_specialcharinset.C b/src/mathed/math_specialcharinset.C deleted file mode 100644 index 562fe89d3c..0000000000 --- a/src/mathed/math_specialcharinset.C +++ /dev/null @@ -1,44 +0,0 @@ -#ifdef __GNUG__ -#pragma implementation -#endif - -#include "math_specialcharinset.h" -#include "math_mathmlstream.h" -#include "math_support.h" - - -MathSpecialCharInset::MathSpecialCharInset(char c) - : char_(c) -{} - - -MathInset * MathSpecialCharInset::clone() const -{ - return new MathSpecialCharInset(*this); -} - - -void MathSpecialCharInset::metrics(MathMetricsInfo & mi) const -{ - MathShapeChanger dummy(mi.base.font, LyXFont::ITALIC_SHAPE); - mathed_char_dim(mi.base.font, char_, ascent_, descent_, width_); -} - - -void MathSpecialCharInset::draw(MathPainterInfo & pi, int x, int y) const -{ - MathShapeChanger dummy(pi.base.font, LyXFont::ITALIC_SHAPE); - pi.draw(x, y, char_); -} - - -void MathSpecialCharInset::write(WriteStream & os) const -{ - os << "\\" << char_; -} - - -void MathSpecialCharInset::normalize(NormalStream & os) const -{ - os << "\\" << char_; -} diff --git a/src/mathed/math_specialcharinset.h b/src/mathed/math_specialcharinset.h deleted file mode 100644 index 7d17eab8b7..0000000000 --- a/src/mathed/math_specialcharinset.h +++ /dev/null @@ -1,35 +0,0 @@ -// -*- C++ -*- -#ifndef MATH_SPECIALCHARINSET_H -#define MATH_SPECIALCHARINSET_H - -#include "math_diminset.h" - -#ifdef __GNUG__ -#pragma interface -#endif - -/** An inset for characters like {, #, and $ that need to be escaped - when written out, but can be inserted by a single keystroke - \author André Pönitz - */ - -class MathSpecialCharInset : public MathDimInset { -public: - /// - explicit MathSpecialCharInset(char c); - /// - MathInset * clone() const; - /// - void metrics(MathMetricsInfo & st) const; - /// - void draw(MathPainterInfo &, int x, int y) const; - /// - void write(WriteStream & os) const; - /// - void normalize(NormalStream &) const; - -private: - /// the character - char char_; -}; -#endif diff --git a/src/mathed/math_stringinset.C b/src/mathed/math_stringinset.C index 220ee4013a..2708266302 100644 --- a/src/mathed/math_stringinset.C +++ b/src/mathed/math_stringinset.C @@ -54,7 +54,7 @@ void MathStringInset::maplize(MapleStream & os) const // insert '*' between adjacent chars if type is LM_TC_VAR os << str_[0]; for (string::size_type i = 1; i < str_.size(); ++i) - os << '*' << str_[i]; + os << str_[i]; } @@ -68,7 +68,7 @@ void MathStringInset::octavize(OctaveStream & os) const // insert '*' between adjacent chars if type is LM_TC_VAR os << str_[0]; for (string::size_type i = 1; i < str_.size(); ++i) - os << '*' << str_[i]; + os << str_[i]; } diff --git a/src/mathed/math_support.C b/src/mathed/math_support.C index 3cc23305b8..cec237a5de 100644 --- a/src/mathed/math_support.C +++ b/src/mathed/math_support.C @@ -525,28 +525,6 @@ void math_font_max_dim(LyXFont const & font, int & asc, int & des) } -string convertDelimToLatexName(string const & name) -{ - if (name == "(") - return name; - if (name == "[") - return name; - if (name == ".") - return name; - if (name == ")") - return name; - if (name == "]") - return name; - if (name == "/") - return name; - if (name == "|") - return name; - return "\\" + name + " "; -} - - - - struct fontinfo { string cmd_; LyXFont::FONT_FAMILY family_; diff --git a/src/mathed/math_support.h b/src/mathed/math_support.h index 0ea86a78db..2cd35476cf 100644 --- a/src/mathed/math_support.h +++ b/src/mathed/math_support.h @@ -39,8 +39,6 @@ void drawChar(MathPainterInfo & pain, void math_font_max_dim(LyXFont const &, int & asc, int & desc); -string convertDelimToLatexName(string const & name); - void augmentFont(LyXFont & f, string const & cmd); diff --git a/src/mathed/math_symbolinset.C b/src/mathed/math_symbolinset.C index 57d8d7b2bc..bdcfdb8a1d 100644 --- a/src/mathed/math_symbolinset.C +++ b/src/mathed/math_symbolinset.C @@ -115,6 +115,8 @@ void MathSymbolInset::maplize(MapleStream & os) const { if (name() == "cdot") os << '*'; + else if (name() == "infty") + os << "infinity"; else os << name(); } -- 2.39.5