示例#1
0
 public void Add(TexFormula formula)
 {
     if (formula.RootAtom is RowAtom)
     {
         Add(RowAtom.Get(formula.ExtractRoot()));
     }
     else
     {
         Add(formula.RootAtom);
     }
 }
示例#2
0
        private Atom InsertAttribute(Atom atom, Atom begin, Atom end)
        {
            if (!(atom is RowAtom))
            {
                atom = RowAtom.Get(atom);
            }
            var row = (RowAtom)atom;

            row.Add(end);
            row.Elements.Insert(0, begin);
            return(row);
        }
示例#3
0
        public static TexFormula Get(IList <TexFormula> formulaList)
        {
            var formula = ObjPool <TexFormula> .Get();

            if (formulaList.Count == 1)
            {
                formula.Add(formulaList[0]);
            }
            else
            {
                formula.RootAtom = RowAtom.Get(formulaList);
            }
            return(formula);
        }
示例#4
0
 public static void ParseMatrix(List <Atom> el, List <List <Atom> > childs)
 {
     Last(childs).Add(RowAtom.Get());
     foreach (Atom a in el)
     {
         if (a is SymbolAtom)
         {
             var b = ((SymbolAtom)a);
             if (b.Name == "ampersand")
             {
                 Last(childs).Add(RowAtom.Get());
                 b.Flush();
             }
             else if (b.Name == "mid")
             {
                 childs.Add(ListPool <Atom> .Get());
                 Last(childs).Add(RowAtom.Get());
                 b.Flush();
             }
             else
             {
                 ((RowAtom)Last(Last(childs))).Add(a);
             }
         }
         else if (a is CharAtom)
         {
             var b = ((CharAtom)a);
             if (b.Character == 0x26)
             {
                 Last(childs).Add(RowAtom.Get());
                 b.Flush();
             }
             else if ((b.Character == 0x7c))
             {
                 childs.Add(ListPool <Atom> .Get());
                 Last(childs).Add(RowAtom.Get());
                 b.Flush();
             }
             else
             {
                 ((RowAtom)Last(Last(childs))).Add(a);
             }
         }
         else
         {
             ((RowAtom)Last(Last(childs))).Add(a);
         }
     }
 }
示例#5
0
 public void Add(Atom atom, bool preferUnwrap = false)
 {
     if (RootAtom == null)
     {
         RootAtom = atom;
     }
     else
     {
         if (!(RootAtom is RowAtom))
         {
             RootAtom = RowAtom.Get(RootAtom);
         }
         ((RowAtom)RootAtom).Add(atom, preferUnwrap);
     }
 }
示例#6
0
 public void Add(Atom atom)
 {
     if (RootAtom == null)
     {
         RootAtom = atom;
     }
     else
     {
         if (!(RootAtom is RowAtom))
         {
             RootAtom = RowAtom.Get(RootAtom);
         }
         ((RowAtom)RootAtom).Add(atom);
     }
 }
示例#7
0
        public static void ParseMatrixVertical(List <Atom> el, List <List <Atom> > childs)
        {
            Last(childs).Add(ObjPool <RowAtom> .Get());
            int vPool = 0, hPool = 0;

            foreach (Atom a in el)
            {
                if (a is SymbolAtom)
                {
                    var b = ((SymbolAtom)a);
                    if (b.Name == "ampersand")
                    {
                        hPool++;
                        Last(childs).Add(RowAtom.Get());
                        vPool = 0;
                        for (int i = 0; i < childs.Count; i++)
                        {
                            if (childs[i].Count < hPool + 1)
                            {
                                childs[i].Add(RowAtom.Get());
                            }
                        }
                        b.Flush();
                    }
                    else if (b.Name == "mid")
                    {
                        vPool++;
                        if (childs.Count <= vPool)
                        {
                            childs.Add(new List <Atom>());
                            while (Last(childs).Count < hPool + 1)
                            {
                                Last(childs).Add(RowAtom.Get());
                            }
                        }
                        b.Flush();
                    }
                }
                else if (a is CharAtom)
                {
                    var b = ((CharAtom)a);
                    if (b.Character == 0x26 /*ampersand*/)
                    {
                        hPool++;
                        Last(childs).Add(RowAtom.Get());
                        vPool = 0;
                        for (int i = 0; i < childs.Count; i++)
                        {
                            if (childs[i].Count < hPool + 1)
                            {
                                childs[i].Add(RowAtom.Get());
                            }
                        }
                        b.Flush();
                    }
                    else if (b.Character == 0x7c)
                    {
                        vPool++;
                        if (childs.Count <= vPool)
                        {
                            childs.Add(new List <Atom>());
                            while (Last(childs).Count < hPool + 1)
                            {
                                Last(childs).Add(RowAtom.Get());
                            }
                        }
                        b.Flush();
                    }
                    else
                    {
                        ((RowAtom)Last(childs[vPool])).Add(a);
                    }
                }
                else
                {
                    ((RowAtom)Last(childs[vPool])).Add(a);
                }
            }
        }
示例#8
0
        private void ProcessEscapeSequence(TexFormula formula, string value, ref int position)
        {
            position++;

            var command = LookForAWord(value, ref position);

            // Check if there's no command
            if (command.Length == 0)
            {
                if (position < value.Length)
                {
                    var nextChar = value[position];
                    if (IsParserReserved(nextChar))
                    {
                        formula.Add(ConvertCharacter(value, ref position, nextChar));
                    }
                }
                return;
            }

            //Check if the command registered in Commands
            if (isCommandRegistered(command))
            {
                formula.Add(AttachScripts(formula, value, ref position,
                                          ProcessCommand(formula, value, ref position, command)));
                return;
            }

            //Check if the command registered in FontID
            var fontID = TEXPreference.main.GetFontIndexByID(command);

            if (fontID != -1)
            {
                SkipWhiteSpace(value, ref position);
                formula.Add(ParseFontStyle(value, ref position, fontID,
                                           ParseFontStyle(ReadInsideBracket(value, ref position))));
                return;
            }

            SymbolAtom symbolAtom = SymbolAtom.GetAtom(command);

            //Check if the command registered in Symbol database

            if (symbolAtom != null)
            {
                // Symbol was found.
                if (symbolAtom.RightType == CharType.Accent && formula.RootAtom != null)
                {
                    //Accent is Found
                    Atom baseAtom = formula.RootAtom;
                    if (baseAtom is RowAtom)
                    {
                        var row = (RowAtom)baseAtom;
                        baseAtom = MatrixAtom.Last(row.Elements);
                        row.Elements.RemoveAt(row.Elements.Count - 1);
                    }
                    else
                    {
                        formula.RootAtom = null;
                    }

                    formula.Add(AttachScripts(formula, value, ref position, AccentedAtom.Get(baseAtom, symbolAtom)));
                }
                else
                {
                    formula.Add(AttachScripts(formula, value, ref position, symbolAtom));
                }
                return;
            }

            //No lucks, now ...

            {
                // Command aren't defined, use it as command text style
                RowAtom row = RowAtom.Get();
                for (int i = 0; i < command.Length; i++)
                {
                    var charAtom = CharAtom.Get(command[i],
                                                TEXConfiguration.main.Typeface_Commands);
                    row.Add(charAtom);
                }
                formula.Add(AttachScripts(formula, value, ref position, row));
            }
        }