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)
33 if (objtype == LM_OT_SCRIPT)
38 MathParInset::MathParInset(MathParInset * p)
43 MathedIter it(p->GetData());
48 MathParInset::~MathParInset()
53 MathedInset * MathParInset::Clone()
55 return new MathParInset(this);
59 void MathParInset::setData(MathedArray * a)
63 // A standard paragraph shouldn't have any tabs nor CRs.
64 MathedIter it(&array);
66 char c = it.GetChar();
67 if (c == LM_TC_TAB || c == LM_TC_CR)
76 MathParInset::draw(Painter & pain, int x, int y)
87 MathedXIter data(this);
89 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
92 MathedXIter data(this);
96 byte cx = data.GetChar();
98 string s = data.GetString();
99 drawStr(pain, data.fcode(), size(), x, y, s);
100 mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
106 if (MathIsInset(cx)) {
108 MathedInset * p = data.GetInset();
109 if (cx == LM_TC_UP) {
111 x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
112 yy -= (asc + p->Descent()+4);
115 yy -= (p->Descent()>asc) ? p->Descent()+4: asc;
117 else if (cx == LM_TC_DOWN) {
119 x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
120 yy += des + p->Ascent() + 2;
122 yy += des + p->Ascent()/2;
128 p->draw(pain, x, yy);
129 if (cx!= LM_TC_UP && cx!= LM_TC_DOWN) {
130 limits = p->GetLimits();
136 else if (cx == LM_TC_TAB) {
137 if (cxp == cx || cxp == LM_TC_CR || data.IsFirst()) {
138 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
143 else if (cx == LM_TC_CR) {
144 if (cxp == LM_TC_TAB || cxp == LM_TC_CR || data.IsFirst()) {
145 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
151 lyxerr << "GMathed Error: Unrecognized code[" << cx << "]" << endl;
157 if (cxp == LM_TC_TAB || cxp == LM_TC_CR) {
159 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
165 MathParInset::Metrics()
177 ascent = df_asc;//mathed_char_height(LM_TC_VAR, size, 'I', asc, des);
180 if (array.empty()) return;
183 MathedXIter data(this);
188 string s = data.GetString();
189 mathed_string_height(data.fcode(),
190 size(), s, asc, des);
191 if (asc > ascent) ascent = asc;
192 if (des > descent) descent = des;
194 mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
196 if (MathIsInset(cx)) {
197 MathedInset * p = data.GetInset();
200 if (cx == LM_TC_UP) {
201 asc += (limits) ? p->Height() + 4: p->Ascent() +
202 ((p->Descent()>asc) ? p->Descent() - asc + 4: 0);
204 if (cx == LM_TC_DOWN) {
205 des += ((limits) ? p->Height() + 4: p->Height() - p->Ascent() / 2);
210 if (asc > ascent) ascent = asc;
211 if (des > descent) descent = des;
212 if (cx!= LM_TC_UP && cx!= LM_TC_DOWN)
213 limits = p->GetLimits();
216 if (cx == LM_TC_TAB) {
218 data.GetIncPos(x, y);
219 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
220 if (ascent<df_asc) ascent = df_asc;
223 data.setTab(x-tb, tab);
229 if (cx == LM_TC_CR) {
232 data.GetIncPos(x, y);
233 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
234 if (ascent<df_asc) ascent = df_asc;
237 data.setTab(x - tb, tab);
238 } else //if (GetColumns() == 1)
241 data.GetIncPos(x, y);
243 if (ascent<df_asc) ascent = df_asc;
246 data.subMetrics(ascent, descent);
251 lyxerr << "Mathed Error: Unrecognized code[" << cx
257 data.GetIncPos(width, ls);
259 // No matter how simple is a matrix, it is NOT a subparagraph
261 if (cxp == LM_TC_TAB) {
262 if (ascent<df_asc) ascent = df_asc;
265 data.setTab(width - tb, tab);
269 data.subMetrics(ascent, descent);
274 void MathParInset::Write(ostream & os, bool fragile)
276 if (array.empty()) return;
279 MathedIter data(&array);
281 MathedRowSt const * crow = getRowSt();
284 if (!Permit(LMPF_FIXED_SIZE)) {
285 l = lm_get_key_by_id(size(), LM_TK_STY);
287 os << '\\' << l->name << ' ';
291 byte cx = data.GetChar();
293 string str = data.GetString();
295 if (data.fcode() >= LM_TC_RM && data.fcode() <= LM_TC_TEXTRM) {
296 os << '\\' << math_font_name[data.fcode()-LM_TC_RM] << '{';
298 for (string::const_iterator s = str.begin();
299 s != str.end(); ++s) {
301 if (MathIsSymbol(data.fcode())) {
302 l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ?
303 LM_TK_BIGSYM : LM_TK_SYM);
305 os << '\\' << l->name << ' ';
307 #warning this does not compile on gcc 2.97
308 //lyxerr << "Illegal symbol code[" << c
309 // << " " << str.end() - s << " " << data.fcode() << "]";
312 // Is there a standard logical XOR?
313 if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') ||
314 (data.fcode() == LM_TC_SPECIAL))
317 if (c == '{') ++brace;
318 if (c == '}') --brace;
320 if (c == '}' && data.fcode() == LM_TC_TEX && brace < 0)
321 lyxerr <<"Math warning: Unexpected closing brace."
327 if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
330 if (MathIsInset(cx)) {
331 MathedInset * p = data.GetInset();
334 if (cx == LM_TC_DOWN)
336 p->Write(os, fragile);
337 if (cx == LM_TC_UP || cx == LM_TC_DOWN)
351 if (!crow->isNumbered()) {
354 if (!crow->getLabel().empty()) {
359 crow = crow->getNext();
364 ++number_of_newlines;
369 lyxerr << "WMath Error: unrecognized code[" << cx << "]";
375 if (!crow->isNumbered()) {
378 if (!crow->getLabel().empty()) {
386 os << string(brace, '}');
390 bool MathParInset::Inside(int x, int y)
392 return (x >= xo() && x <= xo() + width
393 && y <= yo() + descent && y >= yo() - ascent);
397 void MathParInset::GetXY(int & x, int & y) const
404 void MathParInset::UserSetSize(short sz)
408 flag = flag & ~LMPF_FIXED_SIZE;
413 void MathParInset::SetStyle(short sz)
415 if (Permit(LMPF_FIXED_SIZE)) {
416 if (Permit(LMPF_SCRIPT))
417 sz = (sz < LM_ST_SCRIPT) ? LM_ST_SCRIPT: LM_ST_SCRIPTSCRIPT;
418 if (Permit(LMPF_SMALLER) && sz < LM_ST_SCRIPTSCRIPT) {
421 MathedInset::SetStyle(sz);
426 bool MathParInset::Permit(short f) const
428 return bool(f & flag);
432 MathedArray * MathParInset::GetData()
438 void MathParInset::setXY(int x, int y)