public void AddChild(PowerPointRecord entry) { if (this._children == null) { this._children = new List <PowerPointRecord>(); } this._children.Add(entry); }
private PowerPointRecord GetRecord(PowerPointRecord parent) { if (this._contentStream.Position + 8 >= this._contentStream.Length) { return(null); } UInt16 version = this._contentReader.ReadUInt16(); UInt16 type = this._contentReader.ReadUInt16(); UInt32 length = this._contentReader.ReadUInt32(); return(new PowerPointRecord(parent, version, type, length, this._contentStream.Position)); }
/// <summary> /// 初始化新的Record /// </summary> /// <param name="parent">父节点</param> /// <param name="version">RecordVersion和Instance</param> /// <param name="type">Record类型</param> /// <param name="length">Record内容大小</param> /// <param name="offset">Record相对PowerPoint Document偏移</param> public PowerPointRecord(PowerPointRecord parent, UInt16 version, UInt16 type, UInt32 length, Int64 offset) { this._recVer = (UInt16)(version & 0xF); this._recInstance = (UInt16)(version & 0xFFF0); this._recType = (RecordType)type; this._recLen = length; this._offset = offset; this._deepth = (parent == null ? 0 : parent._deepth + 1); this._parent = parent; if (_recVer == 0xF) { this._children = new List <PowerPointRecord>(); } }
protected override void ReadContent() { DirectoryEntry entry = this._dirRootEntry.GetChild("PowerPoint Document"); if (entry == null) { return; } try { this._contentStream = new MemoryStream(this._entryData[entry.EntryID]); this._contentReader = new BinaryReader(this._contentStream); #region 测试方法 this._recordTree = new StringBuilder(); #endregion this._allText = new StringBuilder(); this._records = new List <PowerPointRecord>(); PowerPointRecord record = null; while (this._contentStream.Position < this._contentStream.Length) { record = this.ReadRecord(null); if (record == null || record.RecordType == 0) { break; } } this._allText = new StringBuilder(StringHelper.ReplaceString(this._allText.ToString())); } finally { if (this._contentReader != null) { this._contentReader.Close(); } if (this._contentStream != null) { this._contentStream.Close(); } } }
private PowerPointRecord ReadRecord(PowerPointRecord parent) { PowerPointRecord record = GetRecord(parent); if (record == null) { return(null); } #region 测试方法 else { this._recordTree.Append('-', record.Deepth * 2); this._recordTree.AppendFormat("[{0}]-[{1}]-[Len:{2}]", record.RecordType, record.Deepth, record.RecordLength); this._recordTree.AppendLine(); } #endregion if (parent == null) { this._records.Add(record); } else { parent.AddChild(record); } if (record.RecordVersion == 0xF) { while (this._contentStream.Position < record.Offset + record.RecordLength) { this.ReadRecord(record); } } else { if (record.Parent != null && ( record.Parent.RecordType == RecordType.ListWithTextContainer || record.Parent.RecordType == RecordType.HeadersFootersContainer || (UInt32)record.Parent.RecordType == 0xF00D)) { if (record.RecordType == RecordType.TextCharsAtom || record.RecordType == RecordType.CString)//找到Unicode双字节文字内容 { Byte[] data = this._contentReader.ReadBytes((Int32)record.RecordLength); this._allText.Append(StringHelper.GetString(true, data)); this._allText.AppendLine(); } else if (record.RecordType == RecordType.TextBytesAtom)//找到Unicode<256单字节文字内容 { Byte[] data = this._contentReader.ReadBytes((Int32)record.RecordLength); this._allText.Append(StringHelper.GetString(false, data)); this._allText.AppendLine(); } else { this._contentStream.Seek(record.RecordLength, SeekOrigin.Current); } } else { if (this._contentStream.Position + record.RecordLength < this._contentStream.Length) { this._contentStream.Seek(record.RecordLength, SeekOrigin.Current); } else { this._contentStream.Seek(0, SeekOrigin.End); } } } return(record); }