Exemple #1
0
        public void Load(System.IO.TextReader reader)
        {
            RTFReader myReader = new RTFReader();

            myReader.LoadReader(reader);
            Load(myReader);
        }
Exemple #2
0
 /// <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();
     }
 }
Exemple #3
0
 /// <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();
     }
 }
Exemple #4
0
        /// <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();
        }
Exemple #5
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);
                     }
                 }
             }
         }
         CheckBuffer();
         myStr.Append(token.Key);
         return(true);
     }
     else if (token.Type == RTFTokenType.Control &&
              token.Key == "'" && token.HasParam)
     {
         myBuffer.Add((byte)token.Param);
         return(true);
     }
     if (token.Key == RTFConsts._u && token.HasParam)
     {
         // Unicode char
         CheckBuffer();
         // 忽略 \u 指令
         //myStr.Append( (char)token.Param);
         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);
 }