public virtual void VarFix(Function F) { //if(F==null) //{ // return; //} //System.out.println(F.toString()); for (int i = 0; i < F.numSubNodes; i++) { Function Fnode = F.GetSubNode(i); if (Fnode.GetID() == FVar.ID) { FVar var = this.FindVariable(((FVar)Fnode).varName); if (var != null) { //System.out.println(((FVar)Fnode).getVarName()); F.SetSubNode(i, var); } continue; } if (Fnode.GetID().Equals(FCons.ID)) { continue; } VarFix(F.GetSubNode(i)); } }
// Sets Value to a Valriable in VarList public static FVar ML_VariableList(int request, String name, double val) { if (request == MLGUI.UpdateVariableValue) { foreach (VariableEntry ve in MLGUI.ML_Variables) { if (ve.Name == name) { ve.Variable.SetValue(val); return(ve.Variable); } } } else if (request == MLGUI.AddItem) { foreach (VariableEntry ve in MLGUI.ML_Variables) { if (ve.Name == name) { ve.Variable.SetValue(val); return(ve.Variable); } } ML_FunctionList(MLGUI.RemoveItem, name); FVar newVar = new FVar(name); newVar.SetValue(val); MLGUI.lastVariableEntry = new VariableEntry(name, newVar); MLGUI.ML_Variables.Add(MLGUI.lastVariableEntry); return(newVar); } return(null); }
public virtual Function AddVariable(FVar var) { if (FindVariable(var.varName) == null) { varList.Add(var); } return(var); }
public virtual FunctionTree GetDerivative(FVar var) { if (rootNode.HasVariable(var)) { return(new FunctionTree(rootNode.GetDerivative(var))); } return(new FunctionTree(new FCons(0))); }
public override Function GetDerivative(FVar var) { if (Operand().HasVariable(var)) { return(new FNeg(Operand().GetDerivative(var))); } return(new FCons(0)); }
public virtual FunctionTree GetDerivative(string var) { FVar v = new FVar(@var); if (rootNode.HasVariable(v)) { return(new FunctionTree(rootNode.GetDerivative(v))); } return(new FunctionTree(new FCons(0))); }
public virtual bool HasVariable(FVar var) { foreach (FVar v in varList) { if (v.varName.Equals(var.varName)) { return(true); } } return(false); }
public bool VariableToSetValue(String varName) { if ((tempVar = FindVariable(varName)) != null && tempVar.IsSet()) { tempCons = new FCons(tempVar.varValue); VarToVal(rootNode); varList.Remove(tempVar); tempVar = null; tempCons = null; GenerateFunctionTreeText(funcTreeTextStyle); return(true); } return(false); }
// Returns NULL if request did not succeeed public static FVar ML_VariableList(int request, String name) { if (request == MLGUI.GetVariable) { foreach (VariableEntry ve in MLGUI.ML_Variables) { if (ve.Name == name) { return(ve.Variable); } } } else if (request == MLGUI.AddItem) { foreach (VariableEntry ve in MLGUI.ML_Variables) { if (ve.Name == name) { return(ve.Variable); } } ML_FunctionList(MLGUI.RemoveItem, name); FVar newVar = new FVar(name); MLGUI.lastVariableEntry = new VariableEntry(name, newVar); MLGUI.ML_Variables.Add(MLGUI.lastVariableEntry); return(newVar); } else if (request == MLGUI.RemoveItem) { foreach (VariableEntry ve in MLGUI.ML_Variables) { if (ve.Name == name) { FVar temp = ve.Variable; MLGUI.ML_Variables.Remove(ve); return(temp); } } } else if (request == MLGUI.RemoveLastItem) { MLGUI.ML_Variables.Remove(MLGUI.lastVariableEntry); return(MLGUI.lastVariableEntry.Variable); } return(null); }
public bool VariableToFunction(String varName, Function F) { if ((tempVar = FindVariable(varName)) != null) { tempFunc = F; VarToFunc(rootNode); varList.Remove(tempVar); foreach (FVar v in F.varList) { AddVariable(v); } tempVar = null; tempCons = null; GenerateFunctionTreeText(funcTreeTextStyle); return(true); } return(false); }
public virtual double GetValue(params string[] str) { // parse and set values for (int i = 0; i < str.Length; i++) { int w = 0; char c; string s = ""; int len = str[i].Length; while (w < len) { c = str[i][w]; if (c == '=') { break; } s = s + char.ToString(c); //System.out.println(str[i] + " // " + s); w++; } FVar f = FindVariable(s); if (f != null && w < len) { try { f.SetValue(Convert.ToDouble(str[i].Substring(++w))); } catch (FormatException) { } } } return(rootNode.GetValue()); }
public virtual void VarFix(Function F) { for (int i = 0; i < F.numSubNodes; i++) { Function Fnode = F.GetSubNode(i); if (Fnode.GetID() == FVar.ID) { FVar var = FindVariable(((FVar)Fnode).varName); if (var != null) { F.SetSubNode(i, var); } continue; } if (Fnode.GetID().Equals(FCons.ID)) { continue; } VarFix(F.GetSubNode(i)); } }
public override Function GetDerivative(FVar @var) { bool checkLHS = LHS().HasVariable(var); bool checkRHS = RHS().HasVariable(var); bool checkBoth = checkLHS && checkRHS; if (checkLHS && !checkRHS) { return(LHS().GetDerivative(var)); } if (!checkLHS && checkRHS) { return(RHS().GetDerivative(var)); } if (checkBoth) { return(new FAdd(LHS().GetDerivative(var), RHS().GetDerivative(@var))); } return(new FCons(0)); }
public static void CreateFunctionTree(string[] postfixArray, FunctionTree FTree) { FunctionStack fStk = new FunctionStack(); FTree.varList = new List <FVar>(); string f; int i = 0; Function temp1, temp2; bool chk1, chk2; while (i < postfixArray.Length) { f = postfixArray[i]; //Console.Write(" "+ f); if (f.Equals(FNeg.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FNeg.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FNeg(fStk.TopAndPop())); } else if (f.Equals(FAdd.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FAdd.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FAdd(fStk.TopAndPop(), fStk.TopAndPop(), 1)); } else if (f.Equals(FSub.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FSub.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FSub(fStk.TopAndPop(), fStk.TopAndPop(), 1)); } else if (f.Equals(FMul.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FMul.Symbol, StringComparison.CurrentCultureIgnoreCase)) { temp1 = fStk.TopAndPop(); chk1 = temp1.GetID().Equals(FCons.ID) && !fStk.Top().GetID().Equals(FCons.ID); if (chk1 && fStk.Top().isTwoSidedFunction&& !((TwoSidedFunction)fStk.Top()).RHS().GetID().Equals(FCons.ID)) { temp2 = ((TwoSidedFunction)fStk.Top()).RHS(); ((TwoSidedFunction)fStk.Top()).SetRHS(temp1); fStk.Push(new FMul(temp2, fStk.TopAndPop(), 1)); } else if (chk1 && fStk.Top().isVariable) { fStk.Push(new FMul(fStk.TopAndPop(), temp1, 1)); } else { fStk.Push(new FMul(temp1, fStk.TopAndPop(), 1)); } } else if (f.Equals(FDiv.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FDiv.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FDiv(fStk.TopAndPop(), fStk.TopAndPop(), 1)); } else if (f.Equals(FPow.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FPow.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FPow(fStk.TopAndPop(), fStk.TopAndPop(), 1)); } else if (f.Equals(FExp.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FExp.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FExp(fStk.TopAndPop())); } else if (f.Equals(FLn.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FLn.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FLn(fStk.TopAndPop())); } // sin() else if (f.Equals(FSin.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FSin.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FSin(fStk.TopAndPop())); } else if (f.Equals(FCos.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FCos.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FCos(fStk.TopAndPop())); } // add rest of the functions else if (IsConstant(f)) // double number { fStk.Push(new FCons(Convert.ToDouble(f))); } else { FVar @var = FTree.FindVariable(f); if (@var != null) { fStk.Push(@var); } else { FunctionTree temp; FVar tempVar; if ((tempVar = ListHandler.ML_VariableList(MLGUI.GetVariable, f)) != null && tempVar.IsSet()) { fStk.Push(new FCons(tempVar.GetValue())); } else if ((temp = ListHandler.ML_FunctionList(MLGUI.GetFunction, f)) != null) { fStk.Push(temp.rootNode); } else { fStk.Push(FTree.AddVariable(ListHandler.ML_VariableList(MLGUI.AddItem, f))); // variable } } } i++; } FTree.rootNode = fStk.TopAndPop(); }
internal bool ReadTableEntryCollection(Typeface typeface, RestoreTicket ticket, TableEntryCollection tables, BinaryReader input) { if (ticket != null) { return(ReadTableEntryCollectionOnRestoreMode(typeface, ticket, tables, input)); } typeface.SetTableEntryCollection(tables.CloneTableHeaders()); var rd = new EntriesReaderHelper(tables, input); //PART 1: basic information OS2Table os2Table = rd.Read(new OS2Table()); Meta meta = rd.Read(new Meta()); NameEntry nameEntry = rd.Read(new NameEntry()); Head head = rd.Read(new Head()); MaxProfile maxProfile = rd.Read(new MaxProfile()); HorizontalHeader horizontalHeader = rd.Read(new HorizontalHeader()); HorizontalMetrics horizontalMetrics = rd.Read(new HorizontalMetrics(horizontalHeader.NumberOfHMetrics, maxProfile.GlyphCount)); VerticalHeader vhea = rd.Read(new VerticalHeader()); if (vhea != null) { VerticalMetrics vmtx = rd.Read(new VerticalMetrics(vhea.NumOfLongVerMetrics)); } Cmap cmaps = rd.Read(new Cmap()); VerticalDeviceMetrics vdmx = rd.Read(new VerticalDeviceMetrics()); Kern kern = rd.Read(new Kern()); //------------------------------------ //PART 2: glyphs detail //2.1 True type font GlyphLocations glyphLocations = rd.Read(new GlyphLocations(maxProfile.GlyphCount, head.WideGlyphLocations)); Glyf glyf = rd.Read(new Glyf(glyphLocations)); Gasp gaspTable = rd.Read(new Gasp()); COLR colr = rd.Read(new COLR()); CPAL cpal = rd.Read(new CPAL()); //2.2 Cff font PostTable postTable = rd.Read(new PostTable()); CFFTable cff = rd.Read(new CFFTable()); //additional math table (if available) MathTable mathtable = rd.Read(new MathTable()); //------------------------------------ //PART 3: advanced typography GDEF gdef = rd.Read(new GDEF()); GSUB gsub = rd.Read(new GSUB()); GPOS gpos = rd.Read(new GPOS()); BASE baseTable = rd.Read(new BASE()); JSTF jstf = rd.Read(new JSTF()); STAT stat = rd.Read(new STAT()); if (stat != null) { //variable font FVar fvar = rd.Read(new FVar()); if (fvar != null) { GVar gvar = rd.Read(new GVar()); CVar cvar = rd.Read(new CVar()); HVar hvar = rd.Read(new HVar()); MVar mvar = rd.Read(new MVar()); AVar avar = rd.Read(new AVar()); } } bool isPostScriptOutline = false; bool isBitmapFont = false; typeface.SetBasicTypefaceTables(os2Table, nameEntry, head, horizontalMetrics); if (glyf == null) { //check if this is cff table ? if (cff == null) { //check cbdt/cblc ? CBLC cblcTable = rd.Read(new CBLC()); if (cblcTable != null) { CBDT cbdtTable = rd.Read(new CBDT()); //read cbdt //bitmap font BitmapFontGlyphSource bmpFontGlyphSrc = new BitmapFontGlyphSource(cblcTable); bmpFontGlyphSrc.LoadCBDT(cbdtTable); Glyph[] glyphs = bmpFontGlyphSrc.BuildGlyphList(); typeface.SetBitmapGlyphs(glyphs, bmpFontGlyphSrc); isBitmapFont = true; } else { //TODO: EBLC fontBmpTable = rd.Read(new EBLC()); throw new NotSupportedException(); } } else { isPostScriptOutline = true; typeface.SetCffFontSet(cff.Cff1FontSet); } } else { typeface.SetTtfGlyphs(glyf.Glyphs); } //---------------------------- typeface.CmapTable = cmaps; typeface.KernTable = kern; typeface.MaxProfile = maxProfile; typeface.HheaTable = horizontalHeader; //---------------------------- typeface.GaspTable = gaspTable; if (!isPostScriptOutline && !isBitmapFont) { //for true-type font outline FpgmTable fpgmTable = rd.Read(new FpgmTable()); //control values table CvtTable cvtTable = rd.Read(new CvtTable()); PrepTable propProgramTable = rd.Read(new PrepTable()); typeface.ControlValues = cvtTable?._controlValues; typeface.FpgmProgramBuffer = fpgmTable?._programBuffer; typeface.PrepProgramBuffer = propProgramTable?._programBuffer; } //------------------------- typeface.LoadOpenFontLayoutInfo( gdef, gsub, gpos, baseTable, colr, cpal); //------------ typeface.SetSvgTable(rd.Read(new SvgTable())); typeface.PostTable = postTable; if (mathtable != null) { MathGlyphLoader.LoadMathGlyph(typeface, mathtable); } #if DEBUG //test //int found = typeface.GetGlyphIndexByName("Uacute"); if (typeface.IsCffFont) { //optional typeface.UpdateAllCffGlyphBounds(); } #endif typeface.UpdateLangs(meta); typeface.UpdateFrequentlyUsedValues(); return(true); }
public static void ProcessInput(int startpoint) { processing = true; if (startpoint == 0) { r3.Text = ""; } noOfLines = r2.Lines.Length - 1; int u = startpoint; // process only last line for (; u < noOfLines; u++) { cuurrentLineNo = u; Initialize(); show_output = true; p_line = r2.Lines[u]; p_line = p_line.Trim(' '); if (p_line == "") { continue; } if (p_line[p_line.Length - 1] == ';') { show_output = false; } p_line = p_line.Trim(';'); p_len = p_line.Length; if (p_len == 0) { continue; } // Skip Initial Spaces SkipSpaces(); inx--; if (End()) { continue; } // Store This Point; beginInx = inx; if (IsCommand()) { // Skip Spaces SkipSpaces(); inx--; if (End()) { continue; } ParseCommand(); } else if (IsEquation(p_line)) { if (SplitEquation(p_line, VariableAssignment)) { FVar temp = null; if ((temp = ListHandler.ML_VariableList(MLGUI.GetVariable, is_var)) != null) { ListHandler.ML_VariableList(MLGUI.UpdateVariableValue, temp.varName, is_val); } else { ListHandler.ML_VariableList(MLGUI.AddItem, is_var, is_val); } } else if (SplitEquation(p_line, FunctionAssignment)) { FunctionTree temp = null; if ((temp = ListHandler.ML_FunctionList(MLGUI.GetFunction, is_var)) != null) { ListHandler.ML_FunctionList(MLGUI.UpdateFunctionExpression, is_var, is_func); } else { ListHandler.ML_FunctionList(MLGUI.AddItem, is_var, is_func); } //foreach (FVar v in temp.varList) //{ //if (ListHandler.ML_FunctionList(MLGUI.GetFunction, v.varName)) //} } else { syntaxError = true; Error(); } } else if (IsVariable(p_line)) { ListHandler.ML_VariableList(MLGUI.RemoveItem, is_var); ListHandler.ML_VariableList(MLGUI.AddItem, is_var); } else if (IsFunction(p_line)) { FunctionEntry temp = null; if ((temp = ListHandler.ML_FunctionListSecondary(MLGUI.GetFunctionFromExpression, is_func)) != null) { r2.AppendText(temp.Name); r2.SelectionStart = r2.TextLength; r2.ScrollToCaret(); } else { ListHandler.ML_FunctionList(MLGUI.AddItem, "", is_func); } } else { parseError = true; Error(); } if (output[0] != "" && show_output) { string lu = (u + 1) + ""; r3.AppendText("line-" + lu); for (int o = 0; o < (5 - lu.Length); o++) { r3.Text += " "; } r3.AppendText("\t" + output[0] + "\n"); int z = 1; while (output[z] != "" && z < output.Length) { for (int o = 0; o < 10; o++) { r3.Text += " "; } r3.AppendText("\t" + output[z] + "\n"); z++; } } } processing = false; }
public static void ParseCommand() { // commands = { "solve", "value", "derivative", "integral", "roots", "plot" , "simplify"}; switch (comm_inx) { case 0: // solve case 1: // value { } break; case 2: // derivative { int bracket = 0; // Parse Function while (NotEnd()) { if (bracket == 0 && p_line[inx] == ',') { break; } if (p_line[inx] == '(') { bracket++; } if (p_line[inx] == ')') { bracket--; } synline[syn_inx] += p_line[inx]; inx++; } if (synline[syn_inx] == "") { syntaxError = true; Error(); break; } bool isVariable = false; bool isFunction = false; bool isFunctionName = false; int func_fn_inx = 0; int var_fn_inx = 0; // Try Parsing Function or Variable // All Variables get Added to ML_Variables if (isFunctionName = IsExistingFunctionName(synline[syn_inx])) { funcs[func_inx] = is_existingFunc; func_inx++; if (End()) { output[output_inx] = funcs[func_fn_inx].GetDerivative(funcs[func_fn_inx].VarList[0]).ToString(); break; } } else if (isVariable = IsVariable(synline[syn_inx])) { vars[var_inx] = ListHandler.ML_VariableList(MLGUI.AddItem, is_var); var_fn_inx = var_inx; var_inx++; if (End()) { FunctionTree temp = new FunctionTree(vars[var_fn_inx]); output[output_inx] = temp.GetDerivative(vars[var_fn_inx]).ToString(); break; } } else if (isFunction = IsFunction(synline[syn_inx])) { funcs[func_inx] = ListHandler.ML_FunctionList(MLGUI.AddItem, "", is_func); func_fn_inx = func_inx; func_inx++; if (End()) { output[output_inx] = funcs[func_fn_inx].GetDerivative(funcs[func_fn_inx].VarList[0]).ToString(); break; } } else { syntaxError = true; Error(); break; } // Parse Further SkipSpaces(); inx--; if (End()) { break; } bool wrtSet = false; FVar wrtVar = null; double wrtVarVal = 0; bool wrtVarValSet = false; syn_inx++; List <string> varEqList = new List <string>(); // Next vars[var_inx] Entry will be the w.r.t. variable int func_sl_inx = syn_inx; // Parse rest of the line // Requires addition of "," at end p_line = p_line + ","; p_len = p_line.Length; inx++; while (NotEnd()) { if (p_line[inx] == ',') { if (!isVariable && IsEquation(synline[syn_inx]) && SplitEquation(synline[syn_inx], VariableAssignment)) { if (ListHandler.ML_VariableList(MLGUI.UpdateVariableValue, is_var, is_val) == null) { syntaxError = true; break; } else { varEqList.Add(is_var); } } else if (IsNumber(synline[syn_inx]) && !wrtVarValSet) { wrtVarVal = is_val; if (wrtSet) { ListHandler.ML_VariableList(MLGUI.UpdateVariableValue, wrtVar.varName, is_val); wrtVarVal = is_val; } wrtVarValSet = true; } else if (IsVariable(synline[syn_inx]) && !wrtSet) { wrtVar = ListHandler.ML_VariableList(MLGUI.AddItem, is_var); wrtSet = true; } else { syntaxError = true; break; } syn_inx++; } else { synline[syn_inx] += p_line[inx]; } inx++; } if (Error()) { break; } if (isVariable) { if (!wrtSet) { wrtVar = vars[var_fn_inx]; if (wrtVarValSet) { ListHandler.ML_VariableList(MLGUI.UpdateVariableValue, wrtVar.varName, wrtVarVal); } } output[output_inx] += vars[var_fn_inx].GetDerivative(wrtVar).ToString(); break; } if (!wrtSet) { wrtVar = funcs[func_fn_inx].varList[0]; } if (wrtVarValSet) { ListHandler.ML_VariableList(MLGUI.UpdateVariableValue, wrtVar.varName, wrtVarVal); } FunctionTree copy = funcs[func_fn_inx].GetCopy(); foreach (string varEq in varEqList) { if (varEq == wrtVar.varName) { continue; } if (!copy.VariableToSetValue(varEq)) { syntaxError = true; break; } } FunctionTree der = copy.GetDerivative(wrtVar); if (Error()) { break; } // Store result in output string if (der.varList.Count == 0) { output[output_inx] = der.GetValue().ToString(); // Important to figure out properly comm_isAnsNumVal = true; // Single answer ListHandler.ML_FunctionList(MLGUI.RemoveItem, "ans"); ListHandler.ML_VariableList(MLGUI.RemoveItem, "ans"); ListHandler.ML_VariableList(MLGUI.AddItem, "ans", der.GetValue()); } else { output[output_inx] = der.ToString(); if (der.CanHaveValue()) { string derVal = der.GetValue().ToString(); if (!(derVal == output[output_inx])) { output_inx++; output[output_inx] = derVal; // Important to figure out properly comm_isAnsFunc = true; comm_isAnsNumVal = true; // Two Answers ListHandler.ML_FunctionList(MLGUI.RemoveItem, "ans0"); ListHandler.ML_VariableList(MLGUI.RemoveItem, "ans0"); ListHandler.ML_FunctionList(MLGUI.RemoveItem, "ans"); ListHandler.ML_VariableList(MLGUI.RemoveItem, "ans"); ListHandler.ML_FunctionList(MLGUI.AddItem, "ans0", der.ToString()); ListHandler.ML_VariableList(MLGUI.AddItem, "ans", der.GetValue()); } else { // Important to figure out properly comm_isAnsNumVal = true; ListHandler.ML_FunctionList(MLGUI.RemoveItem, "ans"); ListHandler.ML_VariableList(MLGUI.RemoveItem, "ans"); ListHandler.ML_VariableList(MLGUI.AddItem, "ans", der.GetValue()); } } else { // Important to figure out properly comm_isAnsFunc = true; // Single answer ListHandler.ML_FunctionList(MLGUI.RemoveItem, "ans"); ListHandler.ML_VariableList(MLGUI.RemoveItem, "ans"); ListHandler.ML_FunctionList(MLGUI.AddItem, "ans", der.ToString()); } } } break; case 3: // integral { } break; case 4: // roots { } break; case 5: // plot { } break; case 6: // simplify { } break; case 7: // cls { r2.SelectAll(); r2.SelectionProtected = false; r2.Clear(); r3.Clear(); mlgui.AddLineNumbers(0); } break; default: break; } }
public virtual Function AddVariable(FVar @var) { this.varList.Add(@var); return(@var); }
public override Function GetIntegral(FVar var) { return(null); }
public abstract Function GetIntegral(FVar var);
public abstract Function GetDerivative(FVar var);
internal Typeface ReadTableEntryCollection(TableEntryCollection tables, BinaryReader input) { OS2Table os2Table = ReadTableIfExists(tables, input, new OS2Table()); NameEntry nameEntry = ReadTableIfExists(tables, input, new NameEntry()); Head header = ReadTableIfExists(tables, input, new Head()); MaxProfile maximumProfile = ReadTableIfExists(tables, input, new MaxProfile()); HorizontalHeader horizontalHeader = ReadTableIfExists(tables, input, new HorizontalHeader()); HorizontalMetrics horizontalMetrics = ReadTableIfExists(tables, input, new HorizontalMetrics(horizontalHeader.HorizontalMetricsCount, maximumProfile.GlyphCount)); //--- PostTable postTable = ReadTableIfExists(tables, input, new PostTable()); CFFTable cff = ReadTableIfExists(tables, input, new CFFTable()); //-------------- Cmap cmaps = ReadTableIfExists(tables, input, new Cmap()); GlyphLocations glyphLocations = ReadTableIfExists(tables, input, new GlyphLocations(maximumProfile.GlyphCount, header.WideGlyphLocations)); Glyf glyf = ReadTableIfExists(tables, input, new Glyf(glyphLocations)); //-------------- Gasp gaspTable = ReadTableIfExists(tables, input, new Gasp()); VerticalDeviceMetrics vdmx = ReadTableIfExists(tables, input, new VerticalDeviceMetrics()); //-------------- Kern kern = ReadTableIfExists(tables, input, new Kern()); //deprecated //-------------- //advanced typography GDEF gdef = ReadTableIfExists(tables, input, new GDEF()); GSUB gsub = ReadTableIfExists(tables, input, new GSUB()); GPOS gpos = ReadTableIfExists(tables, input, new GPOS()); BASE baseTable = ReadTableIfExists(tables, input, new BASE()); JSTF jstf = ReadTableIfExists(tables, input, new JSTF()); COLR colr = ReadTableIfExists(tables, input, new COLR()); CPAL cpal = ReadTableIfExists(tables, input, new CPAL()); VerticalHeader vhea = ReadTableIfExists(tables, input, new VerticalHeader()); if (vhea != null) { VerticalMetrics vmtx = ReadTableIfExists(tables, input, new VerticalMetrics(vhea.NumOfLongVerMetrics)); } STAT stat = ReadTableIfExists(tables, input, new STAT()); if (stat != null) { FVar fvar = ReadTableIfExists(tables, input, new FVar()); if (fvar != null) { GVar gvar = ReadTableIfExists(tables, input, new GVar()); CVar cvar = ReadTableIfExists(tables, input, new CVar()); HVar hvar = ReadTableIfExists(tables, input, new HVar()); MVar mvar = ReadTableIfExists(tables, input, new MVar()); AVar avar = ReadTableIfExists(tables, input, new AVar()); } } //test math table MathTable mathtable = ReadTableIfExists(tables, input, new MathTable()); //--------------------------------------------- //about truetype instruction init //--------------------------------------------- Typeface typeface = null; bool isPostScriptOutline = false; bool isBitmapFont = false; if (glyf == null) { //check if this is cff table ? if (cff == null) { //check cbdt/cblc ? CBLC cblcTable = ReadTableIfExists(tables, input, new CBLC()); if (cblcTable != null) { CBDT cbdtTable = ReadTableIfExists(tables, input, new CBDT()); //read cbdt //bitmap font BitmapFontGlyphSource bmpFontGlyphSrc = new BitmapFontGlyphSource(cblcTable, cbdtTable); Glyph[] glyphs = bmpFontGlyphSrc.BuildGlyphList(); typeface = new Typeface( nameEntry, header.Bounds, header.UnitsPerEm, bmpFontGlyphSrc, glyphs, horizontalMetrics, os2Table); isBitmapFont = true; } else { //TODO: EBLC fontBmpTable = ReadTableIfExists(tables, input, new EBLC()); throw new NotSupportedException(); } } else { //... //PostScript outline font isPostScriptOutline = true; typeface = new Typeface( nameEntry, header.Bounds, header.UnitsPerEm, cff, horizontalMetrics, os2Table); } } else { typeface = new Typeface( nameEntry, header.Bounds, header.UnitsPerEm, glyf.Glyphs, horizontalMetrics, os2Table); } //---------------------------- typeface.CmapTable = cmaps; typeface.KernTable = kern; typeface.GaspTable = gaspTable; typeface.MaxProfile = maximumProfile; typeface.HheaTable = horizontalHeader; //---------------------------- if (!isPostScriptOutline && !isBitmapFont) { FpgmTable fpgmTable = ReadTableIfExists(tables, input, new FpgmTable()); //control values table CvtTable cvtTable = ReadTableIfExists(tables, input, new CvtTable()); if (cvtTable != null) { typeface.ControlValues = cvtTable._controlValues; } if (fpgmTable != null) { typeface.FpgmProgramBuffer = fpgmTable._programBuffer; } PrepTable propProgramTable = ReadTableIfExists(tables, input, new PrepTable()); if (propProgramTable != null) { typeface.PrepProgramBuffer = propProgramTable._programBuffer; } } //------------------------- typeface.LoadOpenFontLayoutInfo( gdef, gsub, gpos, baseTable, colr, cpal); //------------ { SvgTable svgTable = ReadTableIfExists(tables, input, new SvgTable()); if (svgTable != null) { typeface._svgTable = svgTable; } } typeface.PostTable = postTable; if (mathtable != null) { var mathGlyphLoader = new MathGlyphLoader(); mathGlyphLoader.LoadMathGlyph(typeface, mathtable); } #if DEBUG //test //int found = typeface.GetGlyphIndexByName("Uacute"); if (typeface.IsCffFont) { //optional typeface.UpdateAllCffGlyphBounds(); } #endif return(typeface); }
public override Function GetIntegral(FVar @var) { // TODO Auto-generated method stub return(null); }
public static void CreateFunctionTree(string[] postfixArray, FunctionTree FTree) { FunctionStack fStk = new FunctionStack(); string f; int i = 0; FTree.varList = new List <FVar>(); while (i < postfixArray.Length) { f = postfixArray[i]; //System.out.println("fff "+ f); if (f.Equals(FNeg.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FNeg.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FNeg(fStk.TopAndPop())); } else if (f.Equals(FAdd.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FAdd.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FAdd(fStk.TopAndPop(), fStk.TopAndPop(), 1)); } else if (f.Equals(FSub.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FSub.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FSub(fStk.TopAndPop(), fStk.TopAndPop(), 1)); } else if (f.Equals(FMul.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FMul.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FMul(fStk.TopAndPop(), fStk.TopAndPop(), 1)); } else if (f.Equals(FDiv.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FDiv.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FDiv(fStk.TopAndPop(), fStk.TopAndPop(), 1)); } else if (f.Equals(FPow.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FPow.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FPow(fStk.TopAndPop(), fStk.TopAndPop(), 1)); } else if (f.Equals(FExp.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FExp.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FExp(fStk.TopAndPop())); } else if (f.Equals(FLn.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FLn.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FLn(fStk.TopAndPop())); } // sin() else if (f.Equals(FSin.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FSin.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FSin(fStk.TopAndPop())); } else if (f.Equals(FCos.ID, StringComparison.CurrentCultureIgnoreCase) || f.Equals(FCos.Symbol, StringComparison.CurrentCultureIgnoreCase)) { fStk.Push(new FCos(fStk.TopAndPop())); } // add rest of the functions else if (IsConstant(f)) // double number { fStk.Push(new FCons(Convert.ToDouble(f))); } else { FVar @var = FTree.FindVariable(f); if (@var != null) { fStk.Push(@var); } else { fStk.Push(FTree.AddVariable(new FVar(f))); // variable } } i++; } FTree.rootNode = fStk.TopAndPop(); }
public VariableEntry(string n, FVar v) { Name = n; Variable = v; }