/// <summary> /// Returns a list of all CHPX which are valid for the given FCs. /// </summary> /// <param name="fcMin">The lower boundary</param> /// <param name="fcMax">The upper boundary</param> /// <returns>The FCs</returns> public List <Int32> GetFileCharacterPositions(Int32 fcMin, Int32 fcMax) { List <Int32> list = new List <Int32>(); for (int i = 0; i < this.AllChpxFkps.Count; i++) { FormattedDiskPageCHPX fkp = this.AllChpxFkps[i]; //if the last fc of this fkp is smaller the fcMin //this fkp is before the requested range if (fkp.rgfc[fkp.rgfc.Length - 1] < fcMin) { continue; } //if the first fc of this fkp is larger the Max //this fkp is beyond the requested range if (fkp.rgfc[0] > fcMax) { break; } //don't add the duplicated values of the FKP boundaries (Length-1) int max = fkp.rgfc.Length - 1; //last fkp? //use full table if (i == (this.AllChpxFkps.Count - 1)) { max = fkp.rgfc.Length; } for (int j = 0; j < max; j++) { if (fkp.rgfc[j] < fcMin && fkp.rgfc[j + 1] > fcMin) { //this chpx starts before fcMin list.Add(fkp.rgfc[j]); } else if (fkp.rgfc[j] >= fcMin && fkp.rgfc[j] < fcMax) { //this chpx is in the range list.Add(fkp.rgfc[j]); } } } return(list); }
private void parse(StructuredStorageReader reader, Int32 fibFC) { this.Storage = reader; this.WordDocumentStream = reader.GetStream("WordDocument"); //parse FIB this.WordDocumentStream.Seek(fibFC, System.IO.SeekOrigin.Begin); this.FIB = new FileInformationBlock(new VirtualStreamReader(this.WordDocumentStream)); //check the file version if ((int)FIB.nFib != 0) { if (this.FIB.nFib < FileInformationBlock.FibVersion.Fib1997) { throw new ByteParseException("Could not parse the file because it was created by an unsupported application (Word 95 or older)."); } } else { if (this.FIB.nFibNew < FileInformationBlock.FibVersion.Fib1997) { throw new ByteParseException("Could not parse the file because it was created by an unsupported application (Word 95 or older)."); } } //get the streams if (this.FIB.fWhichTblStm) { this.TableStream = reader.GetStream("1Table"); } else { this.TableStream = reader.GetStream("0Table"); } try { this.DataStream = reader.GetStream("Data"); } catch (StreamNotFoundException) { this.DataStream = null; } //Read all needed STTBs this.RevisionAuthorTable = new StringTable(typeof(String), this.TableStream, this.FIB.fcSttbfRMark, this.FIB.lcbSttbfRMark); this.FontTable = new StringTable(typeof(FontFamilyName), this.TableStream, this.FIB.fcSttbfFfn, this.FIB.lcbSttbfFfn); this.BookmarkNames = new StringTable(typeof(String), this.TableStream, this.FIB.fcSttbfBkmk, this.FIB.lcbSttbfBkmk); this.AutoTextNames = new StringTable(typeof(String), this.TableStream, this.FIB.fcSttbfGlsy, this.FIB.lcbSttbfGlsy); //this.ProtectionUsers = new StringTable(typeof(String), this.TableStream, this.FIB.fcSttbProtUser, this.FIB.lcbSttbProtUser); //Read all needed PLCFs this.AnnotationsReferencePlex = new Plex <AnnotationReferenceDescriptor>(30, this.TableStream, this.FIB.fcPlcfandRef, this.FIB.lcbPlcfandRef); this.TextboxBreakPlex = new Plex <BreakDescriptor>(6, this.TableStream, this.FIB.fcPlcfTxbxBkd, this.FIB.lcbPlcfTxbxBkd); this.TextboxBreakPlexHeader = new Plex <BreakDescriptor>(6, this.TableStream, this.FIB.fcPlcfTxbxHdrBkd, this.FIB.lcbPlcfTxbxHdrBkd); this.OfficeDrawingPlex = new Plex <FileShapeAddress>(26, this.TableStream, this.FIB.fcPlcSpaMom, this.FIB.lcbPlcSpaMom); this.OfficeDrawingPlexHeader = new Plex <FileShapeAddress>(26, this.TableStream, this.FIB.fcPlcSpaHdr, this.FIB.lcbPlcSpaHdr); this.SectionPlex = new Plex <SectionDescriptor>(12, this.TableStream, this.FIB.fcPlcfSed, this.FIB.lcbPlcfSed); this.BookmarkStartPlex = new Plex <BookmarkFirst>(4, this.TableStream, this.FIB.fcPlcfBkf, this.FIB.lcbPlcfBkf); this.EndnoteReferencePlex = new Plex <Int16>(2, this.TableStream, this.FIB.fcPlcfendRef, this.FIB.lcbPlcfendRef); this.FootnoteReferencePlex = new Plex <Int16>(2, this.TableStream, this.FIB.fcPlcffndRef, this.FIB.lcbPlcffndRef); // PLCFs without types this.BookmarkEndPlex = new Plex <Exception>(0, this.TableStream, this.FIB.fcPlcfBkl, this.FIB.lcbPlcfBkl); this.AutoTextPlex = new Plex <Exception>(0, this.TableStream, this.FIB.fcPlcfGlsy, this.FIB.lcbPlcfGlsy); //read the FKPs this.AllPapxFkps = FormattedDiskPagePAPX.GetAllPAPXFKPs(this.FIB, this.WordDocumentStream, this.TableStream, this.DataStream); this.AllChpxFkps = FormattedDiskPageCHPX.GetAllCHPXFKPs(this.FIB, this.WordDocumentStream, this.TableStream); //read custom tables this.DocumentProperties = new DocumentProperties(this.FIB, this.TableStream); this.Styles = new StyleSheet(this.FIB, this.TableStream, this.DataStream); this.ListTable = new ListTable(this.FIB, this.TableStream); this.ListFormatOverrideTable = new ListFormatOverrideTable(this.FIB, this.TableStream); this.OfficeArtContent = new OfficeArtContent(this.FIB, this.TableStream); this.HeaderAndFooterTable = new HeaderAndFooterTable(this); this.AnnotationReferenceExtraTable = new AnnotationReferenceExtraTable(this.FIB, this.TableStream); this.CommandTable = new CommandTable(this.FIB, this.TableStream); this.AnnotationOwners = new AnnotationOwnerList(this.FIB, this.TableStream); //parse the piece table and construct a list that contains all chars this.PieceTable = new PieceTable(this.FIB, this.TableStream); this.Text = this.PieceTable.GetAllChars(this.WordDocumentStream); //build a dictionaries of all PAPX this.AllPapx = new Dictionary <Int32, ParagraphPropertyExceptions>(); for (int i = 0; i < this.AllPapxFkps.Count; i++) { for (int j = 0; j < this.AllPapxFkps[i].grppapx.Length; j++) { this.AllPapx.Add(this.AllPapxFkps[i].rgfc[j], this.AllPapxFkps[i].grppapx[j]); } } //build a dictionary of all SEPX this.AllSepx = new Dictionary <Int32, SectionPropertyExceptions>(); for (int i = 0; i < this.SectionPlex.Elements.Count; i++) { //Read the SED SectionDescriptor sed = (SectionDescriptor)this.SectionPlex.Elements[i]; Int32 cp = this.SectionPlex.CharacterPositions[i + 1]; //Get the SEPX VirtualStreamReader wordReader = new VirtualStreamReader(this.WordDocumentStream); this.WordDocumentStream.Seek(sed.fcSepx, System.IO.SeekOrigin.Begin); Int16 cbSepx = wordReader.ReadInt16(); SectionPropertyExceptions sepx = new SectionPropertyExceptions(wordReader.ReadBytes(cbSepx - 2)); this.AllSepx.Add(cp, sepx); } //read the Glossary if (this.FIB.pnNext > 0) { this.Glossary = new WordDocument(this.Storage, (int)(this.FIB.pnNext * 512)); } }