RtfDomParser.RTFReader.ReadToken C# (CSharp) Method

ReadToken() public method

read token
public ReadToken ( ) : RTFToken
return RTFToken
        public RTFToken ReadToken()
        {
            bolFirstTokenInGroup = false;
            myLastToken = myCurrentToken;
            if (myLastToken != null && myLastToken.Type == RTFTokenType.GroupStart)
            {
                bolFirstTokenInGroup = true;
            }
            myCurrentToken = myLex.NextToken( );
            if( myCurrentToken == null || myCurrentToken.Type == RTFTokenType.Eof )
            {
                myCurrentToken = null;
                return null;
            }
            intTokenCount++;
            if (myCurrentToken.Type == RTFTokenType.GroupStart)
            {
                if (_LayerStack.Count == 0)
                {
                    _LayerStack.Push(new RTFRawLayerInfo());
                }
                else
                {
                    RTFRawLayerInfo info = _LayerStack.Peek();
                    _LayerStack.Push(info.Clone());
                }
                intLevel++;
            }
            else if (myCurrentToken.Type == RTFTokenType.GroupEnd)
            {
                if (_LayerStack.Count > 0)
                {
                    _LayerStack.Pop();
                }
                intLevel--;
            }
            if (this.EnableDefaultProcess)
            {
                this.DefaultProcess();
            }
            //if (myTokenStack.Count > 0)
            //{
            //    myCurrentToken.Parent = (RTFToken)myTokenStack[myTokenStack.Count - 1];
            //}
            //myTokenStack.Add( myCurrentToken );
            return myCurrentToken ;
        }

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// load rtf
        /// </summary>
        /// <param name="reader">RTF text reader</param>
        public void Load(RTFReader reader)
        {
            MyNodes.Clear();
            var groups = new Stack<RTFNodeGroup>();
            RTFNodeGroup newGroup = null;
            RTFNode newNode = null;
            while (reader.ReadToken() != null)
            {
                if (reader.TokenType == RTFTokenType.GroupStart)
                {
                    // begin group
                    if (newGroup == null)
                    {
                        newGroup = this;
                    }
                    else
                    {
                        newGroup = new RTFNodeGroup();
                        newGroup.OwnerDocument = this;
                    }
                    if (newGroup != this)
                    {
                        var g = groups.Peek();
                        g.AppendChild(newGroup);
                    }
                    groups.Push(newGroup);
                }
                else if (reader.TokenType == RTFTokenType.GroupEnd)
                {
                    // end group
                    newGroup = groups.Pop();
                    newGroup.MergeText();
                    if (newGroup.FirstNode is RTFNode)
                    {
                        switch (newGroup.Keyword)
                        {
                            case RTFConsts.Fonttbl:
                                // read font table
                                ReadFontTable(newGroup);
                                break;
                            case RTFConsts.Colortbl:
                                // read color table
                                ReadColorTable(newGroup);
                                break;
                            case RTFConsts.Info:
                                // read document information
                                ReadDocumentInfo(newGroup);
                                break;
                        }
                    }
                    if (groups.Count > 0)
                    {
                        newGroup = groups.Peek();
                    }
                    else
                    {
                        break;
                    }
                    //NewGroup.MergeText();
                }
                else
                {
                    // read content

                    newNode = new RTFNode(reader.CurrentToken);
                    newNode.OwnerDocument = this;
                    newGroup.AppendChild(newNode);
                    if (newNode.Keyword == RTFConsts.F)
                    {
                        var font = FontTable[newNode.Parameter];
                        if (font != null)
                        {
                            _myFontChartset = font.Encoding;
                        }
                        else
                        {
                            _myFontChartset = null;
                        }
                        //myFontChartset = RTFFont.GetRTFEncoding( NewNode.Parameter );
                    }
                    else if (newNode.Keyword == RTFConsts.Af)
                    {
                        var font = FontTable[newNode.Parameter];
                        if (font != null)
                        {
                            _myAssociateFontChartset = font.Encoding;
                        }
                        else
                        {
                            _myAssociateFontChartset = null;
                        }
                    }
                }
            } // while( reader.ReadToken() != null )
            while (groups.Count > 0)
            {
                newGroup = groups.Pop();
                newGroup.MergeText();
            }
            //this.UpdateInformation();
        }
All Usage Examples Of RtfDomParser.RTFReader::ReadToken