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"
16 extern int number_of_newlines;
19 MathedRowSt * MathParInset::getRowSt() const
25 MathParInset::MathParInset(short st, string const & nm, short ot)
26 : MathedInset(nm, ot, st)
33 if (objtype == LM_OT_SCRIPT)
38 MathParInset::MathParInset(MathParInset * p)
43 MathedIter it(p->GetData());
48 MathParInset::~MathParInset()
58 MathedInset * MathParInset::Clone()
60 return new MathParInset(this);
64 void MathParInset::SetData(MathedArray * a)
68 // A standard paragraph shouldn't have any tabs nor CRs.
72 char c = it.GetChar();
73 if (c == LM_TC_TAB || c == LM_TC_CR)
83 MathParInset::draw(Painter & pain, int x, int y)
87 int asc = df_asc, des = 0;
91 if (!array || array->empty()) {
93 MathedXIter data(this);
96 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
99 MathedXIter data(this);
103 byte cx = data.GetChar();
105 string s = data.GetString();
106 drawStr(pain, data.FCode(), size, x, y, s);
107 mathed_char_height(LM_TC_CONST, size, 'y', asc, des);
113 if (MathIsInset(cx)) {
115 MathedInset * p = data.GetInset();
116 if (cx == LM_TC_UP) {
118 x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
119 yy -= (asc + p->Descent()+4);
122 yy -= (p->Descent()>asc) ? p->Descent()+4: asc;
124 else if (cx == LM_TC_DOWN) {
126 x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
127 yy += des + p->Ascent() + 2;
129 yy += des + p->Ascent()/2;
135 p->draw(pain, x, yy);
136 if (cx!= LM_TC_UP && cx!= LM_TC_DOWN) {
137 limits = p->GetLimits();
143 else if (cx == LM_TC_TAB) {
144 if (cxp == cx || cxp == LM_TC_CR || data.IsFirst()) {
145 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
150 else if (cx == LM_TC_CR) {
151 if (cxp == LM_TC_TAB || cxp == LM_TC_CR || data.IsFirst()) {
152 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
158 lyxerr << "GMathed Error: Unrecognized code[" << cx << "]" << endl;
164 if (cxp == LM_TC_TAB || cxp == LM_TC_CR) {
166 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
172 MathParInset::Metrics()
184 ascent = df_asc;//mathed_char_height(LM_TC_VAR, size, 'I', asc, des);
188 if (array->empty()) return;
191 MathedXIter data(this);
196 string s = data.GetString();
197 mathed_string_height(data.FCode(), size, s, asc, des);
198 if (asc > ascent) ascent = asc;
199 if (des > descent) descent = des;
201 mathed_char_height(LM_TC_CONST, size, 'y', asc, des);
203 if (MathIsInset(cx)) {
204 MathedInset * p = data.GetInset();
207 if (cx == LM_TC_UP) {
208 asc += (limits) ? p->Height() + 4: p->Ascent() +
209 ((p->Descent()>asc) ? p->Descent() - asc + 4: 0);
211 if (cx == LM_TC_DOWN) {
212 des += ((limits) ? p->Height() + 4: p->Height() - p->Ascent() / 2);
217 if (asc > ascent) ascent = asc;
218 if (des > descent) descent = des;
219 if (cx!= LM_TC_UP && cx!= LM_TC_DOWN)
220 limits = p->GetLimits();
223 if (cx == LM_TC_TAB) {
225 data.GetIncPos(x, y);
226 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
227 if (ascent<df_asc) ascent = df_asc;
230 data.setTab(x-tb, tab);
236 if (cx == LM_TC_CR) {
239 data.GetIncPos(x, y);
240 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
241 if (ascent<df_asc) ascent = df_asc;
244 data.setTab(x - tb, tab);
245 } else //if (GetColumns() == 1)
248 data.GetIncPos(x, y);
250 if (ascent<df_asc) ascent = df_asc;
253 data.subMetrics(ascent, descent);
258 lyxerr << "Mathed Error: Unrecognized code[" << cx
264 data.GetIncPos(width, ls);
266 // No matter how simple is a matrix, it is NOT a subparagraph
268 if (cxp == LM_TC_TAB) {
269 if (ascent<df_asc) ascent = df_asc;
272 data.setTab(width - tb, tab);
276 data.subMetrics(ascent, descent);
281 void MathParInset::Write(ostream & os, bool fragile)
286 MathedIter data(array);
288 MathedRowSt const * crow = getRowSt();
291 if (!Permit(LMPF_FIXED_SIZE)) {
292 l = lm_get_key_by_id(size, LM_TK_STY);
294 os << '\\' << l->name << ' ';
298 byte cx = data.GetChar();
300 string str = data.GetString();
302 if (data.FCode() >= LM_TC_RM && data.FCode() <= LM_TC_TEXTRM) {
303 os << '\\' << math_font_name[data.FCode()-LM_TC_RM] << '{';
305 for (string::const_iterator s = str.begin();
306 s != str.end(); ++s) {
308 if (MathIsSymbol(data.FCode())) {
309 l = lm_get_key_by_id(c, (data.FCode() == LM_TC_BSYM) ?
310 LM_TK_BIGSYM : LM_TK_SYM);
312 os << '\\' << l->name << ' ';
314 #warning this does not compile on gcc 2.97
315 //lyxerr << "Illegal symbol code[" << c
316 // << " " << str.end() - s << " " << data.FCode() << "]";
319 // Is there a standard logical XOR?
320 if ((data.FCode() == LM_TC_TEX && c != '{' && c != '}') ||
321 (data.FCode() == LM_TC_SPECIAL))
324 if (c == '{') ++brace;
325 if (c == '}') --brace;
327 if (c == '}' && data.FCode() == LM_TC_TEX && brace < 0)
328 lyxerr <<"Math warning: Unexpected closing brace."
334 if (data.FCode()>= LM_TC_RM && data.FCode()<= LM_TC_TEXTRM)
337 if (MathIsInset(cx)) {
338 MathedInset * p = data.GetInset();
341 if (cx == LM_TC_DOWN)
343 p->Write(os, fragile);
344 if (cx == LM_TC_UP || cx == LM_TC_DOWN)
358 if (!crow->isNumbered()) {
361 if (!crow->getLabel().empty()) {
366 crow = crow->getNext();
371 ++number_of_newlines;
376 lyxerr << "WMath Error: unrecognized code[" << cx << "]";
382 if (!crow->isNumbered()) {
385 if (!crow->getLabel().empty()) {
393 os << string(brace, '}');