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()
30 MathParInset::MathParInset(short st, string const & nm, short ot)
31 : MathedInset(nm, ot, st)
37 if (objtype == LM_OT_SCRIPT)
42 MathedInset * MathParInset::Clone()
44 return new MathParInset(*this);
48 void MathParInset::setData(MathedArray const & a)
52 // A standard paragraph shouldn't have any tabs nor CRs.
53 MathedIter it(&array);
55 char c = it.GetChar();
56 if (c == LM_TC_TAB || c == LM_TC_CR)
65 MathParInset::draw(Painter & pain, int x, int y)
75 MathedXIter data(this);
77 //MathedXIter data(this);
79 pain.rectangle(x, y - df_asc, df_width, df_asc,
83 //MathedXIter data(this);
87 byte const cx = data.GetChar();
89 string const s = data.GetString();
90 drawStr(pain, data.fcode(), size(), x, y, s);
91 mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
95 } else if (MathIsInset(cx)) {
97 MathedInset * p = data.GetInset();
100 x -= (xp > p->Width()) ?
101 p->Width() + (xp - p->Width()) / 2 : xp;
102 yy -= (asc + p->Descent() + 4);
104 yy -= (p->Descent() > asc) ?
105 p->Descent() + 4 : asc;
106 } else if (cx == LM_TC_DOWN) {
108 x -= (xp > p->Width()) ?
109 p->Width() + (xp - p->Width()) / 2 : xp;
110 yy += des + p->Ascent() + 2;
112 yy += des + p->Ascent() / 2;
117 p->draw(pain, x, yy);
118 if (cx != LM_TC_UP && cx != LM_TC_DOWN) {
119 limits = p->GetLimits();
124 } else if (cx == LM_TC_TAB) {
126 || cxp == LM_TC_CR || data.IsFirst()) {
127 pain.rectangle(x, y - df_asc,
133 } else if (cx == LM_TC_CR) {
135 || cxp == LM_TC_CR || data.IsFirst()) {
136 pain.rectangle(x, y - df_asc,
143 lyxerr << "GMathed Error: Unrecognized code[" << cx << "]" << endl;
149 if (cxp == LM_TC_TAB || cxp == LM_TC_CR) {
151 pain.rectangle(x, y - df_asc, df_width, df_asc,
158 MathParInset::Metrics()
170 ascent = df_asc;//mathed_char_height(LM_TC_VAR, size, 'I', asc, des);
173 if (array.empty()) return;
176 MathedXIter data(this);
181 string const s = data.GetString();
182 mathed_string_height(data.fcode(),
183 size(), s, asc, des);
184 if (asc > ascent) ascent = asc;
185 if (des > descent) descent = des;
187 mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
188 } else if (MathIsInset(cx)) {
189 MathedInset * p = data.GetInset();
192 if (cx == LM_TC_UP) {
193 asc += (limits) ? p->Height() + 4: p->Ascent() +
194 ((p->Descent()>asc) ? p->Descent() - asc + 4: 0);
195 } else if (cx == LM_TC_DOWN) {
196 des += (limits ? p->Height() + 4 : p->Height() - p->Ascent() / 2);
201 if (asc > ascent) ascent = asc;
202 if (des > descent) descent = des;
203 if (cx!= LM_TC_UP && cx!= LM_TC_DOWN)
204 limits = p->GetLimits();
206 } else if (cx == LM_TC_TAB) {
209 data.GetIncPos(x, y);
210 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
211 if (ascent < df_asc) ascent = df_asc;
214 data.setTab(x - tb, tab);
219 } else if (cx == LM_TC_CR) {
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);
229 } else //if (GetColumns() == 1)
233 data.GetIncPos(x, y);
235 if (ascent < df_asc) ascent = df_asc;
238 data.subMetrics(ascent, descent);
243 lyxerr << "Mathed Error: Unrecognized code[" << cx
249 data.GetIncPos(width, ls);
251 // No matter how simple is a matrix, it is NOT a subparagraph
253 if (cxp == LM_TC_TAB) {
254 if (ascent<df_asc) ascent = df_asc;
257 data.setTab(width - tb, tab);
261 data.subMetrics(ascent, descent);
266 void MathParInset::Write(ostream & os, bool fragile)
268 if (array.empty()) return;
271 MathedIter data(&array);
273 MathedRowContainer::iterator crow = getRowSt().begin();
276 if (!Permit(LMPF_FIXED_SIZE)) {
277 l = lm_get_key_by_id(size(), LM_TK_STY);
279 os << '\\' << l->name << ' ';
283 byte cx = data.GetChar();
285 string str = data.GetString();
287 if (data.fcode() >= LM_TC_RM && data.fcode() <= LM_TC_TEXTRM) {
288 os << '\\' << math_font_name[data.fcode()-LM_TC_RM] << '{';
290 for (string::const_iterator s = str.begin();
291 s != str.end(); ++s) {
293 if (MathIsSymbol(data.fcode())) {
294 l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ?
295 LM_TK_BIGSYM : LM_TK_SYM);
297 os << '\\' << l->name << ' ';
300 #warning this does not compile on gcc 2.97
302 //lyxerr << "Illegal symbol code[" << c
303 // << " " << str.end() - s << " " << data.fcode() << "]";
306 // Is there a standard logical XOR?
307 if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') ||
308 (data.fcode() == LM_TC_SPECIAL))
311 if (c == '{') ++brace;
312 if (c == '}') --brace;
314 if (c == '}' && data.fcode() == LM_TC_TEX && brace < 0)
315 lyxerr <<"Math warning: Unexpected closing brace."
321 if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
324 if (MathIsInset(cx)) {
325 MathedInset * p = data.GetInset();
328 if (cx == LM_TC_DOWN)
330 p->Write(os, fragile);
331 if (cx == LM_TC_UP || cx == LM_TC_DOWN)
345 if (!crow->isNumbered()) {
348 if (!crow->getLabel().empty()) {
358 ++number_of_newlines;
363 lyxerr << "WMath Error: unrecognized code[" << cx << "]";
369 if (!crow->isNumbered()) {
372 if (!crow->getLabel().empty()) {
380 os << string(brace, '}');
384 void MathParInset::clear()
389 bool MathParInset::Inside(int x, int y)
391 return (x >= xo() && x <= xo() + width
392 && y <= yo() + descent && y >= yo() - ascent);
396 void MathParInset::GetXY(int & x, int & y) const
403 void MathParInset::UserSetSize(short sz)
407 flag = flag & ~LMPF_FIXED_SIZE;
412 void MathParInset::SetStyle(short sz)
414 if (Permit(LMPF_FIXED_SIZE)) {
415 if (Permit(LMPF_SCRIPT))
416 sz = (sz < LM_ST_SCRIPT) ? LM_ST_SCRIPT: LM_ST_SCRIPTSCRIPT;
417 if (Permit(LMPF_SMALLER) && sz < LM_ST_SCRIPTSCRIPT) {
420 MathedInset::SetStyle(sz);
425 bool MathParInset::Permit(short f) const
427 return bool(f & flag);
431 MathedArray & MathParInset::GetData()
437 MathedArray const & MathParInset::GetData() const
443 void MathParInset::setXY(int x, int y)