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)
33 if (objtype == LM_OT_SCRIPT)
38 // This is virtual and needed.
39 MathParInset::~MathParInset()
44 MathedInset * MathParInset::Clone()
46 return new MathParInset(*this);
50 void MathParInset::setData(MathedArray const & a)
54 // A standard paragraph shouldn't have any tabs nor CRs.
55 MathedIter it(&array);
57 char c = it.GetChar();
58 if (c == LM_TC_TAB || c == LM_TC_CR)
67 MathParInset::draw(Painter & pain, int x, int y)
77 MathedXIter data(this);
79 //MathedXIter data(this);
81 pain.rectangle(x, y - df_asc, df_width, df_asc,
85 //MathedXIter data(this);
89 byte cx = data.GetChar();
91 string const s = data.GetString();
92 drawStr(pain, data.fcode(), size(), x, y, s);
93 mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
98 if (MathIsInset(cx)) {
100 MathedInset * p = data.GetInset();
101 if (cx == LM_TC_UP) {
103 x -= (xp > p->Width()) ?
104 p->Width() + (xp - p->Width()) / 2 : xp;
105 yy -= (asc + p->Descent() + 4);
107 yy -= (p->Descent() > asc) ?
108 p->Descent() + 4 : asc;
109 } else if (cx == LM_TC_DOWN) {
111 x -= (xp > p->Width()) ?
112 p->Width() + (xp - p->Width()) / 2 : xp;
113 yy += des + p->Ascent() + 2;
115 yy += des + p->Ascent() / 2;
120 p->draw(pain, x, yy);
121 if (cx != LM_TC_UP && cx != LM_TC_DOWN) {
122 limits = p->GetLimits();
127 } else if (cx == LM_TC_TAB) {
129 || cxp == LM_TC_CR || data.IsFirst()) {
130 pain.rectangle(x, y - df_asc,
136 } else if (cx == LM_TC_CR) {
138 || cxp == LM_TC_CR || data.IsFirst()) {
139 pain.rectangle(x, y - df_asc,
146 lyxerr << "GMathed Error: Unrecognized code[" << cx << "]" << endl;
152 if (cxp == LM_TC_TAB || cxp == LM_TC_CR) {
154 pain.rectangle(x, y - df_asc, df_width, df_asc,
161 MathParInset::Metrics()
173 ascent = df_asc;//mathed_char_height(LM_TC_VAR, size, 'I', asc, des);
176 if (array.empty()) return;
179 MathedXIter data(this);
184 string s = data.GetString();
185 mathed_string_height(data.fcode(),
186 size(), s, asc, des);
187 if (asc > ascent) ascent = asc;
188 if (des > descent) descent = des;
190 mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
192 if (MathIsInset(cx)) {
193 MathedInset * p = data.GetInset();
196 if (cx == LM_TC_UP) {
197 asc += (limits) ? p->Height() + 4: p->Ascent() +
198 ((p->Descent()>asc) ? p->Descent() - asc + 4: 0);
200 if (cx == LM_TC_DOWN) {
201 des += ((limits) ? p->Height() + 4: p->Height() - p->Ascent() / 2);
206 if (asc > ascent) ascent = asc;
207 if (des > descent) descent = des;
208 if (cx!= LM_TC_UP && cx!= LM_TC_DOWN)
209 limits = p->GetLimits();
212 if (cx == LM_TC_TAB) {
214 data.GetIncPos(x, y);
215 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
216 if (ascent<df_asc) ascent = df_asc;
219 data.setTab(x-tb, tab);
225 if (cx == LM_TC_CR) {
228 data.GetIncPos(x, y);
229 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
230 if (ascent<df_asc) ascent = df_asc;
233 data.setTab(x - tb, tab);
234 } else //if (GetColumns() == 1)
237 data.GetIncPos(x, y);
239 if (ascent<df_asc) ascent = df_asc;
242 data.subMetrics(ascent, descent);
247 lyxerr << "Mathed Error: Unrecognized code[" << cx
253 data.GetIncPos(width, ls);
255 // No matter how simple is a matrix, it is NOT a subparagraph
257 if (cxp == LM_TC_TAB) {
258 if (ascent<df_asc) ascent = df_asc;
261 data.setTab(width - tb, tab);
265 data.subMetrics(ascent, descent);
270 void MathParInset::Write(ostream & os, bool fragile)
272 if (array.empty()) return;
275 MathedIter data(&array);
277 MathedRowSt const * crow = getRowSt();
280 if (!Permit(LMPF_FIXED_SIZE)) {
281 l = lm_get_key_by_id(size(), LM_TK_STY);
283 os << '\\' << l->name << ' ';
287 byte cx = data.GetChar();
289 string str = data.GetString();
291 if (data.fcode() >= LM_TC_RM && data.fcode() <= LM_TC_TEXTRM) {
292 os << '\\' << math_font_name[data.fcode()-LM_TC_RM] << '{';
294 for (string::const_iterator s = str.begin();
295 s != str.end(); ++s) {
297 if (MathIsSymbol(data.fcode())) {
298 l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ?
299 LM_TK_BIGSYM : LM_TK_SYM);
301 os << '\\' << l->name << ' ';
303 #warning this does not compile on gcc 2.97
304 //lyxerr << "Illegal symbol code[" << c
305 // << " " << str.end() - s << " " << data.fcode() << "]";
308 // Is there a standard logical XOR?
309 if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') ||
310 (data.fcode() == LM_TC_SPECIAL))
313 if (c == '{') ++brace;
314 if (c == '}') --brace;
316 if (c == '}' && data.fcode() == LM_TC_TEX && brace < 0)
317 lyxerr <<"Math warning: Unexpected closing brace."
323 if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
326 if (MathIsInset(cx)) {
327 MathedInset * p = data.GetInset();
330 if (cx == LM_TC_DOWN)
332 p->Write(os, fragile);
333 if (cx == LM_TC_UP || cx == LM_TC_DOWN)
347 if (!crow->isNumbered()) {
350 if (!crow->getLabel().empty()) {
355 crow = crow->getNext();
360 ++number_of_newlines;
365 lyxerr << "WMath Error: unrecognized code[" << cx << "]";
371 if (!crow->isNumbered()) {
374 if (!crow->getLabel().empty()) {
382 os << string(brace, '}');
386 void MathParInset::clear()
391 bool MathParInset::Inside(int x, int y)
393 return (x >= xo() && x <= xo() + width
394 && y <= yo() + descent && y >= yo() - ascent);
398 void MathParInset::GetXY(int & x, int & y) const
405 void MathParInset::UserSetSize(short sz)
409 flag = flag & ~LMPF_FIXED_SIZE;
414 void MathParInset::SetStyle(short sz)
416 if (Permit(LMPF_FIXED_SIZE)) {
417 if (Permit(LMPF_SCRIPT))
418 sz = (sz < LM_ST_SCRIPT) ? LM_ST_SCRIPT: LM_ST_SCRIPTSCRIPT;
419 if (Permit(LMPF_SMALLER) && sz < LM_ST_SCRIPTSCRIPT) {
422 MathedInset::SetStyle(sz);
427 bool MathParInset::Permit(short f) const
429 return bool(f & flag);
433 MathedArray & MathParInset::GetData()
439 void MathParInset::setXY(int x, int y)