diff --git a/uppsrc/TDraw/formula.cpp b/uppsrc/TDraw/formula.cpp index 6bd0a6d44..6d6c615ba 100644 --- a/uppsrc/TDraw/formula.cpp +++ b/uppsrc/TDraw/formula.cpp @@ -672,10 +672,10 @@ private: void Push(bool makeindex); bool Pop(); - RefCon MakeBinary(RefCon left, WString text, + RefCon MakeBinary(RefCon left, const WString& text, bool is_symbol, RefCon right, int gap = Null, int perc_shift = 0) const; - RefCon MakeUnary(String text, RefCon form, - int gap = Null, bool symbol = false, int perc_shift = 0) const; + RefCon MakeUnary(String text, bool is_symbol, + RefCon form, int gap = Null, int perc_shift = 0) const; private: struct State @@ -724,7 +724,7 @@ RefCon FormulaParser::RunSemicolon() while(Check(';')) { RefCon right = RunComma(); - item = MakeBinary(item, ";", right, Formula::GetTextHeight0(item, right) >> 1); + item = MakeBinary(item, ";", false, right, Formula::GetTextHeight0(item, right) >> 1); } return item; } @@ -736,7 +736,7 @@ RefCon FormulaParser::RunComma() { // must run before '&', aargh! RefCon right = RunComma(); int ht = Formula::GetTextHeight0(item, right); - return MakeBinary(item, "&", right, Percent(50, ht), ht); + return MakeBinary(item, "&", false, right, Percent(50, ht), ht); } bool row = false; if(Check('&')) @@ -789,43 +789,41 @@ RefCon FormulaParser::RunComp() RefCon item = RunMul(); for(;;) if(Check('=', '~')) - item = MakeBinary(item, WString(0x2248, 1), RunComp(), gap); - else if(Check('=')) - item = MakeBinary(item, "=", RunComp(), gap); - else if(Check('<', '>')) - item = MakeBinary(item, WString(0x2260, 1), RunComp(), gap, -11); - else if(Check('<', '=')) - item = MakeBinary(item, WString(0x2264, 1), RunComp(), gap, -9); - else if(Check('>', '=')) - item = MakeBinary(item, WString(0x2265, 1), RunComp(), gap, -9); + item = MakeBinary(item, WString(0x2248, 1), false, RunComp(), gap); else if(Check('<', '-', '>')) - item = MakeBinary(item, WString(0x2194, 1), RunComp(), Null, -13); + item = MakeBinary(item, WString(0x2194, 1), false, RunComp(), gap, -5); + else if(Check('<', '=', '>')) + item = MakeBinary(item, "\xDB", true, RunComp(), 2 * gap, -5); + else if(Check('<', '>')) + item = MakeBinary(item, WString(0x2260, 1), false, RunComp(), gap, -5); + else if(Check('<', '=')) + item = MakeBinary(item, WString(0x2264, 1), false, RunComp(), gap, -5); + else if(Check('>', '=')) + item = MakeBinary(item, WString(0x2265, 1), false, RunComp(), gap, -5); else if(Check('<', '-')) - item = MakeBinary(item, WString(0x2190, 1), RunComp(), Null, -13); + item = MakeBinary(item, WString(0x2190, 1), false, RunComp(), gap, -5); else if(Check('-', '>')) - item = MakeBinary(item, WString(0x2192, 1), RunComp(), Null, -13); + item = MakeBinary(item, WString(0x2192, 1), false, RunComp(), gap, -5); else if(Check('=', '>')) - item = MakeBinary(item, "\xDE", RunComp(), Null, -13); + item = MakeBinary(item, "\xDE", true, RunComp(), 2 * gap, -10); else if(Check('=', '<')) - item = MakeBinary(item, "\xDC", RunComp(), Null, -13); + item = MakeBinary(item, "\xDC", true, RunComp(), 2 * gap, -10); else if(Skip() == '.' && ptr[1] == '.' && ptr[2] != '.') { ptr += 2; - RefCon right = RunComp(); - Vector< RefCon > list; - list << item; - list << new FormulaText("..", state.font, state.color); - list << right; - int ht = Formula::GetTextHeight0(item, right); - item = new FormulaMatrix(list, new FormulaSpace(Percent(20, ht))); + item = MakeBinary(item, "..", false, RunComp(), gap, 0); } + else if(Check('+', '-')) + item = MakeBinary(item, WString(0x00B1, 1), false, RunComp(), gap); else if(Check('<')) - item = MakeBinary(item, "<", RunComp(), gap); + item = MakeBinary(item, "<", false, RunComp(), gap); else if(Check('>')) - item = MakeBinary(item, ">", RunComp(), gap); + item = MakeBinary(item, ">", false, RunComp(), gap); + else if(Check('=')) + item = MakeBinary(item, "=", false, RunComp(), gap); else if(Check('+')) - item = MakeBinary(item, "+", RunComp()); + item = MakeBinary(item, "+", false, RunComp()); else if(Check('-')) - item = MakeBinary(item, "-", RunComp(), Null, -11); + item = MakeBinary(item, "-", false, RunComp(), Null, -11); else if(Check('|', '|')) { RefCon right = RunComp(); @@ -837,7 +835,7 @@ RefCon FormulaParser::RunComp() return new FormulaMatrix(list, new FormulaSpace(Percent(50, ht))); } else if(Check('|')) - item = MakeBinary(item, Null, RunComp(), 0, false); + item = MakeBinary(item, Null, false, RunComp(), 0); else return item; } @@ -847,13 +845,13 @@ RefCon FormulaParser::RunMul() RefCon item = RunDiv(); for(;;) if(Check('*')) - item = MakeBinary(item, "*", RunDiv()); + item = MakeBinary(item, "*", false, RunDiv()); else if(Skip() == '.' && ptr[1] != '.') { ptr++; - item = MakeBinary(item, ".", RunDiv(), Null, -20); + item = MakeBinary(item, ".", false, RunDiv(), Null, -20); } else if(Check('~')) - item = MakeBinary(item, Null, RunDiv()); + item = MakeBinary(item, Null, false, RunDiv()); else return item; } @@ -863,7 +861,7 @@ RefCon FormulaParser::RunDiv() RefCon item = RunPostfix(); for(;;) if(Check('/', '_')) - item = MakeBinary(item, "/", RunPostfix()); + item = MakeBinary(item, "/", false, RunPostfix()); else if(Check('/')) item = new FormulaRatio(item, RunPostfix()); else @@ -884,12 +882,12 @@ RefCon FormulaParser::RunPostfix() else if(!!(in = RunParen())) { int tht = Formula::GetTextHeight0(item, in); - item = MakeBinary(item, Null, in, Formula::GetFuncSpace(tht)); + item = MakeBinary(item, Null, false, in, Formula::GetFuncSpace(tht)); } else if(Check('!')) - item = MakeBinary(item, Null, new FormulaText("!", state.font), state.color); + item = MakeBinary(item, Null, false, new FormulaText("!", state.font), state.color); else if(Check(':')) - item = MakeBinary(item, Null, RunTerm(), 0); + item = MakeBinary(item, Null, false, RunTerm(), 0); else return item; } @@ -915,7 +913,7 @@ bool FormulaParser::RunIndex(RefCon& topright, RefCon& bottomr if(!topright) topright = form; else - topright = MakeBinary(topright, Null, form, 0); + topright = MakeBinary(topright, Null, false, form, 0); done = true; continue; } @@ -982,11 +980,11 @@ RefCon FormulaParser::RunTerm() if(!!paren) return paren; if(Check('@')) - return MakeUnary("\xB6", RunTerm(), 0, true); + return MakeUnary("\xB6", true, RunTerm(), 0, true); if(Check('-')) - return MakeUnary("-", RunTerm(), 0, true); + return MakeUnary("-", false, RunTerm(), 0, true); if(Check('+')) - return MakeUnary("+", RunTerm(), 0, true); + return MakeUnary("+", false, RunTerm(), 0, true); if(Check('.', '.', '.')) return new FormulaText("...", state.font, state.color); if(Check('~', '~')) @@ -995,7 +993,7 @@ RefCon FormulaParser::RunTerm() for(; *ptr == '~'; ptr++) blanks++; RefCon item = RunTerm(); - return MakeUnary(Null, item, (blanks * Formula::GetTextHeight0(item)) >> 1); + return MakeUnary(Null, false, item, (blanks * Formula::GetTextHeight0(item)) >> 1); } Font font = state.font; @@ -1117,7 +1115,7 @@ RefCon FormulaParser::RunTerm() RefCon body = new FormulaSymbol(group_sym, ht, arg->GetTextHeight(), state.color); if(!!topright || !!bottomright || !!top || !!bottom || !!topleft || !!bottomleft) body = new FormulaIndex(body, topright, bottomright, top, bottom, topleft, bottomleft); - return MakeBinary(body, Null, arg); + return MakeBinary(body, Null, false, arg); } else if(ident == "oo") return new FormulaText(WString(0x221E, 1), font, state.color, -11); @@ -1263,8 +1261,8 @@ bool FormulaParser::Check(char c1, char c2, char c3) return true; } -RefCon FormulaParser::MakeBinary(RefCon left, - WString text, RefCon right, int gap, int perc_shift) const +RefCon FormulaParser::MakeBinary(RefCon left, const WString& text, bool is_symbol, + RefCon right, int gap, int perc_shift) const { int ht = Formula::GetTextHeight0(left, right); if(IsNull(gap)) @@ -1273,6 +1271,8 @@ RefCon FormulaParser::MakeBinary(RefCon left, formula.Add() = left; if(!IsNull(text)) { Font f = state.font; + if(is_symbol) + f.Face(Font::SYMBOL); f.Height(ht); formula.Add() = new FormulaText(text, f, state.color, perc_shift); } @@ -1282,15 +1282,14 @@ RefCon FormulaParser::MakeBinary(RefCon left, return form; } -RefCon FormulaParser::MakeUnary(String text, RefCon form, - int gap, bool symbol, int perc_shift) const +RefCon FormulaParser::MakeUnary(String text, bool is_symbol, + RefCon form, int gap, int perc_shift) const { int ht = form->GetTextHeight(); Vector< RefCon > formula; - if(!IsNull(text)) - { + if(!IsNull(text)) { Font f = state.font; - if(symbol) + if(is_symbol) f.Face(Font::SYMBOL); f.Height(ht); formula.Add() = new FormulaText(text.ToWString(), f, state.color, perc_shift); @@ -1307,7 +1306,7 @@ RefCon FormulaParser::GetError(String text, Font font) const void FormulaParser::AddError(RefCon& item, String text) const { int ht = item->GetTextHeight(); - item = MakeBinary(item, Null, GetError(text, Font(state.font).Height(ht))); + item = MakeBinary(item, Null, false, GetError(text, Font(state.font).Height(ht))); } void FormulaParser::Force(char c, RefCon& errout)