/// <summary>
        /// Returns a list of all PAPX FCs between they given boundaries.
        /// </summary>
        /// <param name="fcMin">The lower boundary</param>
        /// <param name="fcMax">The upper boundary</param>
        /// <param name="fib">The FileInformationBlock</param>
        /// <param name="wordStream">The VirtualStream "WordStream"</param>
        /// <param name="tableStream">The VirtualStream "0Table" or "1Table"</param>
        /// <returns>The FCs</returns>
        public static List <Int32> GetFileCharacterPositions(
            Int32 fcMin,
            Int32 fcMax,
            FileInformationBlock fib,
            VirtualStream wordStream,
            VirtualStream tableStream,
            VirtualStream dataStream)
        {
            List <Int32> list = new List <Int32>();
            List <FormattedDiskPagePAPX> fkps = FormattedDiskPagePAPX.GetAllPAPXFKPs(fib, wordStream, tableStream, dataStream);

            for (int i = 0; i < fkps.Count; i++)
            {
                FormattedDiskPage fkp = fkps[i];

                //the last entry of each is always the same as the first entry of the next FKP
                //so, ignore all last _entries except for the last FKP.
                int max = fkp.rgfc.Length;
                if (i < fkps.Count - 1)
                {
                    max--;
                }

                for (int j = 0; j < max; j++)
                {
                    if (fkp.rgfc[j] >= fcMin && fkp.rgfc[j] < fcMax)
                    {
                        list.Add(fkp.rgfc[j]);
                    }
                }
            }

            return(list);
        }
        /// <summary>
        /// Returnes a list of all ParagraphPropertyExceptions which correspond to text
        /// between the given offsets.
        /// </summary>
        /// <param name="fcMin">The lower boundary</param>
        /// <param name="fcMax">The upper boundary</param>
        /// <param name="fib">The FileInformationBlock</param>
        /// <param name="wordStream">The VirtualStream "WordStream"</param>
        /// <param name="tableStream">The VirtualStream "0Table" or "1Table"</param>
        /// <returns>The FCs</returns>
        public static List <ParagraphPropertyExceptions> GetParagraphPropertyExceptions(
            Int32 fcMin,
            Int32 fcMax,
            FileInformationBlock fib,
            VirtualStream wordStream,
            VirtualStream tableStream,
            VirtualStream dataStream)
        {
            List <ParagraphPropertyExceptions> list = new List <ParagraphPropertyExceptions>();
            List <FormattedDiskPagePAPX>       fkps = FormattedDiskPagePAPX.GetAllPAPXFKPs(fib, wordStream, tableStream, dataStream);

            for (int i = 0; i < fkps.Count; i++)
            {
                FormattedDiskPagePAPX fkp = fkps[i];

                for (int j = 0; j < fkp.grppapx.Length; j++)
                {
                    if (fkp.rgfc[j] >= fcMin && fkp.rgfc[j] < fcMax)
                    {
                        list.Add(fkp.grppapx[j]);
                    }
                }
            }

            return(list);
        }
示例#3
0
        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.Fib1997Beta)
                {
                    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.Fib1997Beta)
                {
                    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);
            //
            this.UserVariables = new StwStructure(this.TableStream, this.FIB.fcStwUser, this.FIB.lcbStwUser);

            //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[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));
            }
        }