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 MathParInset::~MathParInset()
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)
77 MathedXIter data(this);
79 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
82 MathedXIter data(this);
86 byte cx = data.GetChar();
88 string s = data.GetString();
89 drawStr(pain, data.fcode(), size(), x, y, s);
90 mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
96 if (MathIsInset(cx)) {
98 MathedInset * p = data.GetInset();
101 x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
102 yy -= (asc + p->Descent()+4);
105 yy -= (p->Descent()>asc) ? p->Descent()+4: asc;
107 else if (cx == LM_TC_DOWN) {
109 x -= (xp>p->Width()) ? p->Width()+(xp-p->Width())/2: xp;
110 yy += des + p->Ascent() + 2;
112 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();
126 else if (cx == LM_TC_TAB) {
127 if (cxp == cx || cxp == LM_TC_CR || data.IsFirst()) {
128 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
133 else if (cx == LM_TC_CR) {
134 if (cxp == LM_TC_TAB || cxp == LM_TC_CR || data.IsFirst()) {
135 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
141 lyxerr << "GMathed Error: Unrecognized code[" << cx << "]" << endl;
147 if (cxp == LM_TC_TAB || cxp == LM_TC_CR) {
149 pain.rectangle(x, y - df_asc, df_width, df_asc, LColor::mathline);
155 MathParInset::Metrics()
167 ascent = df_asc;//mathed_char_height(LM_TC_VAR, size, 'I', asc, des);
170 if (array.empty()) return;
173 MathedXIter data(this);
178 string s = data.GetString();
179 mathed_string_height(data.fcode(),
180 size(), s, asc, des);
181 if (asc > ascent) ascent = asc;
182 if (des > descent) descent = des;
184 mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
186 if (MathIsInset(cx)) {
187 MathedInset * p = data.GetInset();
190 if (cx == LM_TC_UP) {
191 asc += (limits) ? p->Height() + 4: p->Ascent() +
192 ((p->Descent()>asc) ? p->Descent() - asc + 4: 0);
194 if (cx == LM_TC_DOWN) {
195 des += ((limits) ? p->Height() + 4: p->Height() - p->Ascent() / 2);
200 if (asc > ascent) ascent = asc;
201 if (des > descent) descent = des;
202 if (cx!= LM_TC_UP && cx!= LM_TC_DOWN)
203 limits = p->GetLimits();
206 if (cx == LM_TC_TAB) {
208 data.GetIncPos(x, y);
209 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
210 if (ascent<df_asc) ascent = df_asc;
213 data.setTab(x-tb, tab);
219 if (cx == LM_TC_CR) {
222 data.GetIncPos(x, y);
223 if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
224 if (ascent<df_asc) ascent = df_asc;
227 data.setTab(x - tb, tab);
228 } else //if (GetColumns() == 1)
231 data.GetIncPos(x, y);
233 if (ascent<df_asc) ascent = df_asc;
236 data.subMetrics(ascent, descent);
241 lyxerr << "Mathed Error: Unrecognized code[" << cx
247 data.GetIncPos(width, ls);
249 // No matter how simple is a matrix, it is NOT a subparagraph
251 if (cxp == LM_TC_TAB) {
252 if (ascent<df_asc) ascent = df_asc;
255 data.setTab(width - tb, tab);
259 data.subMetrics(ascent, descent);
264 void MathParInset::Write(ostream & os, bool fragile)
266 if (array.empty()) return;
269 MathedIter data(&array);
271 MathedRowSt const * crow = getRowSt();
274 if (!Permit(LMPF_FIXED_SIZE)) {
275 l = lm_get_key_by_id(size(), LM_TK_STY);
277 os << '\\' << l->name << ' ';
281 byte cx = data.GetChar();
283 string str = data.GetString();
285 if (data.fcode() >= LM_TC_RM && data.fcode() <= LM_TC_TEXTRM) {
286 os << '\\' << math_font_name[data.fcode()-LM_TC_RM] << '{';
288 for (string::const_iterator s = str.begin();
289 s != str.end(); ++s) {
291 if (MathIsSymbol(data.fcode())) {
292 l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ?
293 LM_TK_BIGSYM : LM_TK_SYM);
295 os << '\\' << l->name << ' ';
297 #warning this does not compile on gcc 2.97
298 //lyxerr << "Illegal symbol code[" << c
299 // << " " << str.end() - s << " " << data.fcode() << "]";
302 // Is there a standard logical XOR?
303 if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') ||
304 (data.fcode() == LM_TC_SPECIAL))
307 if (c == '{') ++brace;
308 if (c == '}') --brace;
310 if (c == '}' && data.fcode() == LM_TC_TEX && brace < 0)
311 lyxerr <<"Math warning: Unexpected closing brace."
317 if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
320 if (MathIsInset(cx)) {
321 MathedInset * p = data.GetInset();
324 if (cx == LM_TC_DOWN)
326 p->Write(os, fragile);
327 if (cx == LM_TC_UP || cx == LM_TC_DOWN)
341 if (!crow->isNumbered()) {
344 if (!crow->getLabel().empty()) {
349 crow = crow->getNext();
354 ++number_of_newlines;
359 lyxerr << "WMath Error: unrecognized code[" << cx << "]";
365 if (!crow->isNumbered()) {
368 if (!crow->getLabel().empty()) {
376 os << string(brace, '}');
380 void MathParInset::clear()
385 bool MathParInset::Inside(int x, int y)
387 return (x >= xo() && x <= xo() + width
388 && y <= yo() + descent && y >= yo() - ascent);
392 void MathParInset::GetXY(int & x, int & y) const
399 void MathParInset::UserSetSize(short sz)
403 flag = flag & ~LMPF_FIXED_SIZE;
408 void MathParInset::SetStyle(short sz)
410 if (Permit(LMPF_FIXED_SIZE)) {
411 if (Permit(LMPF_SCRIPT))
412 sz = (sz < LM_ST_SCRIPT) ? LM_ST_SCRIPT: LM_ST_SCRIPTSCRIPT;
413 if (Permit(LMPF_SMALLER) && sz < LM_ST_SCRIPTSCRIPT) {
416 MathedInset::SetStyle(sz);
421 bool MathParInset::Permit(short f) const
423 return bool(f & flag);
427 MathedArray & MathParInset::GetData()
433 void MathParInset::setXY(int x, int y)