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"
14 extern int number_of_newlines;
17 MathedRowSt * MathParInset::getRowSt() const
23 MathParInset::MathParInset(short st, string const & nm, short ot)
24 : MathedInset(nm, ot, st)
31 if (objtype == LM_OT_SCRIPT)
36 MathParInset::MathParInset(MathParInset * p)
41 MathedIter it(p->GetData());
46 MathParInset::~MathParInset()
56 MathedInset * MathParInset::Clone()
58 return new MathParInset(this);
62 void MathParInset::SetData(MathedArray * a)
66 // A standard paragraph shouldn't have any tabs nor CRs.
70 char c = it.GetChar();
71 if (c == LM_TC_TAB || c == LM_TC_CR)
81 MathParInset::draw(Painter & pain, int x, int y)
85 int asc = df_asc, des = 0;
89 if (!array || array->empty()) {
91 MathedXIter data(this);
94 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
97 MathedXIter data(this);
101 byte cx = data.GetChar();
103 string s = data.GetString();
104 drawStr(pain, data.FCode(), size, x, y, s);
105 mathed_char_height(LM_TC_CONST, size, 'y', asc, des);
111 if (MathIsInset(cx)) {
113 MathedInset * p = data.GetInset();
114 if (cx == LM_TC_UP) {
116 x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
117 yy -= (asc + p->Descent()+4);
120 yy -= (p->Descent()>asc) ? p->Descent()+4: asc;
122 else if (cx == LM_TC_DOWN) {
124 x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
125 yy += des + p->Ascent() + 2;
127 yy += des + p->Ascent()/2;
133 p->draw(pain, x, yy);
134 if (cx!= LM_TC_UP && cx!= LM_TC_DOWN) {
135 limits = p->GetLimits();
141 else if (cx == LM_TC_TAB) {
142 if (cxp == cx || cxp == LM_TC_CR || data.IsFirst()) {
143 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
148 else if (cx == LM_TC_CR) {
149 if (cxp == LM_TC_TAB || cxp == LM_TC_CR || data.IsFirst()) {
150 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
156 lyxerr << "GMathed Error: Unrecognized code[" << cx << "]" << endl;
162 if (cxp == LM_TC_TAB || cxp == LM_TC_CR) {
164 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
170 MathParInset::Metrics()
182 ascent = df_asc;//mathed_char_height(LM_TC_VAR, size, 'I', asc, des);
186 if (array->empty()) return;
189 MathedXIter data(this);
194 string s = data.GetString();
195 mathed_string_height(data.FCode(), size, s, asc, des);
196 if (asc > ascent) ascent = asc;
197 if (des > descent) descent = des;
199 mathed_char_height(LM_TC_CONST, size, 'y', asc, des);
201 if (MathIsInset(cx)) {
202 MathedInset * p = data.GetInset();
205 if (cx == LM_TC_UP) {
206 asc += (limits) ? p->Height() + 4: p->Ascent() +
207 ((p->Descent()>asc) ? p->Descent() - asc + 4: 0);
209 if (cx == LM_TC_DOWN) {
210 des += ((limits) ? p->Height() + 4: p->Height() - p->Ascent() / 2);
215 if (asc > ascent) ascent = asc;
216 if (des > descent) descent = des;
217 if (cx!= LM_TC_UP && cx!= LM_TC_DOWN)
218 limits = p->GetLimits();
221 if (cx == LM_TC_TAB) {
223 data.GetIncPos(x, y);
224 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
225 if (ascent<df_asc) ascent = df_asc;
228 data.setTab(x-tb, tab);
234 if (cx == LM_TC_CR) {
237 data.GetIncPos(x, y);
238 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
239 if (ascent<df_asc) ascent = df_asc;
242 data.setTab(x - tb, tab);
243 } else //if (GetColumns() == 1)
246 data.GetIncPos(x, y);
248 if (ascent<df_asc) ascent = df_asc;
251 data.subMetrics(ascent, descent);
256 lyxerr << "Mathed Error: Unrecognized code[" << cx
262 data.GetIncPos(width, ls);
264 // No matter how simple is a matrix, it is NOT a subparagraph
266 if (cxp == LM_TC_TAB) {
267 if (ascent<df_asc) ascent = df_asc;
270 data.setTab(width - tb, tab);
274 data.subMetrics(ascent, descent);
279 void MathParInset::Write(ostream & os, bool fragile)
284 MathedIter data(array);
286 MathedRowSt const * crow = getRowSt();
289 if (!Permit(LMPF_FIXED_SIZE)) {
290 l = lm_get_key_by_id(size, LM_TK_STY);
292 os << '\\' << l->name << ' ';
296 byte cx = data.GetChar();
298 string str = data.GetString();
300 if (data.FCode() >= LM_TC_RM && data.FCode() <= LM_TC_TEXTRM) {
301 os << '\\' << math_font_name[data.FCode()-LM_TC_RM] << '{';
303 for (string::const_iterator s = str.begin();
304 s != str.end(); ++s) {
306 if (MathIsSymbol(data.FCode())) {
307 l = lm_get_key_by_id(c, (data.FCode() == LM_TC_BSYM) ?
308 LM_TK_BIGSYM : LM_TK_SYM);
310 os << '\\' << l->name << ' ';
312 #warning this does not compile on gcc 2.97
313 //lyxerr << "Illegal symbol code[" << c
314 // << " " << str.end() - s << " " << data.FCode() << "]";
317 // Is there a standard logical XOR?
318 if ((data.FCode() == LM_TC_TEX && c != '{' && c != '}') ||
319 (data.FCode() == LM_TC_SPECIAL))
322 if (c == '{') ++brace;
323 if (c == '}') --brace;
325 if (c == '}' && data.FCode() == LM_TC_TEX && brace < 0)
326 lyxerr <<"Math warning: Unexpected closing brace."
332 if (data.FCode()>= LM_TC_RM && data.FCode()<= LM_TC_TEXTRM)
335 if (MathIsInset(cx)) {
336 MathedInset * p = data.GetInset();
339 if (cx == LM_TC_DOWN)
341 p->Write(os, fragile);
342 if (cx == LM_TC_UP || cx == LM_TC_DOWN)
356 if (!crow->isNumbered()) {
359 if (!crow->getLabel().empty()) {
364 crow = crow->getNext();
369 ++number_of_newlines;
374 lyxerr << "WMath Error: unrecognized code[" << cx << "]";
380 if (!crow->isNumbered()) {
383 if (!crow->getLabel().empty()) {
391 os << string(brace, '}');