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)
88 int asc = df_asc, des = 0;
92 if (!array || array->empty()) {
94 MathedXIter data(this);
97 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
100 MathedXIter data(this);
104 byte cx = data.GetChar();
106 string s = data.GetString();
107 drawStr(pain, data.FCode(), size, x, y, s);
108 mathed_char_height(LM_TC_CONST, size, 'y', asc, des);
114 if (MathIsInset(cx)) {
116 MathedInset * p = data.GetInset();
117 if (cx == LM_TC_UP) {
119 x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
120 yy -= (asc + p->Descent()+4);
123 yy -= (p->Descent()>asc) ? p->Descent()+4: asc;
125 else if (cx == LM_TC_DOWN) {
127 x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
128 yy += des + p->Ascent() + 2;
130 yy += des + p->Ascent()/2;
136 p->draw(pain, x, yy);
137 if (cx!= LM_TC_UP && cx!= LM_TC_DOWN) {
138 limits = p->GetLimits();
144 else if (cx == LM_TC_TAB) {
145 if (cxp == cx || cxp == LM_TC_CR || data.IsFirst()) {
146 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
151 else if (cx == LM_TC_CR) {
152 if (cxp == LM_TC_TAB || cxp == LM_TC_CR || data.IsFirst()) {
153 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
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, LColor::mathline);
173 MathParInset::Metrics()
185 ascent = df_asc;//mathed_char_height(LM_TC_VAR, size, 'I', asc, des);
189 if (array->empty()) return;
192 MathedXIter data(this);
197 string s = data.GetString();
198 mathed_string_height(data.FCode(), size, s, asc, des);
199 if (asc > ascent) ascent = asc;
200 if (des > descent) descent = des;
202 mathed_char_height(LM_TC_CONST, size, 'y', asc, des);
204 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);
212 if (cx == LM_TC_DOWN) {
213 des += ((limits) ? p->Height() + 4: p->Height() - p->Ascent() / 2);
218 if (asc > ascent) ascent = asc;
219 if (des > descent) descent = des;
220 if (cx!= LM_TC_UP && cx!= LM_TC_DOWN)
221 limits = p->GetLimits();
224 if (cx == LM_TC_TAB) {
226 data.GetIncPos(x, y);
227 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
228 if (ascent<df_asc) ascent = df_asc;
231 data.setTab(x-tb, tab);
237 if (cx == LM_TC_CR) {
240 data.GetIncPos(x, y);
241 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
242 if (ascent<df_asc) ascent = df_asc;
245 data.setTab(x - tb, tab);
246 } else //if (GetColumns() == 1)
249 data.GetIncPos(x, y);
251 if (ascent<df_asc) ascent = df_asc;
254 data.subMetrics(ascent, descent);
259 lyxerr << "Mathed Error: Unrecognized code[" << cx
265 data.GetIncPos(width, ls);
267 // No matter how simple is a matrix, it is NOT a subparagraph
269 if (cxp == LM_TC_TAB) {
270 if (ascent<df_asc) ascent = df_asc;
273 data.setTab(width - tb, tab);
277 data.subMetrics(ascent, descent);
282 void MathParInset::Write(ostream & os, bool fragile)
287 MathedIter data(array);
289 MathedRowSt const * crow = getRowSt();
292 if (!Permit(LMPF_FIXED_SIZE)) {
293 l = lm_get_key_by_id(size, LM_TK_STY);
295 os << '\\' << l->name << ' ';
299 byte cx = data.GetChar();
301 string str = data.GetString();
303 if (data.FCode() >= LM_TC_RM && data.FCode() <= LM_TC_TEXTRM) {
304 os << '\\' << math_font_name[data.FCode()-LM_TC_RM] << '{';
306 for (string::const_iterator s = str.begin();
307 s != str.end(); ++s) {
309 if (MathIsSymbol(data.FCode())) {
310 l = lm_get_key_by_id(c, (data.FCode() == LM_TC_BSYM) ?
311 LM_TK_BIGSYM : LM_TK_SYM);
313 os << '\\' << l->name << ' ';
315 #warning this does not compile on gcc 2.97
316 //lyxerr << "Illegal symbol code[" << c
317 // << " " << str.end() - s << " " << data.FCode() << "]";
320 // Is there a standard logical XOR?
321 if ((data.FCode() == LM_TC_TEX && c != '{' && c != '}') ||
322 (data.FCode() == LM_TC_SPECIAL))
325 if (c == '{') ++brace;
326 if (c == '}') --brace;
328 if (c == '}' && data.FCode() == LM_TC_TEX && brace < 0)
329 lyxerr <<"Math warning: Unexpected closing brace."
335 if (data.FCode()>= LM_TC_RM && data.FCode()<= LM_TC_TEXTRM)
338 if (MathIsInset(cx)) {
339 MathedInset * p = data.GetInset();
342 if (cx == LM_TC_DOWN)
344 p->Write(os, fragile);
345 if (cx == LM_TC_UP || cx == LM_TC_DOWN)
359 if (!crow->isNumbered()) {
362 if (!crow->getLabel().empty()) {
367 crow = crow->getNext();
372 ++number_of_newlines;
377 lyxerr << "WMath Error: unrecognized code[" << cx << "]";
383 if (!crow->isNumbered()) {
386 if (!crow->getLabel().empty()) {
394 os << string(brace, '}');
398 bool MathParInset::Inside(int x, int y)
400 return (x >= xo && x <= xo + width
401 && y <= yo + descent && y >= yo - ascent);
405 void MathParInset::GetXY(int & x, int & y) const
412 void MathParInset::UserSetSize(short sz)
416 flag = flag & ~LMPF_FIXED_SIZE;
421 void MathParInset::SetStyle(short sz)
423 if (Permit(LMPF_FIXED_SIZE)) {
424 if (Permit(LMPF_SCRIPT))
425 sz = (sz < LM_ST_SCRIPT) ? LM_ST_SCRIPT: LM_ST_SCRIPTSCRIPT;
426 if (Permit(LMPF_SMALLER) && sz < LM_ST_SCRIPTSCRIPT) {
429 MathedInset::SetStyle(sz);
434 void MathParInset::setFlag(MathedParFlag f)
440 bool MathParInset::Permit(short f) const
442 return bool(f & flag);
446 MathedArray * MathParInset::GetData()
452 void MathParInset::setXY(int x, int y)