3 #include "math_parinset.h"
6 #include "math_xiter.h"
8 #include "mathed/support.h"
10 #include "math_parser.h"
11 #include "math_rowst.h"
12 #include "math_parinset.h"
17 extern int number_of_newlines;
20 MathedRowSt * MathParInset::getRowSt() const
26 MathParInset::MathParInset(short st, string const & nm, short ot)
27 : MathedInset(nm, ot, st)
34 if (objtype == LM_OT_SCRIPT)
39 MathParInset::MathParInset(MathParInset * p)
44 MathedIter it(p->GetData());
49 MathParInset::~MathParInset()
59 MathedInset * MathParInset::Clone()
61 return new MathParInset(this);
65 void MathParInset::SetData(MathedArray * a)
69 // A standard paragraph shouldn't have any tabs nor CRs.
73 char c = it.GetChar();
74 if (c == LM_TC_TAB || c == LM_TC_CR)
84 MathParInset::draw(Painter & pain, int x, int y)
94 if (!array || array->empty()) {
96 MathedXIter data(this);
99 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
102 MathedXIter data(this);
106 byte cx = data.GetChar();
108 string s = data.GetString();
109 drawStr(pain, data.FCode(), size(), x, y, s);
110 mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
116 if (MathIsInset(cx)) {
118 MathedInset * p = data.GetInset();
119 if (cx == LM_TC_UP) {
121 x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
122 yy -= (asc + p->Descent()+4);
125 yy -= (p->Descent()>asc) ? p->Descent()+4: asc;
127 else if (cx == LM_TC_DOWN) {
129 x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
130 yy += des + p->Ascent() + 2;
132 yy += des + p->Ascent()/2;
138 p->draw(pain, x, yy);
139 if (cx!= LM_TC_UP && cx!= LM_TC_DOWN) {
140 limits = p->GetLimits();
146 else if (cx == LM_TC_TAB) {
147 if (cxp == cx || cxp == LM_TC_CR || data.IsFirst()) {
148 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
153 else if (cx == LM_TC_CR) {
154 if (cxp == LM_TC_TAB || cxp == LM_TC_CR || data.IsFirst()) {
155 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
161 lyxerr << "GMathed Error: Unrecognized code[" << cx << "]" << endl;
167 if (cxp == LM_TC_TAB || cxp == LM_TC_CR) {
169 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
175 MathParInset::Metrics()
187 ascent = df_asc;//mathed_char_height(LM_TC_VAR, size, 'I', asc, des);
191 if (array->empty()) return;
194 MathedXIter data(this);
199 string s = data.GetString();
200 mathed_string_height(data.FCode(),
201 size(), s, asc, des);
202 if (asc > ascent) ascent = asc;
203 if (des > descent) descent = des;
205 mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
207 if (MathIsInset(cx)) {
208 MathedInset * p = data.GetInset();
211 if (cx == LM_TC_UP) {
212 asc += (limits) ? p->Height() + 4: p->Ascent() +
213 ((p->Descent()>asc) ? p->Descent() - asc + 4: 0);
215 if (cx == LM_TC_DOWN) {
216 des += ((limits) ? p->Height() + 4: p->Height() - p->Ascent() / 2);
221 if (asc > ascent) ascent = asc;
222 if (des > descent) descent = des;
223 if (cx!= LM_TC_UP && cx!= LM_TC_DOWN)
224 limits = p->GetLimits();
227 if (cx == LM_TC_TAB) {
229 data.GetIncPos(x, y);
230 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
231 if (ascent<df_asc) ascent = df_asc;
234 data.setTab(x-tb, tab);
240 if (cx == LM_TC_CR) {
243 data.GetIncPos(x, y);
244 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
245 if (ascent<df_asc) ascent = df_asc;
248 data.setTab(x - tb, tab);
249 } else //if (GetColumns() == 1)
252 data.GetIncPos(x, y);
254 if (ascent<df_asc) ascent = df_asc;
257 data.subMetrics(ascent, descent);
262 lyxerr << "Mathed Error: Unrecognized code[" << cx
268 data.GetIncPos(width, ls);
270 // No matter how simple is a matrix, it is NOT a subparagraph
272 if (cxp == LM_TC_TAB) {
273 if (ascent<df_asc) ascent = df_asc;
276 data.setTab(width - tb, tab);
280 data.subMetrics(ascent, descent);
285 void MathParInset::Write(ostream & os, bool fragile)
290 MathedIter data(array);
292 MathedRowSt const * crow = getRowSt();
295 if (!Permit(LMPF_FIXED_SIZE)) {
296 l = lm_get_key_by_id(size(), LM_TK_STY);
298 os << '\\' << l->name << ' ';
302 byte cx = data.GetChar();
304 string str = data.GetString();
306 if (data.FCode() >= LM_TC_RM && data.FCode() <= LM_TC_TEXTRM) {
307 os << '\\' << math_font_name[data.FCode()-LM_TC_RM] << '{';
309 for (string::const_iterator s = str.begin();
310 s != str.end(); ++s) {
312 if (MathIsSymbol(data.FCode())) {
313 l = lm_get_key_by_id(c, (data.FCode() == LM_TC_BSYM) ?
314 LM_TK_BIGSYM : LM_TK_SYM);
316 os << '\\' << l->name << ' ';
318 #warning this does not compile on gcc 2.97
319 //lyxerr << "Illegal symbol code[" << c
320 // << " " << str.end() - s << " " << data.FCode() << "]";
323 // Is there a standard logical XOR?
324 if ((data.FCode() == LM_TC_TEX && c != '{' && c != '}') ||
325 (data.FCode() == LM_TC_SPECIAL))
328 if (c == '{') ++brace;
329 if (c == '}') --brace;
331 if (c == '}' && data.FCode() == LM_TC_TEX && brace < 0)
332 lyxerr <<"Math warning: Unexpected closing brace."
338 if (data.FCode()>= LM_TC_RM && data.FCode()<= LM_TC_TEXTRM)
341 if (MathIsInset(cx)) {
342 MathedInset * p = data.GetInset();
345 if (cx == LM_TC_DOWN)
347 p->Write(os, fragile);
348 if (cx == LM_TC_UP || cx == LM_TC_DOWN)
362 if (!crow->isNumbered()) {
365 if (!crow->getLabel().empty()) {
370 crow = crow->getNext();
375 ++number_of_newlines;
380 lyxerr << "WMath Error: unrecognized code[" << cx << "]";
386 if (!crow->isNumbered()) {
389 if (!crow->getLabel().empty()) {
397 os << string(brace, '}');
401 bool MathParInset::Inside(int x, int y)
403 return (x >= xo() && x <= xo() + width
404 && y <= yo() + descent && y >= yo() - ascent);
408 void MathParInset::GetXY(int & x, int & y) const
415 void MathParInset::UserSetSize(short sz)
419 flag = flag & ~LMPF_FIXED_SIZE;
424 void MathParInset::SetStyle(short sz)
426 if (Permit(LMPF_FIXED_SIZE)) {
427 if (Permit(LMPF_SCRIPT))
428 sz = (sz < LM_ST_SCRIPT) ? LM_ST_SCRIPT: LM_ST_SCRIPTSCRIPT;
429 if (Permit(LMPF_SMALLER) && sz < LM_ST_SCRIPTSCRIPT) {
432 MathedInset::SetStyle(sz);
437 bool MathParInset::Permit(short f) const
439 return bool(f & flag);
443 MathedArray * MathParInset::GetData()
449 void MathParInset::setXY(int x, int y)