private int ParseElement(Input stream) { int data_remaining = (int)stream.Remaining; //Console.WriteLine ("stream.Remaining = {0}", data_remaining); // Weird!! Well, Its a M$ format ;-) // Fixes: 323312 byte [] data = stream.Read(data_remaining > 7 ? 8 : data_remaining); if (data == null || data_remaining < 8) { return(0); } RecordType.TypeCode opcode = (RecordType.TypeCode)GetInt16(data, 2); int length = (int)GetInt32(data, 4); // Protect against garbage length length = (length > 0 ? length : 0); RecordType type = RecordType.Find(opcode); // Process the container tree if (type.is_container) { int length_remaining = length; if (opcode == RecordType.TypeCode.MainMaster) { // Ignore MainMaster container as it contains // just a master-slide view and no user data. stream.Seek(length_remaining, SeekOrigin.Current); } else { while (length_remaining > 0) { int elem_length = ParseElement(stream); if (elem_length == 0) { return(0); } length_remaining -= elem_length; //Console.WriteLine ("ParseElement: length = {0}, rem = {1}", // elem_length, length_remaining); } } } else { if (length != 0) { System.Text.Encoding encoding = null; if (opcode == RecordType.TypeCode.TextBytesAtom) { //encoding = System.Text.Encoding.GetEncoding (28591); encoding = System.Text.Encoding.UTF8; } else if (opcode == RecordType.TypeCode.TextCharsAtom) { encoding = System.Text.Encoding.Unicode; } if (encoding != null && textType != TextType.NotUsed) { StringBuilder strData = new StringBuilder(); data = stream.Read(length); if (data == null) { return(0); } // Replace all ^M with "whitespace", // because of which the contents were not properly // been appended to the text pool. strData.Append(encoding.GetString(data).Replace('\r', ' ')); // Replace all ^K with "whitespace", // because of which the contents were not properly // been appended to the text pool. strData.Replace((char)0x0B, (char)0x20); if (textType == TextType.Title || textType == TextType.CenterBody || textType == TextType.CenterTitle) { HotUp(); } AppendText(strData.ToString()); if (IsHot) { HotDown(); } AppendStructuralBreak(); //Console.WriteLine ("Text : {0}", strData); } else if (opcode == RecordType.TypeCode.TextHeaderAtom) { data = stream.Read(4); textType = (TextType)GetInt32(data, 0); } else { stream.Seek(length, SeekOrigin.Current); } } } // length = RecordHeader.recLen // 8 = sizeof (RecordHeader) // Every Atom/container is preceded by a RecordHeader return(length + 8); }