Наследование: IDisposable
Пример #1
0
        public void Load(System.IO.TextReader reader)
        {
            var myReader = new RTFReader();

            myReader.LoadReader(reader);
            Load(myReader);
        }
Пример #2
0
 /// <summary>
 /// load rtf file
 /// </summary>
 /// <param name="strFileName">file name</param>
 public void Load(string strFileName)
 {
     myEncoding = null;
     using (var reader = new RTFReader())
     {
         if (reader.LoadRTFFile(strFileName))
         {
             Load(reader);
             reader.Close();
         }
         reader.Close();
     }
 }
Пример #3
0
 /// <summary>
 /// load rtf text
 /// </summary>
 /// <param name="strText">text in rtf format</param>
 public void LoadRTFText(string strText)
 {
     myEncoding = null;
     using (var reader = new RTFReader())
     {
         if (reader.LoadRTFText(strText))
         {
             Load(reader);
             reader.Close();
         }
         reader.Close();
     }
 }
Пример #4
0
 /// <summary>
 /// Accept rtf token
 /// </summary>
 /// <param name="token">RTF token</param>
 /// <returns>Is accept it?</returns>
 public bool Accept(RTFToken token, RTFReader reader)
 {
     if (token == null)
     {
         return(false);
     }
     if (token.Type == RTFTokenType.Text)
     {
         if (reader != null)
         {
             if (token.Key[0] == '?')
             {
                 if (reader.LastToken != null)
                 {
                     if (reader.LastToken.Type == RTFTokenType.Keyword &&
                         reader.LastToken.Key == "u" &&
                         reader.LastToken.HasParam)
                     {
                         // 紧跟在在“\uN”后面的问号忽略掉
                         if (token.Key.Length > 0)
                         {
                             CheckBuffer();
                             //myStr.Append(token.Key.Substring(1));
                         }
                         return(true);
                     }
                 }
             }
             //else if (token.Key == "\"")
             //{
             //    // 双引号开头,一直读取内容到双引号结束
             //    CheckBuffer();
             //    while (true)
             //    {
             //        int v = reader.InnerReader.Read();
             //        if (v > 0)
             //        {
             //            if (v == (int)'"')
             //            {
             //                break;
             //            }
             //            else
             //            {
             //                myStr.Append((char)v);
             //            }
             //        }
             //        else
             //        {
             //            break;
             //        }
             //    }//while
             //    return true;
             //}
         }
         CheckBuffer();
         myStr.Append(token.Key);
         return(true);
     }
     else if (token.Type == RTFTokenType.Control &&
              token.Key == "'" && token.HasParam)
     {
         if (reader.CurrentLayerInfo.CheckUCValueCount())
         {
             myBuffer.Add((byte)token.Param);
         }
         return(true);
     }
     if (token.Key == RTFConsts._u && token.HasParam)
     {
         // Unicode char
         CheckBuffer();
         // 不忽略 \u 指令
         myStr.Append((char)token.Param);
         reader.CurrentLayerInfo.UCValueCount = reader.CurrentLayerInfo.UCValue;
         return(true);
     }
     if (token.Key == "tab")
     {
         CheckBuffer();
         myStr.Append("\t");
         return(true);
     }
     if (token.Key == "emdash")
     {
         CheckBuffer();
         myStr.Append('—');
         return(true);
     }
     if (token.Key == "")
     {
         // 提示未识别的字符
         CheckBuffer();
         myStr.Append('-');
         return(true);
     }
     return(false);
 }
