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()
29 string MathParInset::label() const
31 if (row_.size() == 0) {
32 lyxerr << "Warning: Empty rowst when accessing label!\n";
35 return row_.back().getLabel();
39 MathParInset::MathParInset(short st, string const & nm, short ot)
40 : MathedInset(nm, ot, st)
46 if (objtype == LM_OT_SCRIPT)
51 MathedInset * MathParInset::Clone()
53 return new MathParInset(*this);
56 void MathParInset::substitute(MathMacro * m)
58 //lyxerr << "called: MathParInset::substitute, m: " << m << endl;
64 void MathParInset::setData(MathedArray const & a)
68 // A standard paragraph shouldn't have any tabs nor CRs.
69 MathedIter it(&array);
71 char c = it.GetChar();
72 if (c == LM_TC_TAB || c == LM_TC_CR)
80 void MathParInset::draw(Painter & pain, int x, int y)
90 MathedXIter data(this);
93 pain.rectangle(x, y - df_asc, df_width, df_asc,
101 byte const cx = data.GetChar();
103 string const s = data.GetString();
104 drawStr(pain, data.fcode(), size(), x, y, s);
105 mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
107 } else if (cx == 0) {
109 } else if (MathIsInset(cx)) {
111 MathedInset * p = data.GetInset();
112 if (cx == LM_TC_UP) {
114 x -= (xp > p->Width()) ?
115 p->Width() + (xp - p->Width()) / 2 : xp;
116 yy -= (asc + p->Descent() + 4);
118 yy -= (p->Descent() > asc) ?
119 p->Descent() + 4 : asc;
120 } else if (cx == LM_TC_DOWN) {
122 x -= (xp > p->Width()) ?
123 p->Width() + (xp - p->Width()) / 2 : xp;
124 yy += des + p->Ascent() + 2;
126 yy += des + p->Ascent() / 2;
131 p->draw(pain, x, yy);
132 if (cx != LM_TC_UP && cx != LM_TC_DOWN) {
133 limits = p->GetLimits();
138 } else if (cx == LM_TC_TAB) {
140 || cxp == LM_TC_CR || data.IsFirst()) {
141 pain.rectangle(x, y - df_asc,
147 } else if (cx == LM_TC_CR) {
149 || cxp == LM_TC_CR || data.IsFirst()) {
150 pain.rectangle(x, y - df_asc,
157 lyxerr << "GMathed Error: Unrecognized code[" << cx << "]" << endl;
163 if (cxp == LM_TC_TAB || cxp == LM_TC_CR) {
165 pain.rectangle(x, y - df_asc, df_width, df_asc,
171 void MathParInset::Metrics()
183 ascent = df_asc;//mathed_char_height(LM_TC_VAR, size, 'I', asc, des);
190 MathedXIter data(this);
195 string const s = data.GetString();
196 mathed_string_height(data.fcode(),
197 size(), s, asc, des);
203 mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
204 } else if (MathIsInset(cx)) {
205 MathedInset * p = data.GetInset();
208 if (cx == LM_TC_UP) {
209 asc += (limits) ? p->Height() + 4: p->Ascent() +
210 ((p->Descent()>asc) ? p->Descent() - asc + 4: 0);
211 } else if (cx == LM_TC_DOWN) {
212 des += (limits ? p->Height() + 4 : p->Height() - p->Ascent() / 2);
221 if (cx!= LM_TC_UP && cx!= LM_TC_DOWN)
222 limits = p->GetLimits();
224 } else if (cx == LM_TC_TAB) {
227 data.GetIncPos(x, y);
228 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
233 data.setTab(x - tb, tab);
238 } else if (cx == LM_TC_CR) {
242 data.GetIncPos(x, y);
243 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
248 data.setTab(x - tb, tab);
249 } else //if (GetColumns() == 1)
253 data.GetIncPos(x, y);
259 data.subMetrics(ascent, descent);
264 lyxerr << "Mathed Error: Unrecognized code[" << cx
270 data.GetIncPos(width, ls);
272 // No matter how simple is a matrix, it is NOT a subparagraph
274 if (cxp == LM_TC_TAB) {
279 data.setTab(width - tb, tab);
283 data.subMetrics(ascent, descent);
288 void MathParInset::Write(ostream & os, bool fragile)
295 MathedIter data(&array);
297 MathedRowContainer::iterator crow = getRowSt().begin();
300 if (!Permit(LMPF_FIXED_SIZE)) {
301 l = lm_get_key_by_id(size(), LM_TK_STY);
303 os << '\\' << l->name << ' ';
306 byte cx = data.GetChar();
308 string str = data.GetString();
310 if (data.fcode() >= LM_TC_RM && data.fcode() <= LM_TC_TEXTRM) {
311 os << '\\' << math_font_name[data.fcode()-LM_TC_RM] << '{';
313 for (string::const_iterator s = str.begin();
314 s != str.end(); ++s) {
316 if (MathIsSymbol(data.fcode())) {
317 l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ?
318 LM_TK_BIGSYM : LM_TK_SYM);
320 os << '\\' << l->name << ' ';
323 #warning this does not compile on gcc 2.97
325 //lyxerr << "Illegal symbol code[" << c
326 // << " " << str.end() - s << " " << data.fcode() << "]";
329 // Is there a standard logical XOR?
330 if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') ||
331 (data.fcode() == LM_TC_SPECIAL))
339 if (c == '}' && data.fcode() == LM_TC_TEX && brace < 0)
340 lyxerr <<"Math warning: Unexpected closing brace."
346 if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
349 if (MathIsInset(cx)) {
350 MathedInset * p = data.GetInset();
353 if (cx == LM_TC_DOWN)
355 p->Write(os, fragile);
356 if (cx == LM_TC_UP || cx == LM_TC_DOWN)
370 if (!crow->isNumbered()) {
373 if (!crow->getLabel().empty()) {
383 ++number_of_newlines;
388 lyxerr << "WMath Error: unrecognized code[" << cx << "]";
396 if (!crow->isNumbered()) {
399 if (!crow->getLabel().empty()) {
407 os << string(brace, '}');
411 void MathParInset::WriteNormal(ostream & os)
422 MathedIter data(&array);
424 MathedRowContainer::iterator crow = getRowSt().begin();
427 if (!Permit(LMPF_FIXED_SIZE)) {
428 l = lm_get_key_by_id(size(), LM_TK_STY);
430 os << l->name << ' ';
433 byte cx = data.GetChar();
435 string str = data.GetString();
437 if (data.fcode() >= LM_TC_RM && data.fcode() <= LM_TC_TEXTRM) {
438 os << "[font " << math_font_name[data.fcode()-LM_TC_RM] << " [";
440 for (string::const_iterator s = str.begin();
441 s != str.end(); ++s) {
443 if (MathIsSymbol(data.fcode())) {
444 l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ?
445 LM_TK_BIGSYM : LM_TK_SYM);
447 os << " [" << l->name << "] ";
450 #warning this does not compile on gcc 2.97
452 //lyxerr << "Illegal symbol code[" << c
453 // << " " << str.end() - s << " " << data.fcode() << "]";
456 // Is there a standard logical XOR?
457 if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') ||
458 (data.fcode() == LM_TC_SPECIAL))
466 if (c == '}' && data.fcode() == LM_TC_TEX && brace < 0)
467 lyxerr <<"Math warning: Unexpected closing brace."
473 if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
476 if (MathIsInset(cx)) {
477 MathedInset * p = data.GetInset();
479 os << "[superscript ";
480 if (cx == LM_TC_DOWN)
483 if (cx == LM_TC_UP || cx == LM_TC_DOWN)
501 lyxerr << "WMath Error: unrecognized code[" << cx << "]";
509 os << string(brace, '}');
515 void MathParInset::clear()
520 bool MathParInset::Inside(int x, int y)
522 return (x >= xo() && x <= xo() + width
523 && y <= yo() + descent && y >= yo() - ascent);
527 void MathParInset::GetXY(int & x, int & y) const
534 void MathParInset::UserSetSize(short sz)
538 flag = flag & ~LMPF_FIXED_SIZE;
543 void MathParInset::SetStyle(short sz)
545 if (Permit(LMPF_FIXED_SIZE)) {
546 if (Permit(LMPF_SCRIPT))
547 sz = (sz < LM_ST_SCRIPT) ? LM_ST_SCRIPT: LM_ST_SCRIPTSCRIPT;
548 if (Permit(LMPF_SMALLER) && sz < LM_ST_SCRIPTSCRIPT)
550 MathedInset::SetStyle(sz);
555 bool MathParInset::Permit(short f) const
557 return bool(f & flag);
561 MathedArray & MathParInset::GetData()
566 void MathParInset::push_back(MathedInset * inset, int t)
568 array.push_back(inset, t);
572 MathedArray const & MathParInset::GetData() const
578 void MathParInset::setXY(int x, int y)