Exemplo n.º 1
0
        public static AccentedAtom Get(Atom baseAtom, string accentName)
        {
            var atom = ObjPool <AccentedAtom> .Get();

            atom.BaseAtom   = baseAtom ?? SpaceAtom.Get(0, 0, 0);
            atom.AccentAtom = SymbolAtom.GetAtom(accentName);
            return(atom);
        }
Exemplo n.º 2
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));
            }
        }