From f1e24333135c3052c533e24c15ffc42b9bbee008 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 29 Aug 2001 16:23:54 +0000 Subject: [PATCH] re-enable { and } in seperate cells; nuke MathScopeInset; git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2620 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/Makefile.am | 2 -- src/mathed/math_cursor.C | 8 ++--- src/mathed/math_parser.C | 31 ++++++++++++------- src/mathed/math_scopeinset.C | 58 ------------------------------------ src/mathed/math_scopeinset.h | 29 ------------------ 5 files changed, 23 insertions(+), 105 deletions(-) delete mode 100644 src/mathed/math_scopeinset.C delete mode 100644 src/mathed/math_scopeinset.h diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index a0f324a867..ca542e9668 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -76,8 +76,6 @@ libmathed_la_SOURCES = \ math_parser.h \ math_rootinset.C \ math_rootinset.h \ - math_scopeinset.C \ - math_scopeinset.h \ math_scriptinset.C \ math_scriptinset.h \ math_sizeinset.C \ diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 124a0ac610..5241a194a5 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -35,7 +35,6 @@ #include "math_charinset.h" #include "math_deliminset.h" #include "math_matrixinset.h" -#include "math_scopeinset.h" #include "math_scriptinset.h" #include "math_spaceinset.h" #include "math_parser.h" @@ -1300,14 +1299,11 @@ void MathCursor::interpret(string const & s) return; } - if (c == '{') { - niceInsert(new MathScopeInset); + if (c == '{' || c == '}') { + niceInsert(new MathCharInset(c, LM_TC_SPECIAL)); return; } - if (c == '}') // ignore it - return; - if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) { static char const greek[26] = {'A', 'B', 'X', 0 , 'E', 0 , 0 , 'H', 'I', 0 , diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 3ca1a4a867..4eadb7bc99 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -37,7 +37,6 @@ #include "math_macrotemplate.h" #include "math_matrixinset.h" #include "math_rootinset.h" -#include "math_scopeinset.h" #include "math_sqrtinset.h" #include "math_scriptinset.h" #include "math_sqrtinset.h" @@ -439,7 +438,7 @@ void Parser::tokenize(string const & buffer) } } -#if 0 +#if 1 lyxerr << "\nTokens: "; for (unsigned i = 0; i < tokens_.size(); ++i) lyxerr << tokens_[i]; @@ -655,7 +654,7 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code) } if (flags & FLAG_BLOCK) { - if (t.cat() == catEnd || t.cat() == catAlign || t.cs() == "\\") + if (t.cat() == catAlign || t.cs() == "\\") return; if (t.cs() == "end") { getArg('{', '}'); @@ -683,15 +682,13 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code) } else if (t.cat() == catBegin) { - //lyxerr << " creating ScopeInset\n"; - array.push_back(new MathScopeInset); - parse_into(array.back()->cell(0), FLAG_BRACE_LAST); + array.push_back(new MathCharInset('{', LM_TC_SPECIAL)); } else if (t.cat() == catEnd) { - if (!(flags & FLAG_BRACE_LAST)) - lyxerr << " ##### unexpected end of block\n"; - return; + if (flags & FLAG_BRACE_LAST) + return; + array.push_back(new MathCharInset('}', LM_TC_SPECIAL)); } else if (t.cat() == catAlign) { @@ -848,7 +845,21 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code) else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") { limits = 0; MathInset * p = createMathInset(t.cs()); - p->cell(0).swap(array); + // search backward for position of last '{' if any + int pos; + for (pos = array.size() - 1; pos >= 0; --pos) { + MathInset * q = array.nextInset(pos); + if (q->getChar() == '{' && q->code() == LM_TC_SPECIAL) + break; + } + if (pos >= 0) { + // found it -> use the part after '{' as "numerator", erase the '{' + p->cell(0) = MathArray(array, pos + 1, array.size()); + array.erase(pos, array.size()); + } else { + // not found -> use everything as "numerator" + p->cell(0).swap(array); + } array.push_back(p); parse_into(p->cell(1), FLAG_BLOCK); } diff --git a/src/mathed/math_scopeinset.C b/src/mathed/math_scopeinset.C deleted file mode 100644 index 199429d629..0000000000 --- a/src/mathed/math_scopeinset.C +++ /dev/null @@ -1,58 +0,0 @@ -#ifdef __GNUG__ -#pragma implementation -#endif - -#include "math_scopeinset.h" -#include "LColor.h" -#include "Painter.h" -#include "support.h" -#include "support/LOstream.h" - - -MathScopeInset::MathScopeInset() - : MathNestInset(1) -{} - - -MathInset * MathScopeInset::clone() const -{ - return new MathScopeInset(*this); -} - - -void MathScopeInset::metrics(MathStyles st) const -{ - xcell(0).metrics(st); - size_ = st; - ascent_ = xcell(0).ascent(); - descent_ = xcell(0).descent(); - width_ = xcell(0).width() + mathed_string_width(LM_TC_TEX, st, "{}"); -} - - -void MathScopeInset::draw(Painter & pain, int x, int y) const -{ - xo(x); - yo(y); - int d = mathed_char_width(LM_TC_TEX, size_, '{'); - drawChar(pain, LM_TC_TEX, size_, x, y, '{'); - xcell(0).draw(pain, x + d, y); - drawChar(pain, LM_TC_TEX, size_, x + width_ - d, y, '}'); - //pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline); -} - - -void MathScopeInset::write(std::ostream & os, bool fragile) const -{ - os << '{'; - cell(0).write(os, fragile); - os << '}'; -} - - -void MathScopeInset::writeNormal(std::ostream & os) const -{ - os << "[scope "; - cell(0).writeNormal(os); - os << "] "; -} diff --git a/src/mathed/math_scopeinset.h b/src/mathed/math_scopeinset.h deleted file mode 100644 index 13cfdf6c10..0000000000 --- a/src/mathed/math_scopeinset.h +++ /dev/null @@ -1,29 +0,0 @@ -// -*- C++ -*- -#ifndef MATH_SCOPEINSET_H -#define MATH_SCOPEINSET_H - -#include "math_nestinset.h" - -#ifdef __GNUG__ -#pragma interface -#endif - -/** An inset for new scopes (i.e. {....} blocks in LaTeX) - \author André Pönitz - */ -class MathScopeInset : public MathNestInset { -public: - /// - MathScopeInset(); - /// - MathInset * clone() const; - /// - void draw(Painter &, int x, int y) const; - /// - void write(std::ostream &, bool fragile) const; - /// - void writeNormal(std::ostream &) const; - /// - void metrics(MathStyles st) const; -}; -#endif -- 2.39.2