7 #include "math_parinset.h"
10 #include "math_xiter.h"
11 #include "math_parser.h"
13 #include "mathed/support.h"
15 #include "math_rowst.h"
16 #include "math_parinset.h"
21 extern int number_of_newlines;
24 MathedRowContainer & MathParInset::getRowSt()
30 string MathParInset::label() const
32 if (row_.size() == 0) {
33 lyxerr << "Warning: Empty rowst when accessing label!\n";
36 return row_.back().getLabel();
40 MathParInset::MathParInset(short st, string const & nm, short ot)
41 : MathedInset(nm, ot, st)
47 if (objtype == LM_OT_SCRIPT)
52 MathedInset * MathParInset::Clone()
54 return new MathParInset(*this);
58 void MathParInset::substitute(MathMacro * m)
60 //lyxerr << "called: MathParInset::substitute, m: " << m << endl;
66 void MathParInset::setData(MathedArray const & a)
70 // A standard paragraph shouldn't have any tabs nor CRs.
71 MathedIter it(&array);
73 char c = it.GetChar();
74 if (c == LM_TC_TAB || c == LM_TC_CR)
82 void MathParInset::draw(Painter & pain, int x, int y)
92 MathedXIter data(this);
95 pain.rectangle(x, y - df_asc, df_width, df_asc,
103 byte const cx = data.GetChar();
105 string const s = data.GetString();
106 drawStr(pain, data.fcode(), size(), x, y, s);
107 mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
109 } else if (cx == 0) {
111 } else if (MathIsInset(cx)) {
113 MathedInset * p = data.GetInset();
114 if (cx == LM_TC_UP) {
116 x -= (xp > p->Width()) ?
117 p->Width() + (xp - p->Width()) / 2 : xp;
118 yy -= (asc + p->Descent() + 4);
120 yy -= (p->Descent() > asc) ?
121 p->Descent() + 4 : asc;
122 } else if (cx == LM_TC_DOWN) {
124 x -= (xp > p->Width()) ?
125 p->Width() + (xp - p->Width()) / 2 : xp;
126 yy += des + p->Ascent() + 2;
128 yy += des + p->Ascent() / 2;
133 p->draw(pain, x, yy);
134 if (cx != LM_TC_UP && cx != LM_TC_DOWN) {
135 limits = p->GetLimits();
140 } else if (cx == LM_TC_TAB) {
142 || cxp == LM_TC_CR || data.IsFirst()) {
143 pain.rectangle(x, y - df_asc,
149 } else if (cx == LM_TC_CR) {
151 || cxp == LM_TC_CR || data.IsFirst()) {
152 pain.rectangle(x, y - df_asc,
159 lyxerr << "GMathed Error: Unrecognized code[" << cx << "]" << endl;
165 if (cxp == LM_TC_TAB || cxp == LM_TC_CR) {
167 pain.rectangle(x, y - df_asc, df_width, df_asc,
173 void MathParInset::Metrics()
185 ascent = df_asc;//mathed_char_height(LM_TC_VAR, size, 'I', asc, des);
192 MathedXIter data(this);
197 string const s = data.GetString();
198 mathed_string_height(data.fcode(),
199 size(), s, asc, des);
205 mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
206 } else if (MathIsInset(cx)) {
207 MathedInset * p = data.GetInset();
210 if (cx == LM_TC_UP) {
211 asc += (limits) ? p->Height() + 4: p->Ascent() +
212 ((p->Descent()>asc) ? p->Descent() - asc + 4: 0);
213 } else if (cx == LM_TC_DOWN) {
214 des += (limits ? p->Height() + 4 : p->Height() - p->Ascent() / 2);
223 if (cx!= LM_TC_UP && cx!= LM_TC_DOWN)
224 limits = p->GetLimits();
226 } else if (cx == LM_TC_TAB) {
229 data.GetIncPos(x, y);
230 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
235 data.setTab(x - tb, tab);
240 } else if (cx == LM_TC_CR) {
244 data.GetIncPos(x, y);
245 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
250 data.setTab(x - tb, tab);
251 } else //if (GetColumns() == 1)
255 data.GetIncPos(x, y);
261 data.subMetrics(ascent, descent);
266 lyxerr << "Mathed Error: Unrecognized code[" << cx
272 data.GetIncPos(width, ls);
274 // No matter how simple is a matrix, it is NOT a subparagraph
276 if (cxp == LM_TC_TAB) {
281 data.setTab(width - tb, tab);
285 data.subMetrics(ascent, descent);
290 void MathParInset::Write(ostream & os, bool fragile)
297 MathedIter data(&array);
299 MathedRowContainer::iterator crow = getRowSt().begin();
302 if (!Permit(LMPF_FIXED_SIZE)) {
303 l = lm_get_key_by_id(size(), LM_TK_STY);
305 os << '\\' << l->name << ' ';
308 byte cx = data.GetChar();
310 string str = data.GetString();
312 if (data.fcode() >= LM_TC_RM && data.fcode() <= LM_TC_TEXTRM) {
313 os << '\\' << math_font_name[data.fcode()-LM_TC_RM] << '{';
315 for (string::const_iterator s = str.begin();
316 s != str.end(); ++s) {
318 if (MathIsSymbol(data.fcode())) {
319 l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ?
320 LM_TK_BIGSYM : LM_TK_SYM);
322 os << '\\' << l->name << ' ';
325 #warning this does not compile on gcc 2.97
327 //lyxerr << "Illegal symbol code[" << c
328 // << " " << str.end() - s << " " << data.fcode() << "]";
331 // Is there a standard logical XOR?
332 if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') ||
333 (data.fcode() == LM_TC_SPECIAL))
341 if (c == '}' && data.fcode() == LM_TC_TEX && brace < 0)
342 lyxerr <<"Math warning: Unexpected closing brace."
348 if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
351 if (MathIsInset(cx)) {
352 MathedInset * p = data.GetInset();
355 if (cx == LM_TC_DOWN)
357 p->Write(os, fragile);
358 if (cx == LM_TC_UP || cx == LM_TC_DOWN)
372 if (!crow->isNumbered()) {
375 if (!crow->getLabel().empty()) {
385 ++number_of_newlines;
390 lyxerr << "WMath Error: unrecognized code[" << cx << "]";
398 if (!crow->isNumbered()) {
401 if (!crow->getLabel().empty()) {
409 os << string(brace, '}');
413 void MathParInset::WriteNormal(ostream & os)
424 MathedIter data(&array);
426 MathedRowContainer::iterator crow = getRowSt().begin();
429 if (!Permit(LMPF_FIXED_SIZE)) {
430 l = lm_get_key_by_id(size(), LM_TK_STY);
432 os << l->name << ' ';
435 byte cx = data.GetChar();
437 string str = data.GetString();
439 if (data.fcode() >= LM_TC_RM && data.fcode() <= LM_TC_TEXTRM) {
440 os << "[font " << math_font_name[data.fcode()-LM_TC_RM] << " [";
442 for (string::const_iterator s = str.begin();
443 s != str.end(); ++s) {
445 if (MathIsSymbol(data.fcode())) {
446 l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ?
447 LM_TK_BIGSYM : LM_TK_SYM);
449 os << " [" << l->name << "] ";
452 #warning this does not compile on gcc 2.97
454 //lyxerr << "Illegal symbol code[" << c
455 // << " " << str.end() - s << " " << data.fcode() << "]";
458 // Is there a standard logical XOR?
459 if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') ||
460 (data.fcode() == LM_TC_SPECIAL))
468 if (c == '}' && data.fcode() == LM_TC_TEX && brace < 0)
469 lyxerr <<"Math warning: Unexpected closing brace."
475 if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
478 if (MathIsInset(cx)) {
479 MathedInset * p = data.GetInset();
481 os << "[superscript ";
482 if (cx == LM_TC_DOWN)
485 if (cx == LM_TC_UP || cx == LM_TC_DOWN)
503 lyxerr << "WMath Error: unrecognized code[" << cx << "]";
511 os << string(brace, '}');
517 void MathParInset::clear()
522 bool MathParInset::Inside(int x, int y)
524 return (x >= xo() && x <= xo() + width
525 && y <= yo() + descent && y >= yo() - ascent);
529 void MathParInset::GetXY(int & x, int & y) const
536 void MathParInset::UserSetSize(short sz)
540 flag = flag & ~LMPF_FIXED_SIZE;
545 void MathParInset::SetStyle(short sz)
547 if (Permit(LMPF_FIXED_SIZE)) {
548 if (Permit(LMPF_SCRIPT))
549 sz = (sz < LM_ST_SCRIPT) ? LM_ST_SCRIPT: LM_ST_SCRIPTSCRIPT;
550 if (Permit(LMPF_SMALLER) && sz < LM_ST_SCRIPTSCRIPT)
552 MathedInset::SetStyle(sz);
557 bool MathParInset::Permit(short f) const
559 return bool(f & flag);
563 MathedArray & MathParInset::GetData()
568 void MathParInset::push_back(MathedInset * inset, int t)
570 array.push_back(inset, t);
574 MathedArray const & MathParInset::GetData() const
580 void MathParInset::setXY(int x, int y)