7 #include "math_parinset.h"
10 #include "math_xiter.h"
12 #include "mathed/support.h"
14 #include "math_parser.h"
15 #include "math_rowst.h"
16 #include "math_parinset.h"
21 extern int number_of_newlines;
24 MathedRowContainer & MathParInset::getRowSt()
26 static MathedRowContainer dummy;
31 MathParInset::MathParInset(short st, string const & nm, short ot)
32 : MathedInset(nm, ot, st)
38 if (objtype == LM_OT_SCRIPT)
43 MathedInset * MathParInset::Clone()
45 return new MathParInset(*this);
49 void MathParInset::setData(MathedArray const & a)
53 // A standard paragraph shouldn't have any tabs nor CRs.
54 MathedIter it(&array);
56 char c = it.GetChar();
57 if (c == LM_TC_TAB || c == LM_TC_CR)
66 MathParInset::draw(Painter & pain, int x, int y)
76 MathedXIter data(this);
78 //MathedXIter data(this);
80 pain.rectangle(x, y - df_asc, df_width, df_asc,
84 //MathedXIter data(this);
88 byte const cx = data.GetChar();
90 string const s = data.GetString();
91 drawStr(pain, data.fcode(), size(), x, y, s);
92 mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
96 } else if (MathIsInset(cx)) {
98 MathedInset * p = data.GetInset();
101 x -= (xp > p->Width()) ?
102 p->Width() + (xp - p->Width()) / 2 : xp;
103 yy -= (asc + p->Descent() + 4);
105 yy -= (p->Descent() > asc) ?
106 p->Descent() + 4 : asc;
107 } else if (cx == LM_TC_DOWN) {
109 x -= (xp > p->Width()) ?
110 p->Width() + (xp - p->Width()) / 2 : xp;
111 yy += des + p->Ascent() + 2;
113 yy += des + p->Ascent() / 2;
118 p->draw(pain, x, yy);
119 if (cx != LM_TC_UP && cx != LM_TC_DOWN) {
120 limits = p->GetLimits();
125 } else if (cx == LM_TC_TAB) {
127 || cxp == LM_TC_CR || data.IsFirst()) {
128 pain.rectangle(x, y - df_asc,
134 } else if (cx == LM_TC_CR) {
136 || cxp == LM_TC_CR || data.IsFirst()) {
137 pain.rectangle(x, y - df_asc,
144 lyxerr << "GMathed Error: Unrecognized code[" << cx << "]" << endl;
150 if (cxp == LM_TC_TAB || cxp == LM_TC_CR) {
152 pain.rectangle(x, y - df_asc, df_width, df_asc,
159 MathParInset::Metrics()
171 ascent = df_asc;//mathed_char_height(LM_TC_VAR, size, 'I', asc, des);
174 if (array.empty()) return;
177 MathedXIter data(this);
182 string const s = data.GetString();
183 mathed_string_height(data.fcode(),
184 size(), s, asc, des);
185 if (asc > ascent) ascent = asc;
186 if (des > descent) descent = des;
188 mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
189 } else if (MathIsInset(cx)) {
190 MathedInset * p = data.GetInset();
193 if (cx == LM_TC_UP) {
194 asc += (limits) ? p->Height() + 4: p->Ascent() +
195 ((p->Descent()>asc) ? p->Descent() - asc + 4: 0);
196 } else if (cx == LM_TC_DOWN) {
197 des += (limits ? p->Height() + 4 : p->Height() - p->Ascent() / 2);
202 if (asc > ascent) ascent = asc;
203 if (des > descent) descent = des;
204 if (cx!= LM_TC_UP && cx!= LM_TC_DOWN)
205 limits = p->GetLimits();
207 } else if (cx == LM_TC_TAB) {
210 data.GetIncPos(x, y);
211 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
212 if (ascent < df_asc) ascent = df_asc;
215 data.setTab(x - tb, tab);
220 } else if (cx == LM_TC_CR) {
224 data.GetIncPos(x, y);
225 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
226 if (ascent < df_asc) ascent = df_asc;
229 data.setTab(x - tb, tab);
230 } else //if (GetColumns() == 1)
234 data.GetIncPos(x, y);
236 if (ascent < df_asc) ascent = df_asc;
239 data.subMetrics(ascent, descent);
244 lyxerr << "Mathed Error: Unrecognized code[" << cx
250 data.GetIncPos(width, ls);
252 // No matter how simple is a matrix, it is NOT a subparagraph
254 if (cxp == LM_TC_TAB) {
255 if (ascent<df_asc) ascent = df_asc;
258 data.setTab(width - tb, tab);
262 data.subMetrics(ascent, descent);
267 void MathParInset::Write(ostream & os, bool fragile)
269 if (array.empty()) return;
272 MathedIter data(&array);
274 MathedRowContainer::iterator crow = getRowSt().begin();
277 if (!Permit(LMPF_FIXED_SIZE)) {
278 l = lm_get_key_by_id(size(), LM_TK_STY);
280 os << '\\' << l->name << ' ';
284 byte cx = data.GetChar();
286 string str = data.GetString();
288 if (data.fcode() >= LM_TC_RM && data.fcode() <= LM_TC_TEXTRM) {
289 os << '\\' << math_font_name[data.fcode()-LM_TC_RM] << '{';
291 for (string::const_iterator s = str.begin();
292 s != str.end(); ++s) {
294 if (MathIsSymbol(data.fcode())) {
295 l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ?
296 LM_TK_BIGSYM : LM_TK_SYM);
298 os << '\\' << l->name << ' ';
300 #warning this does not compile on gcc 2.97
301 //lyxerr << "Illegal symbol code[" << c
302 // << " " << str.end() - s << " " << data.fcode() << "]";
305 // Is there a standard logical XOR?
306 if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') ||
307 (data.fcode() == LM_TC_SPECIAL))
310 if (c == '{') ++brace;
311 if (c == '}') --brace;
313 if (c == '}' && data.fcode() == LM_TC_TEX && brace < 0)
314 lyxerr <<"Math warning: Unexpected closing brace."
320 if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
323 if (MathIsInset(cx)) {
324 MathedInset * p = data.GetInset();
327 if (cx == LM_TC_DOWN)
329 p->Write(os, fragile);
330 if (cx == LM_TC_UP || cx == LM_TC_DOWN)
344 if (!crow->isNumbered()) {
347 if (!crow->getLabel().empty()) {
357 ++number_of_newlines;
362 lyxerr << "WMath Error: unrecognized code[" << cx << "]";
368 if (!crow->isNumbered()) {
371 if (!crow->getLabel().empty()) {
379 os << string(brace, '}');
383 void MathParInset::clear()
388 bool MathParInset::Inside(int x, int y)
390 return (x >= xo() && x <= xo() + width
391 && y <= yo() + descent && y >= yo() - ascent);
395 void MathParInset::GetXY(int & x, int & y) const
402 void MathParInset::UserSetSize(short sz)
406 flag = flag & ~LMPF_FIXED_SIZE;
411 void MathParInset::SetStyle(short sz)
413 if (Permit(LMPF_FIXED_SIZE)) {
414 if (Permit(LMPF_SCRIPT))
415 sz = (sz < LM_ST_SCRIPT) ? LM_ST_SCRIPT: LM_ST_SCRIPTSCRIPT;
416 if (Permit(LMPF_SMALLER) && sz < LM_ST_SCRIPTSCRIPT) {
419 MathedInset::SetStyle(sz);
424 bool MathParInset::Permit(short f) const
426 return bool(f & flag);
430 MathedArray & MathParInset::GetData()
436 MathedArray const & MathParInset::GetData() const
442 void MathParInset::setXY(int x, int y)