Пример #5
0
 /// <summary>
 /// Accept rtf token
 /// </summary>
 /// <param name="token">RTF token</param>
 /// <param name="reader"></param>
 /// <returns>Is accept it?</returns>
 public bool Accept(RTFToken token, RTFReader reader)
 {
     if (token == null)
     {
         return false;
     }
     if (token.Type == RTFTokenType.Text)
     {
         if (reader != null)
         {
             if (token.Key[0] == '?')
             {
                 if (reader.LastToken != null)
                 {
                     if (reader.LastToken.Type == RTFTokenType.Keyword
                         && reader.LastToken.Key == "u"
                         && reader.LastToken.HasParam)
                     {
                         if (token.Key.Length > 0)
                         {
                             CheckBuffer();
                             //myStr.Append(token.Key.Substring(1));
                         }
                         return true;
                     }
                 }
             }
             //else if (token.Key == "\"")
             //{
             //    CheckBuffer();
             //    while (true)
             //    {
             //        int v = reader.InnerReader.Read();
             //        if (v > 0)
             //        {
             //            if (v == (int)'"')
             //            {
             //                break;
             //            }
             //            else
             //            {
             //                myStr.Append((char)v);
             //            }
             //        }
             //        else
             //        {
             //            break;
             //        }
             //    }//while
             //    return true;
             //}
         }
         CheckBuffer();
         _myStr.Append(token.Key);
         return true;
     }
     if (token.Type == RTFTokenType.Control
         && token.Key == "'" && token.HasParam)
     {
         if (reader.CurrentLayerInfo.CheckUcValueCount())
         {
             _myBuffer.Add((byte) token.Param);
         }
         return true;
     }
     if (token.Key == RTFConsts.U && token.HasParam)
     {
         // Unicode char
         CheckBuffer();
         _myStr.Append((char) token.Param);
         reader.CurrentLayerInfo.UcValueCount = reader.CurrentLayerInfo.UcValue;
         return true;
     }
     if (token.Key == "tab")
     {
         CheckBuffer();
         _myStr.Append("\t");
         return true;
     }
     if (token.Key == "emdash")
     {
         CheckBuffer();
         _myStr.Append('—');
         return true;
     }
     if (token.Key == "")
     {
         CheckBuffer();
         _myStr.Append('-');
         return true;
     }
     return false;
 }
 /// <summary>
 /// load rtf text
 /// </summary>
 /// <param name="strText">text in rtf format</param>
 public void LoadRTFText( string strText )
 {
     myEncoding = null ;
     using( RTFReader reader = new RTFReader())
     {
         if( reader.LoadRTFText( strText ))
         {
             Load( reader );
             reader.Close();
         }
         reader.Close();
     }
 }
        /// <summary>
        /// load rtf
        /// </summary>
        /// <param name="reader">RTF text reader</param>
        public void Load( RTFReader reader )
        {
            myNodes.Clear();
            System.Collections.Stack groups = new System.Collections.Stack();
            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 )
                    {
                        RTFNodeGroup g = ( RTFNodeGroup ) groups.Peek();
                        g.AppendChild( NewGroup );
                    }
                    groups.Push( NewGroup );
                }
                else if( reader.TokenType == RTFTokenType.GroupEnd )
                {
                    // end group
                    NewGroup = ( RTFNodeGroup ) 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 = (RTFNodeGroup)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 )
                    {
                        RTFFont font = this.FontTable[NewNode.Parameter];
                        if (font != null)
                        {
                            myFontChartset = font.Encoding;
                        }
                        else
                        {
                            myFontChartset = null;
                        }
                        //myFontChartset = RTFFont.GetRTFEncoding( NewNode.Parameter );
                    }
                    else if (NewNode.Keyword == RTFConsts._af)
                    {
                        RTFFont font = this.FontTable[NewNode.Parameter];
                        if (font != null)
                        {
                            myAssociateFontChartset = font.Encoding;
                        }
                        else
                        {
                            myAssociateFontChartset = null;
                        }
                    }
                }
            }// while( reader.ReadToken() != null )
            while( groups.Count > 0 )
            {
                NewGroup = ( RTFNodeGroup ) groups.Pop();
                NewGroup.MergeText();
            }
            //this.UpdateInformation();
        }
 public void Load( System.IO.TextReader reader )
 {
     RTFReader myReader = new RTFReader();
     myReader.LoadReader( reader );
     Load( myReader );
 }
 /// <summary>
 /// load rtf file
 /// </summary>
 /// <param name="strFileName">file name</param>
 public void Load( string strFileName )
 {
     myEncoding = null ;
     using( RTFReader reader = new RTFReader() )
     {
         if( reader.LoadRTFFile( strFileName ) )
         {
             Load( reader );
             reader.Close();
         }
         reader.Close();
     }
 }
Пример #10
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();
        }
Пример #11
0
 public void Load(TextReader reader)
 {
     var myReader = new RTFReader();
     myReader.LoadReader(reader);
     Load(myReader);
 }
Пример #12
0
        /// <summary>
        /// load rtf file
        /// </summary>
        public void Load(Stream stream)
        {
            _myEncoding = null;
            using (var reader = new RTFReader())
            {
                reader.LoadStream(stream);

                Load(reader);
                reader.Close();
            }
        }
Пример #13
0
        /// <summary>
        /// load rtf
        /// </summary>
        /// <param name="reader">RTF text reader</param>
        public void Load(RTFReader reader)
        {
            myNodes.Clear();
            var          groups   = new System.Collections.Stack();
            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 = ( RTFNodeGroup )groups.Peek();
                        g.AppendChild(NewGroup);
                    }
                    groups.Push(NewGroup);
                }
                else if (reader.TokenType == RTFTokenType.GroupEnd)
                {
                    // end group
                    NewGroup = ( RTFNodeGroup )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 = (RTFNodeGroup)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 = ( RTFNodeGroup )groups.Pop();
                NewGroup.MergeText();
            }
            //this.UpdateInformation();
        }