mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-24 01:01:57 +00:00
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
This commit is contained in:
parent
e729656153
commit
74124b4bf8
@ -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);
|
||||
|
@ -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_;
|
||||
|
@ -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},
|
||||
|
@ -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:
|
||||
|
@ -56,7 +56,9 @@ enum MathTokenEnum
|
||||
LM_TK_NEWLINE,
|
||||
///
|
||||
LM_TK_UNDEF,
|
||||
///
|
||||
/// mathcal, mathrm...
|
||||
LM_TK_OLDFONT,
|
||||
/// cal,...
|
||||
LM_TK_FONT,
|
||||
///
|
||||
LM_TK_LEFT,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user