コード例 #1
0
ファイル: DomDocument.cs プロジェクト: iraychen/MSGReader
        /// <summary>
        /// Read field
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        private void ReadDomField(
            Reader reader,
            DocumentFormatInfo format)
        {
            var field = new DomField {NativeLevel = reader.Level};
            AddContentElement(field);
            var levelBack = reader.Level;
            while (reader.ReadToken() != null)
            {
                if (reader.Level < levelBack)
                    break;

                if (reader.TokenType == RtfTokenType.GroupStart)
                {
                }
                else if (reader.TokenType == RtfTokenType.GroupEnd)
                {
                }
                else
                {
                    switch (reader.Keyword)
                    {
                        case Consts.Flddirty:
                            field.Method = RtfDomFieldMethod.Dirty;
                            break;
            
                        case Consts.Fldedit:
                            field.Method = RtfDomFieldMethod.Edit;
                            break;
                        
                        case Consts.Fldlock:
                            field.Method = RtfDomFieldMethod.Lock;
                            break;
                        
                        case Consts.Fldpriv:
                            field.Method = RtfDomFieldMethod.Priv;
                            break;
                        
                        case Consts.Fldrslt:
                            var result = new ElementContainer {Name = Consts.Fldrslt};
                            field.AppendChild(result);
                            Load(reader, format);
                            result.Locked = true;
                            break;
                        
                        case Consts.Fldinst:
                            var inst = new ElementContainer {Name = Consts.Fldinst};
                            field.AppendChild(inst);
                            Load(reader, format);
                            inst.Locked = true;
                            var txt = inst.InnerText;
                            if (txt != null)
                            {
                                var index = txt.IndexOf(Consts.Hyperlink, StringComparison.Ordinal);
                                if (index >= 0)
                                {
                                    var index1 = txt.IndexOf('\"', index);
                                    if (index1 > 0 && txt.Length > index1 + 2)
                                    {
                                        var index2 = txt.IndexOf('\"', index1 + 2);
                                        if (index2 > index1)
                                        {
                                            var link = txt.Substring(index1 + 1, index2 - index1 - 1);
                                            if (format.Parent != null)
                                            {
                                                if (link.StartsWith("_Toc"))
                                                    link = "#" + link;
                                                format.Parent.Link = link;
                                            }
                                        }
                                    } 
                                }
                            }

                            break;
                    } 
                }
            } 
            field.Locked = true;
            //return field;
        }
コード例 #2
0
ファイル: DomDocument.cs プロジェクト: iraychen/MSGReader
 /// <summary>
 /// Read a rtf emb object
 /// </summary>
 /// <param name="reader">reader</param>
 /// <param name="format">format</param>
 /// <returns>rtf emb object instance</returns>
 private void ReadDomObject(Reader reader, DocumentFormatInfo format)
 {
     var domObject = new DomObject {NativeLevel = reader.Level};
     AddContentElement(domObject);
     var levelBack = reader.Level;
     
     while (reader.ReadToken() != null)
     {
         if (reader.Level < levelBack)
             break;
         if (reader.TokenType == RtfTokenType.GroupStart)
             continue;
         if (reader.TokenType == RtfTokenType.GroupEnd)
             continue;
         if (reader.Level == domObject.NativeLevel + 1
             && reader.Keyword.StartsWith("attribute_"))
             domObject.CustomAttributes[reader.Keyword] = ReadInnerText(reader, true);
         
         switch (reader.Keyword)
         {
             case Consts.Objautlink:
                 domObject.Type = RtfObjectType.AutLink;
                 break;
             
             case Consts.Objclass:
                 domObject.ClassName = ReadInnerText(reader, true);
                 break;
             
             case Consts.Objdata:
                 var data = ReadInnerText(reader, true);
                 domObject.Content = HexToBytes(data);
                 break;
             
             case Consts.Objemb:
                 domObject.Type = RtfObjectType.Emb;
                 break;
             
             case Consts.Objh:
                 domObject.Height = reader.Parameter;
                 break;
             
             case Consts.Objhtml:
                 domObject.Type = RtfObjectType.Html;
                 break;
             
             case Consts.Objicemb:
                 domObject.Type = RtfObjectType.Icemb;
                 break;
             
             case Consts.Objlink:
                 domObject.Type = RtfObjectType.Link;
                 break;
             
             case Consts.Objname:
                 domObject.Name = ReadInnerText(reader, true);
                 break;
             
             case Consts.Objocx:
                 domObject.Type = RtfObjectType.Ocx;
                 break;
             
             case Consts.Objpub:
                 domObject.Type = RtfObjectType.Pub;
                 break;
             
             case Consts.Objsub:
                 domObject.Type = RtfObjectType.Sub;
                 break;
             
             case Consts.Objtime:
                 break;
             
             case Consts.Objw:
                 domObject.Width = reader.Parameter;
                 break;
             
             case Consts.Objscalex:
                 domObject.ScaleX = reader.Parameter;
                 break;
             
             case Consts.Objscaley:
                 domObject.ScaleY = reader.Parameter;
                 break;
             
             case Consts.Result:
                 var result = new ElementContainer {Name = Consts.Result};
                 domObject.AppendChild(result);
                 Load(reader, format);
                 result.Locked = true;
                 break;
         }
     }
     domObject.Locked = true;
 }