]> git.lyx.org Git - lyx.git/commitdiff
make {} a proper inset; simplifications to the parser;
authorAndré Pönitz <poenitz@gmx.net>
Fri, 10 Aug 2001 15:32:26 +0000 (15:32 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 10 Aug 2001 15:32:26 +0000 (15:32 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2489 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/formulabase.C
src/mathed/math_charinset.C
src/mathed/math_hash.C
src/mathed/math_parser.C
src/mathed/math_parser.h
src/mathed/math_scopeinset.C

index be8dbaa61776f90b6ddbcec1067566158caeafd2..b68844fa55391112895afa06584d13e8f8e3f6f1 100644 (file)
@@ -39,6 +39,7 @@
 #include "font.h"
 #include "math_arrayinset.h"
 #include "math_spaceinset.h"
+#include "math_scopeinset.h"
 #include "math_macrotable.h"
 #include "support/lyxlib.h"
 #include "mathed/support.h"
@@ -750,12 +751,12 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
                                if (greek_kb_flag < 2)
                                        greek_kb_flag = 0;
                                
-                       } else if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) {
+                       } else if (c == '{') {
+                               mathcursor->insert(new MathScopeInset);
+                               mathcursor->left();
+                               mathcursor->clearLastCode();
+                       } else if (strchr("!,:;", c) && (varcode == LM_TC_TEX||was_macro)) {
                                mathcursor->insert(c, LM_TC_TEX);
-                               if (c == '{') {
-                                       mathcursor->insert('}', LM_TC_TEX);
-                                       mathcursor->left();
-                               }
                                mathcursor->clearLastCode();
                        } else if (c == '_' && varcode == LM_TC_TEX) {
                                mathcursor->insert(c, LM_TC_SPECIAL);
index 24280e327700873246a1ca6144029f0cbb9c4d3f..7227fc004cb0e0f8447e747c12f3f46a211a3f38 100644 (file)
@@ -59,8 +59,7 @@ void MathCharInset::write(std::ostream & os, bool) const
        if (code_ >= LM_TC_RM && code_ <= LM_TC_TEXTRM) 
                os << '\\' << math_font_name[code_ - LM_TC_RM] << '{';
 
-       if ((code_ == LM_TC_TEX && char_ != '{' && char_ != '}') ||
-                       (code_ == LM_TC_SPECIAL))
+       if (code_ == LM_TC_TEX || code_ == LM_TC_SPECIAL)
                os << '\\';
 
        os << char_;
index 064d1b7872762666e7358c42f10a5ccdbc0c7602..45f91615162f72b264b3fe9737f297da0eb60483 100644 (file)
@@ -88,6 +88,7 @@ latexkeys wordlist[] =
        {"bowtie",  LM_TK_NOGLYPH, 0, LMB_RELATION},
        {"breve",  LM_TK_DECORATION, LM_breve, LMB_NONE},
        {"bullet",  LM_TK_SYM, LM_bullet, LMB_OPERATOR},
+       {"cal",  LM_TK_OLDFONT, LM_TC_CAL, LMB_OPERATOR},
        {"cap",  LM_TK_SYM, LM_cap, LMB_OPERATOR},
        {"cdot",  LM_TK_SYM, LM_cdot, LMB_OPERATOR},
        {"cdots",  LM_TK_DOTS, LM_cdots, LMB_NONE},
index 0c8b5e79c4c76e0e667656506d6a407afe744ec7..d0d480743b0befe95c551f9f6f58b6fbf92b3650 100644 (file)
@@ -41,6 +41,8 @@
 #include "math_matrixinset.h"
 #include "math_noglyphinset.h"
 #include "math_rootinset.h"
+#include "math_scopeinset.h"
+#include "math_sqrtinset.h"
 #include "math_scriptinset.h"
 #include "math_sizeinset.h"
 #include "math_spaceinset.h"
@@ -116,7 +118,6 @@ enum {
        FLAG_BRACE_LAST = 1 << 1,  //  // { Last } ends the parsing process
        FLAG_RIGHT      = 1 << 2,  //  Next right ends the parsing process
        FLAG_END        = 1 << 3,  //  Next end ends the parsing process
-       FLAG_BRACE_FONT = 1 << 4,  //  // { Next } closes a font
        FLAG_BRACK_END  = 1 << 5,  //  // [ Next ] ends the parsing process
        FLAG_AMPERSAND  = 1 << 6,  //  Next & ends the parsing process
        FLAG_NEWLINE    = 1 << 7,  //  Next \\ ends the parsing process
@@ -613,29 +614,14 @@ void Parser::parse_into(MathArray & array, unsigned flags)
                        break;
 
                case LM_TK_OPEN:
-                       ++brace;
-                       if (flags & FLAG_BRACE)
-                               flags &= ~FLAG_BRACE;
-                       else 
-                               array.push_back(new MathCharInset('{', LM_TC_TEX));
+                       array.push_back(new MathScopeInset);
+                       parse_into(array.back()->cell(0), FLAG_BRACE_LAST);
                        break;
 
                case LM_TK_CLOSE:
-                       --brace;
-                       if (brace < 0) {
-                               error("Unmatching braces");
-                               panic = true;
-                               break;
-                       }
-                       if (flags & FLAG_BRACE_FONT) {
-                               yyvarcode = LM_TC_VAR;
-                               flags &= ~FLAG_BRACE_FONT;
-                               break;
-                       }
-                       if (brace == 0 && (flags & FLAG_BRACE_LAST))
+                       if (flags & FLAG_BRACE_LAST) {
                                flags |= FLAG_LEAVE;
-                       else
-                               array.push_back(new MathCharInset('}', LM_TC_TEX));
+                       }
                        break;
                
                case '[':
@@ -775,8 +761,18 @@ void Parser::parse_into(MathArray & array, unsigned flags)
                        break;
                
                case LM_TK_FONT:
+               {
+                       MathTextCodes t = static_cast<MathTextCodes>(lval_->id);
+                       MathArray ar;
+                       parse_into(ar, FLAG_ITEM);
+                       for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it)
+                               (*it)->handleFont(t);
+                       array.push_back(ar);
+                       break;
+               }
+
+               case LM_TK_OLDFONT:
                        yyvarcode = static_cast<MathTextCodes>(lval_->id);
-                       flags |= (FLAG_BRACE | FLAG_BRACE_FONT);
                        break;
 
                case LM_TK_STY:
index fa2e929d15eff204f72c3bb393b02807f115fa5e..b8a2494379c9b64cbf77bfcbcf675ba28e736817 100644 (file)
@@ -56,7 +56,9 @@ enum MathTokenEnum
        LM_TK_NEWLINE,
        ///
        LM_TK_UNDEF,
-       ///
+       /// mathcal, mathrm...
+       LM_TK_OLDFONT,
+       /// cal,...
        LM_TK_FONT,
        ///
        LM_TK_LEFT,
index f85cbbc1e62eb2bb668d3c6d6f239cca947890bc..199429d629390ebf2855ace1bf2ec009a4583290 100644 (file)
@@ -5,6 +5,7 @@
 #include "math_scopeinset.h"
 #include "LColor.h"
 #include "Painter.h"
+#include "support.h"
 #include "support/LOstream.h"
 
 
@@ -23,9 +24,9 @@ void MathScopeInset::metrics(MathStyles st) const
 {
        xcell(0).metrics(st);
        size_    = st;
-       ascent_  = xcell(0).ascent()  + 2;
-       descent_ = xcell(0).descent() + 2;
-       width_   = xcell(0).width()   + 4;
+       ascent_  = xcell(0).ascent();
+       descent_ = xcell(0).descent();
+       width_   = xcell(0).width() + mathed_string_width(LM_TC_TEX, st, "{}");
 }
 
 
@@ -33,8 +34,11 @@ void MathScopeInset::draw(Painter & pain, int x, int y) const
 { 
        xo(x);
        yo(y);
-       xcell(0).draw(pain, x + 2, y); 
-       pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
+       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);
 }