Merge the recent changes from HEAD onto the branch
[beagle.git] / Filters / FilterPPT.cs
blobe5cea707fa749ae5c28a1d5c2ddde74c0ece949f
1 //
2 // FilterPPT.cs
3 //
4 // Copyright (C) 2004 Novell, Inc.
5 //
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
28 using System;
29 using System.Collections;
30 using System.IO;
31 using System.Text;
32 using Gsf;
34 using Beagle.Daemon;
35 using Beagle.Util;
37 internal class RecordType
40 public enum TypeCode {
41 Unknown = 0,
42 Document = 1000,
43 DocumentAtom = 1001,
44 EndDocument = 1002,
45 Slide = 1006,
46 SlideAtom = 1007,
47 Notes = 1008,
48 NotesAtom = 1009,
49 Environment = 1010,
50 SlidePersistAtom = 1011,
51 SSlideLayoutAtom = 1015,
52 MainMaster = 1016,
53 SSSlideInfoAtom = 1017,
54 SlideViewInfo = 1018,
55 GuideAtom = 1019,
56 ViewInfo = 1020,
57 ViewInfoAtom = 1021,
58 SlideViewInfoAtom = 1022,
59 VBAInfo = 1023,
60 VBAInfoAtom = 1024,
61 SSDocInfoAtom = 1025,
62 Summary = 1026,
63 DocRoutingSlip = 1030,
64 OutlineViewInfo = 1031,
65 SorterViewInfo = 1032,
66 ExObjList = 1033,
67 ExObjListAtom = 1034,
68 PPDrawingGroup = 1035, //FIXME: Office Art File Format Docu
69 PPDrawing = 1036, //FIXME: Office Art File Format Docu
70 NamedShows = 1040, // don't know if container
71 NamedShow = 1041,
72 NamedShowSlides = 1042, // don't know if container
73 List = 2000,
74 FontCollection = 2005,
75 BookmarkCollection = 2019,
76 SoundCollAtom = 2021,
77 Sound = 2022,
78 SoundData = 2023,
79 BookmarkSeedAtom = 2025,
80 ColorSchemeAtom = 2032,
81 ExObjRefAtom = 3009,
82 OEShapeAtom = 3009,
83 OEPlaceholderAtom = 3011,
84 GPointAtom = 3024,
85 GRatioAtom = 3031,
86 OutlineTextRefAtom = 3998,
87 TextHeaderAtom = 3999,
88 TextCharsAtom = 4000,
89 StyleTextPropAtom = 4001,
90 BaseTextPropAtom = 4002,
91 TxMasterStyleAtom = 4003,
92 TxCFStyleAtom = 4004,
93 TxPFStyleAtom = 4005,
94 TextRulerAtom = 4006,
95 TextBookmarkAtom = 4007,
96 TextBytesAtom = 4008,
97 TxSIStyleAtom = 4009,
98 TextSpecInfoAtom = 4010,
99 DefaultRulerAtom = 4011,
100 FontEntityAtom = 4023,
101 FontEmbeddedData = 4024,
102 CString = 4026,
103 MetaFile = 4033,
104 ExOleObjAtom = 4035,
105 SrKinsoku = 4040,
106 HandOut = 4041,
107 ExEmbed = 4044,
108 ExEmbedAtom = 4045,
109 ExLink = 4046,
110 BookmarkEntityAtom = 4048,
111 ExLinkAtom = 4049,
112 SrKinsokuAtom = 4050,
113 ExHyperlinkAtom = 4051,
114 ExHyperlink = 4055,
115 SlideNumberMCAtom = 4056,
116 HeadersFooters = 4057,
117 HeadersFootersAtom = 4058,
118 TxInteractiveInfoAtom = 4063,
119 CharFormatAtom = 4066,
120 ParaFormatAtom = 4067,
121 RecolorInfoAtom = 4071,
122 ExQuickTimeMovie = 4074,
123 ExQuickTimeMovieData = 4075,
124 ExControl = 4078,
125 SlideListWithText = 4080,
126 InteractiveInfo = 4082,
127 InteractiveInfoAtom = 4083,
128 UserEditAtom = 4085,
129 CurrentUserAtom = 4086,
130 DateTimeMCAtom = 4087,
131 GenericDateMCAtom = 4088,
132 FooterMCAtom = 4090,
133 ExControlAtom = 4091,
134 ExMediaAtom = 4100,
135 ExVideo = 4101,
136 ExAviMovie = 4102,
137 ExMCIMovie = 4103,
138 ExMIDIAudio = 4109,
139 ExCDAudio = 4110,
140 ExWAVAudioEmbedded = 4111,
141 ExWAVAudioLink = 4112,
142 ExOleObjStg = 4113,
143 ExCDAudioAtom = 4114,
144 ExWAVAudioEmbeddedAtom = 4115,
145 AnimationInfoAtom = 4116,
146 RTFDateTimeMCAtom = 4117,
147 ProgTags = 5000, // don't know if container
148 ProgStringTag = 5001,
149 ProgBinaryTag = 5002,
150 BinaryTagData = 5003,
151 PrintOptions = 6000,
152 PersistPtrFullBlock = 6001, // don't know if container
153 PersistPtrIncrementalBlock = 6002, // don't know if container
154 GScalingAtom = 10001,
155 GRColorAtom = 10002,
156 EscherDggContainer = 0xf000, /* Drawing Group Container */
157 EscherDgg = 0xf006,
158 EscherCLSID = 0xf016,
159 EscherOPT = 0xf00b,
160 EscherBStoreContainer = 0xf001,
161 EscherBSE = 0xf007,
162 EscherBlip_START = 0xf018, /* Blip types are between */
163 EscherBlip_END = 0xf117, /* these two values */
164 EscherDgContainer = 0xf002, /* Drawing Container */
165 EscherDg = 0xf008,
166 EscherRegroupItems = 0xf118,
167 EscherColorScheme = 0xf120, /* bug in docs */
168 EscherSpgrContainer = 0xf003,
169 EscherSpContainer = 0xf004,
170 EscherSpgr = 0xf009,
171 EscherSp = 0xf00a,
172 EscherTextbox = 0xf00c,
173 EscherClientTextbox = 0xf00d,
174 EscherAnchor = 0xf00e,
175 EscherChildAnchor = 0xf00f,
176 EscherClientAnchor = 0xf010,
177 EscherClientData = 0xf011,
178 EscherSolverContainer = 0xf005,
179 EscherConnectorRule = 0xf012, /* bug in docs */
180 EscherAlignRule = 0xf013,
181 EscherArcRule = 0xf014,
182 EscherClientRule = 0xf015,
183 EscherCalloutRule = 0xf017,
184 EscherSelection = 0xf119,
185 EscherColorMRU = 0xf11a,
186 EscherDeletedPspl = 0xf11d, /* bug in docs */
187 EscherSplitMenuColors = 0xf11e,
188 EscherOleObject = 0xf11f,
189 EscherUserDefined = 0xf122,
192 public TypeCode typecode;
193 public string name;
194 public bool is_container;
195 public bool do_read;
196 public int min_record_size;
197 public int max_record_size;
198 RecordType (TypeCode typecode, string name, bool is_container, bool do_read, int min_record_size, int max_record_size)
200 this.typecode = typecode;
201 this.name = name;
202 this.is_container = is_container;
203 this.do_read = do_read;
204 this.min_record_size = min_record_size;
205 this.max_record_size = max_record_size;
208 static RecordType[] types =
210 new RecordType ( TypeCode.Unknown, "Unknown", false, true, -1, -1 ),
211 new RecordType ( TypeCode.Document, "Document", true, true, -1, -1 ),
212 new RecordType ( TypeCode.DocumentAtom, "DocumentAtom", false, true, -1, -1 ),
213 new RecordType ( TypeCode.EndDocument, "EndDocument", false, true, -1, -1 ),
214 new RecordType ( TypeCode.Slide, "Slide", true, true, -1, -1 ),
215 new RecordType ( TypeCode.SlideAtom, "SlideAtom", false, true, -1, -1 ),
216 new RecordType ( TypeCode.Notes, "Notes", true, true, -1, -1 ),
217 new RecordType ( TypeCode.NotesAtom, "NotesAtom", false, true, -1, -1 ),
218 new RecordType ( TypeCode.Environment, "Environment", true, true, -1, -1 ),
219 new RecordType ( TypeCode.SlidePersistAtom, "SlidePersistAtom", false, true, -1, -1 ),
220 new RecordType ( TypeCode.SSlideLayoutAtom, "SSlideLayoutAtom", false, true, -1, -1 ),
221 new RecordType ( TypeCode.MainMaster, "MainMaster", true, true, -1, -1 ),
222 new RecordType ( TypeCode.SSSlideInfoAtom, "SSSlideInfoAtom", false, true, -1, -1 ),
223 new RecordType ( TypeCode.SlideViewInfo, "SlideViewInfo", true, true, -1, -1 ),
224 new RecordType ( TypeCode.GuideAtom, "GuideAtom", false, true, -1, -1 ),
225 new RecordType ( TypeCode.ViewInfo, "ViewInfo", true, true, -1, -1 ),
226 new RecordType ( TypeCode.ViewInfoAtom, "ViewInfoAtom", false, true, -1, -1 ),
227 new RecordType ( TypeCode.SlideViewInfoAtom, "SlideViewInfoAtom", false, true, -1, -1 ),
228 new RecordType ( TypeCode.VBAInfo, "VBAInfo", true, true, -1, -1 ),
229 new RecordType ( TypeCode.VBAInfoAtom, "VBAInfoAtom", false, true, -1, -1 ),
230 new RecordType ( TypeCode.SSDocInfoAtom, "SSDocInfoAtom", false, true, -1, -1 ),
231 new RecordType ( TypeCode.Summary, "Summary", true, true, -1, -1 ),
232 new RecordType ( TypeCode.DocRoutingSlip, "DocRoutingSlip", false, true, -1, -1 ),
233 new RecordType ( TypeCode.OutlineViewInfo, "OutlineViewInfo", true, true, -1, -1 ),
234 new RecordType ( TypeCode.SorterViewInfo, "SorterViewInfo", true, true, -1, -1 ),
235 new RecordType ( TypeCode.ExObjList, "ExObjList", true, true, -1, -1 ),
236 new RecordType ( TypeCode.ExObjListAtom, "ExObjListAtom", false, true, -1, -1 ),
237 new RecordType ( TypeCode.PPDrawingGroup, "PPDrawingGroup", true, true, -1, -1 ), //FIXME: Office Art File Format Docu
238 new RecordType ( TypeCode.PPDrawing, "PPDrawing", true, true, -1, -1 ), //FIXME: Office Art File Format Docu
239 new RecordType ( TypeCode.NamedShows, "NamedShows", false, true, -1, -1 ), // don't know if container
240 new RecordType ( TypeCode.NamedShow, "NamedShow", true, true, -1, -1 ),
241 new RecordType ( TypeCode.NamedShowSlides, "NamedShowSlides", false, true, -1, -1 ), // don't know if container
242 new RecordType ( TypeCode.List, "List", true, true, -1, -1 ),
243 new RecordType ( TypeCode.FontCollection, "FontCollection", true, true, -1, -1 ),
244 new RecordType ( TypeCode.BookmarkCollection, "BookmarkCollection", true, true, -1, -1 ),
245 new RecordType ( TypeCode.SoundCollAtom, "SoundCollAtom", false, true, -1, -1 ),
246 new RecordType ( TypeCode.Sound, "Sound", true, true, -1, -1 ),
247 new RecordType ( TypeCode.SoundData, "SoundData", false, true, -1, -1 ),
248 new RecordType ( TypeCode.BookmarkSeedAtom, "BookmarkSeedAtom", false, true, -1, -1 ),
249 new RecordType ( TypeCode.ColorSchemeAtom, "ColorSchemeAtom", false, true, -1, -1 ),
250 new RecordType ( TypeCode.ExObjRefAtom, "ExObjRefAtom", false, true, -1, -1 ),
251 new RecordType ( TypeCode.OEShapeAtom, "OEShapeAtom", false, true, -1, -1 ),
252 new RecordType ( TypeCode.OEPlaceholderAtom, "OEPlaceholderAtom", false, true, -1, -1 ),
253 new RecordType ( TypeCode.GPointAtom, "GPointAtom", false, true, -1, -1 ),
254 new RecordType ( TypeCode.GRatioAtom, "GRatioAtom", false, true, -1, -1 ),
255 new RecordType ( TypeCode.OutlineTextRefAtom, "OutlineTextRefAtom", false, true, -1, -1 ),
256 new RecordType ( TypeCode.TextHeaderAtom, "TextHeaderAtom", false, true, -1, -1 ),
257 new RecordType ( TypeCode.TextCharsAtom, "TextCharsAtom", false, true, -1, -1 ),
258 new RecordType ( TypeCode.StyleTextPropAtom, "StyleTextPropAtom", false, true, -1, -1 ),
259 new RecordType ( TypeCode.BaseTextPropAtom, "BaseTextPropAtom", false, true, -1, -1 ),
260 new RecordType ( TypeCode.TxMasterStyleAtom, "TxMasterStyleAtom", false, true, -1, -1 ),
261 new RecordType ( TypeCode.TxCFStyleAtom, "TxCFStyleAtom", false, true, -1, -1 ),
262 new RecordType ( TypeCode.TxPFStyleAtom, "TxPFStyleAtom", false, true, -1, -1 ),
263 new RecordType ( TypeCode.TextRulerAtom, "TextRulerAtom", false, true, -1, -1 ),
264 new RecordType ( TypeCode.TextBookmarkAtom, "TextBookmarkAtom", false, true, -1, -1 ),
265 new RecordType ( TypeCode.TextBytesAtom, "TextBytesAtom", false, true, -1, -1 ),
266 new RecordType ( TypeCode.TxSIStyleAtom, "TxSIStyleAtom", false, true, -1, -1 ),
267 new RecordType ( TypeCode.TextSpecInfoAtom, "TextSpecInfoAtom", false, true, -1, -1 ),
268 new RecordType ( TypeCode.DefaultRulerAtom, "DefaultRulerAtom", false, true, -1, -1 ),
269 new RecordType ( TypeCode.FontEntityAtom, "FontEntityAtom", false, true, -1, -1 ),
270 new RecordType ( TypeCode.FontEmbeddedData, "FontEmbeddedData", false, true, -1, -1 ),
271 new RecordType ( TypeCode.CString, "CString", false, true, -1, -1 ),
272 new RecordType ( TypeCode.MetaFile, "MetaFile", false, true, -1, -1 ),
273 new RecordType ( TypeCode.ExOleObjAtom, "ExOleObjAtom", false, true, -1, -1 ),
274 new RecordType ( TypeCode.SrKinsoku, "SrKinsoku", true, true, -1, -1 ),
275 new RecordType ( TypeCode.HandOut, "HandOut", true, true, -1, -1 ),
276 new RecordType ( TypeCode.ExEmbed, "ExEmbed", true, true, -1, -1 ),
277 new RecordType ( TypeCode.ExEmbedAtom, "ExEmbedAtom", false, true, -1, -1 ),
278 new RecordType ( TypeCode.ExLink, "ExLink", true, true, -1, -1 ),
279 new RecordType ( TypeCode.BookmarkEntityAtom, "BookmarkEntityAtom", false, true, -1, -1 ),
280 new RecordType ( TypeCode.ExLinkAtom, "ExLinkAtom", false, true, -1, -1 ),
281 new RecordType ( TypeCode.SrKinsokuAtom, "SrKinsokuAtom", false, true, -1, -1 ),
282 new RecordType ( TypeCode.ExHyperlinkAtom, "ExHyperlinkAtom", false, true, -1, -1 ),
283 new RecordType ( TypeCode.ExHyperlink, "ExHyperlink", true, true, -1, -1 ),
284 new RecordType ( TypeCode.SlideNumberMCAtom, "SlideNumberMCAtom", false, true, -1, -1 ),
285 new RecordType ( TypeCode.HeadersFooters, "HeadersFooters", true, true, -1, -1 ),
286 new RecordType ( TypeCode.HeadersFootersAtom, "HeadersFootersAtom", false, true, -1, -1 ),
287 new RecordType ( TypeCode.TxInteractiveInfoAtom, "TxInteractiveInfoAtom", false, true, -1, -1 ),
288 new RecordType ( TypeCode.CharFormatAtom, "CharFormatAtom", false, true, -1, -1 ),
289 new RecordType ( TypeCode.ParaFormatAtom, "ParaFormatAtom", false, true, -1, -1 ),
290 new RecordType ( TypeCode.RecolorInfoAtom, "RecolorInfoAtom", false, true, -1, -1 ),
291 new RecordType ( TypeCode.ExQuickTimeMovie, "ExQuickTimeMovie", true, true, -1, -1 ),
292 new RecordType ( TypeCode.ExQuickTimeMovieData, "ExQuickTimeMovieData", false, true, -1, -1 ),
293 new RecordType ( TypeCode.ExControl, "ExControl", true, true, -1, -1 ),
294 new RecordType ( TypeCode.SlideListWithText, "SlideListWithText", true, true, -1, -1 ),
295 new RecordType ( TypeCode.InteractiveInfo, "InteractiveInfo", true, true, -1, -1 ),
296 new RecordType ( TypeCode.InteractiveInfoAtom, "InteractiveInfoAtom", false, true, -1, -1 ),
297 new RecordType ( TypeCode.UserEditAtom, "UserEditAtom", false, true, -1, -1 ),
298 new RecordType ( TypeCode.CurrentUserAtom, "CurrentUserAtom", false, true, -1, -1 ),
299 new RecordType ( TypeCode.DateTimeMCAtom, "DateTimeMCAtom", false, true, -1, -1 ),
300 new RecordType ( TypeCode.GenericDateMCAtom, "GenericDateMCAtom", false, true, -1, -1 ),
301 new RecordType ( TypeCode.FooterMCAtom, "FooterMCAtom", false, true, -1, -1 ),
302 new RecordType ( TypeCode.ExControlAtom, "ExControlAtom", false, true, -1, -1 ),
303 new RecordType ( TypeCode.ExMediaAtom, "ExMediaAtom", false, true, -1, -1 ),
304 new RecordType ( TypeCode.ExVideo, "ExVideo", true, true, -1, -1 ),
305 new RecordType ( TypeCode.ExAviMovie, "ExAviMovie", true, true, -1, -1 ),
306 new RecordType ( TypeCode.ExMCIMovie, "ExMCIMovie", true, true, -1, -1 ),
307 new RecordType ( TypeCode.ExMIDIAudio, "ExMIDIAudio", true, true, -1, -1 ),
308 new RecordType ( TypeCode.ExCDAudio, "ExCDAudio", true, true, -1, -1 ),
309 new RecordType ( TypeCode.ExWAVAudioEmbedded, "ExWAVAudioEmbedded", true, true, -1, -1 ),
310 new RecordType ( TypeCode.ExWAVAudioLink, "ExWAVAudioLink", true, true, -1, -1 ),
311 new RecordType ( TypeCode.ExOleObjStg, "ExOleObjStg", false, true, -1, -1 ),
312 new RecordType ( TypeCode.ExCDAudioAtom, "ExCDAudioAtom", false, true, -1, -1 ),
313 new RecordType ( TypeCode.ExWAVAudioEmbeddedAtom, "ExWAVAudioEmbeddedAtom", false, true, -1, -1 ),
314 new RecordType ( TypeCode.AnimationInfoAtom, "AnimationInfoAtom", false, true, -1, -1 ),
315 new RecordType ( TypeCode.RTFDateTimeMCAtom, "RTFDateTimeMCAtom", false, true, -1, -1 ),
316 new RecordType ( TypeCode.ProgTags, "ProgTags", false, true, -1, -1 ), // don't know if container
317 new RecordType ( TypeCode.ProgStringTag, "ProgStringTag", true, true, -1, -1 ),
318 new RecordType ( TypeCode.ProgBinaryTag, "ProgBinaryTag", true, true, -1, -1 ),
319 new RecordType ( TypeCode.BinaryTagData, "BinaryTagData", false, true, -1, -1 ),
320 new RecordType ( TypeCode.PrintOptions, "PrintOptions", false, true, -1, -1 ),
321 new RecordType ( TypeCode.PersistPtrFullBlock, "PersistPtrFullBlock", false, true, -1, -1 ), // don't know if container
322 new RecordType ( TypeCode.PersistPtrIncrementalBlock, "PersistPtrIncrementalBlock", false, true, -1, -1 ),
323 new RecordType ( TypeCode.GScalingAtom, "GScalingAtom", false, true, -1, -1 ),
324 new RecordType ( TypeCode.GRColorAtom, "GRColorAtom", false, true, -1, -1 ),
326 new RecordType ( TypeCode.EscherDggContainer, "EscherDggContainer", true, true, -1, -1 ),
327 new RecordType ( TypeCode.EscherDgg, "EscherDgg", false, true, -1, -1 ),
328 new RecordType ( TypeCode.EscherCLSID, "EscherCLSID", false, true, -1, -1 ),
329 new RecordType ( TypeCode.EscherOPT, "EscherOPT", false, true, -1, -1 ),
330 new RecordType ( TypeCode.EscherBStoreContainer, "EscherBStoreContainer", true, true, -1, -1 ),
331 new RecordType ( TypeCode.EscherBSE, "EscherBSE", false, true, -1, -1 ),
332 new RecordType ( TypeCode.EscherBlip_START, "EscherBlip_START", false, true, -1, -1 ),
333 new RecordType ( TypeCode.EscherBlip_END, "EscherBlip_END", false, true, -1, -1 ),
334 new RecordType ( TypeCode.EscherDgContainer, "EscherDgContainer", true, true, -1, -1 ),
335 new RecordType ( TypeCode.EscherDg, "EscherDg", false, true, -1, -1 ),
336 new RecordType ( TypeCode.EscherRegroupItems, "EscherRegroupItems", false, true, -1, -1 ),
337 new RecordType ( TypeCode.EscherColorScheme, "EscherColorScheme", false, true, -1, -1 ),
338 new RecordType ( TypeCode.EscherSpgrContainer, "EscherSpgrContainer", true, true, -1, -1 ),
339 new RecordType ( TypeCode.EscherSpContainer, "EscherSpContainer", true, true, -1, -1 ),
340 new RecordType ( TypeCode.EscherSpgr, "EscherSpgr", false, true, -1, -1 ),
341 new RecordType ( TypeCode.EscherSp, "EscherSp", false, true, -1, -1 ),
342 new RecordType ( TypeCode.EscherTextbox, "EscherTextbox", false, true, -1, -1 ),
343 new RecordType ( TypeCode.EscherClientTextbox, "EscherClientTextbox", true, true, -1, -1 ),
344 new RecordType ( TypeCode.EscherAnchor, "EscherAnchor", false, true, -1, -1 ),
345 new RecordType ( TypeCode.EscherChildAnchor, "EscherChildAnchor", false, true, -1, -1 ),
346 new RecordType ( TypeCode.EscherClientAnchor, "EscherClientAnchor", false, true, -1, -1 ),
347 new RecordType ( TypeCode.EscherClientData, "EscherClientData", true, true, -1, -1 ),
348 new RecordType ( TypeCode.EscherSolverContainer, "EscherSolverContainer", true, true, -1, -1 ),
349 new RecordType ( TypeCode.EscherConnectorRule, "EscherConnectorRule", false, true, -1, -1 ),
350 new RecordType ( TypeCode.EscherAlignRule, "EscherAlignRule", false, true, -1, -1 ),
351 new RecordType ( TypeCode.EscherArcRule, "EscherArcRule", false, true, -1, -1 ),
352 new RecordType ( TypeCode.EscherClientRule, "EscherClientRule", false, true, -1, -1 ),
353 new RecordType ( TypeCode.EscherCalloutRule, "EscherCalloutRule", false, true, -1, -1 ),
354 new RecordType ( TypeCode.EscherSelection, "EscherSelection", false, true, -1, -1 ),
355 new RecordType ( TypeCode.EscherColorMRU, "EscherColorMRU", false, true, -1, -1 ),
356 new RecordType ( TypeCode.EscherDeletedPspl, "EscherDeletedPspl", false, true, -1, -1 ),
357 new RecordType ( TypeCode.EscherSplitMenuColors, "EscherSplitMenuColors", false, true, -1, -1 ),
358 new RecordType ( TypeCode.EscherOleObject, "EscherOleObject", false, true, -1, -1 ),
359 new RecordType ( TypeCode.EscherUserDefined, "EscherUserDefined", false, true, -1, -1 )
362 public static RecordType Find (TypeCode typecode)
364 for (int i = 0; i < types.Length; i++) {
365 if (types[i].typecode == typecode)
366 return types[i];
368 return types[0];
372 namespace Beagle.Filters {
374 public class FilterPPT : FilterOle {
376 private enum TextType {
377 Invalid = -1,
378 Title,
379 Body,
380 Notes,
381 NotUsed,
382 Other,
383 CenterBody,
384 CenterTitle,
385 HalfBody,
386 QuarterBody
389 TextType textType;
390 public FilterPPT ()
392 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("application/vnd.ms-powerpoint"));
393 textType = TextType.Invalid;
394 file = null;
395 FileName = null;
396 SnippetMode = true;
399 private int ParseElement (Input stream)
401 int data_remaining = (int) stream.Remaining;
402 //Console.WriteLine ("stream.Remaining = {0}", data_remaining);
404 // Weird!! Well, Its a M$ format ;-)
405 // Fixes: 323312
406 byte [] data = stream.Read (data_remaining > 7 ? 8 : data_remaining);
407 if (data == null || data_remaining < 8)
408 return 0;
410 RecordType.TypeCode opcode = (RecordType.TypeCode) GetInt16(data, 2);
411 int length = (int)GetInt32(data, 4);
412 // Protect against garbage length
413 length = (length > 0 ? length : 0);
414 RecordType type = RecordType.Find (opcode);
416 // Process the container tree
417 if (type.is_container) {
418 int length_remaining = length;
420 if (opcode == RecordType.TypeCode.MainMaster) {
421 // Ignore MainMaster container as it contains
422 // just a master-slide view and no user data.
423 stream.Seek (length_remaining, SeekOrigin.Current);
424 } else {
425 while (length_remaining > 0) {
426 int elem_length = ParseElement(stream);
427 if (elem_length == 0)
428 return 0;
429 length_remaining -= elem_length;
430 //Console.WriteLine ("ParseElement: length = {0}, rem = {1}",
431 // elem_length, length_remaining);
434 } else {
435 if (length != 0) {
436 System.Text.Encoding encoding = null;
438 if (opcode == RecordType.TypeCode.TextBytesAtom) {
439 //encoding = System.Text.Encoding.GetEncoding (28591);
440 encoding = System.Text.Encoding.UTF8;
441 } else if (opcode == RecordType.TypeCode.TextCharsAtom) {
442 encoding = System.Text.Encoding.Unicode;
445 if (encoding != null && textType != TextType.NotUsed) {
446 StringBuilder strData = new StringBuilder () ;
447 data = stream.Read(length);
448 if (data == null)
449 return 0;
450 // Replace all ^M with "whitespace",
451 // because of which the contents were not properly
452 // been appended to the text pool.
453 strData.Append (encoding.GetString (data).Replace ('\r', ' '));
455 // Replace all ^K with "whitespace",
456 // because of which the contents were not properly
457 // been appended to the text pool.
458 strData.Replace ((char)0x0B, (char)0x20);
460 if (textType == TextType.Title ||
461 textType == TextType.CenterBody ||
462 textType == TextType.CenterTitle)
463 HotUp ();
464 AppendText (strData.ToString());
465 if (IsHot)
466 HotDown ();
467 else
468 AppendStructuralBreak ();
469 //Console.WriteLine ("Text : {0}", strData);
470 } else if (opcode == RecordType.TypeCode.TextHeaderAtom) {
471 data = stream.Read (4);
472 textType = (TextType) GetInt32 (data, 0);
473 } else {
474 stream.Seek(length, SeekOrigin.Current);
479 // length = RecordHeader.recLen
480 // 8 = sizeof (RecordHeader)
481 // Every Atom/container is preceded by a RecordHeader
482 return length + 8;
486 override protected void ExtractMetaData (Input sumStream, Input docSumStream)
488 int slide_count = 0;
489 DocProp prop = null;
491 if (docSumMeta != null) {
492 prop = docSumMeta.Lookup ("gsf:slide-count");
493 if (prop != null)
494 slide_count = (int) prop.Val;
495 if (slide_count > 0)
496 AddProperty (Beagle.Property.NewUnsearched ("fixme:slide-count", slide_count));
500 override protected void DoPull ()
502 if (file == null) {
503 Finished ();
504 return;
507 Input stream = null;
508 try {
509 stream = file.ChildByName ("PowerPoint Document");
511 if (stream != null) {
513 // The parsing was getting terminated when "EndDocument"
514 // container was parsed. We need to continue our
515 // parsing till the end of the file, since, some of the
516 // slides do persist after the actual "Document"
517 // container.
518 // PPTs exported from OO.o actually writes almost all the slides
519 // after "Document" container.
520 // And certain PPTs do have some slides in after
521 // "Document" container.
522 //Console.WriteLine ("Length of stream = {0}", stream.Size);
523 int ret = -1;
524 while (!stream.Eof && ret != 0) {
525 ret = ParseElement (stream);
526 //Console.WriteLine ("Position of the ptr in the stream: {0}", stream.Position);
529 stream.Dispose ();
530 } else {
531 Logger.Log.Error ("Ole stream not found in {0}. Content extraction skipped.", FileName);
534 Finished ();
535 } catch (Exception e) {
536 Logger.Log.Error ("Exception {0} occurred during DoPull.", e.Message);
537 Error ();
541 override protected void OpenStorage (FileInfo info)
543 FileName = info.FullName;
545 // PPT 95/97-2000 format contains a "PP97_DUALSTORAGE", which is required
546 // to index PPT 97-2000 files.
547 // We don't support PPT 95 files, however, we happily accept patches ;-)
549 Input temp_input = null;
550 try {
551 temp_input = file.ChildByName ("PP97_DUALSTORAGE");
553 if (temp_input != null) {
554 // "PP97_DUALSTORAGE" is a storage containing some streams
555 if (temp_input.Handle != IntPtr.Zero) {
556 file.Dispose ();
557 file = (Gsf.Infile) GLib.Object.GetObject (temp_input.Handle);
559 } else {
560 using (temp_input = file.ChildByName ("Header")) {
561 using (Input temp_input2 = file.ChildByName ("PowerPoint Document")) {
562 if (temp_input != null || temp_input2 == null) {
563 Log.Error ("{0} is an unsupported PPT 95/4.0 file. Skipping", FileName);
564 Error ();
565 return;
571 using (temp_input = file.ChildByName ("EncryptedSummary")) {
572 if (temp_input != null) {
573 Log.Warn ("{0} is a password-protected PowerPoint file. Skipping.", FileName);
574 Error ();
578 } catch (Exception) {
580 Logger.Log.Error ("Unable to open OleFile stream of "+info.FullName);
581 Error ();