From 74124b4bf85af8e902b2ed844ab8b6349073e814 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 10 Aug 2001 15:32:26 +0000 Subject: [PATCH] make {} a proper inset; simplifications to the parser; git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2489 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formulabase.C | 11 ++++++----- src/mathed/math_charinset.C | 3 +-- src/mathed/math_hash.C | 1 + src/mathed/math_parser.C | 38 ++++++++++++++++-------------------- src/mathed/math_parser.h | 4 +++- src/mathed/math_scopeinset.C | 14 ++++++++----- 6 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index be8dbaa617..b68844fa55 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -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); diff --git a/src/mathed/math_charinset.C b/src/mathed/math_charinset.C index 24280e3277..7227fc004c 100644 --- a/src/mathed/math_charinset.C +++ b/src/mathed/math_charinset.C @@ -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_; diff --git a/src/mathed/math_hash.C b/src/mathed/math_hash.C index 064d1b7872..45f9161516 100644 --- a/src/mathed/math_hash.C +++ b/src/mathed/math_hash.C @@ -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}, diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 0c8b5e79c4..d0d480743b 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -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(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(lval_->id); - flags |= (FLAG_BRACE | FLAG_BRACE_FONT); break; case LM_TK_STY: diff --git a/src/mathed/math_parser.h b/src/mathed/math_parser.h index fa2e929d15..b8a2494379 100644 --- a/src/mathed/math_parser.h +++ b/src/mathed/math_parser.h @@ -56,7 +56,9 @@ enum MathTokenEnum LM_TK_NEWLINE, /// LM_TK_UNDEF, - /// + /// mathcal, mathrm... + LM_TK_OLDFONT, + /// cal,... LM_TK_FONT, /// LM_TK_LEFT, diff --git a/src/mathed/math_scopeinset.C b/src/mathed/math_scopeinset.C index f85cbbc1e6..199429d629 100644 --- a/src/mathed/math_scopeinset.C +++ b/src/mathed/math_scopeinset.C @@ -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); } -- 2.39.2