Exemple #1
0
        public void TestReadWrite()
        {
            FileInformationBlock fib = _hWPFDocFixture._fib;

            byte[] mainStream  = _hWPFDocFixture._mainStream;
            byte[] tableStream = _hWPFDocFixture._tableStream;
            int    fcMin       = fib.GetFcMin();

            CPSplitCalculator cps = new CPSplitCalculator(fib);

            ComplexFileTable cft = new ComplexFileTable(mainStream, tableStream, fib.GetFcClx(), fcMin);
            TextPieceTable   tpt = cft.GetTextPieceTable();

            SectionTable sectionTable = new SectionTable(mainStream, tableStream,
                                                         fib.GetFcPlcfsed(),
                                                         fib.GetLcbPlcfsed(),
                                                         fcMin, tpt, cps);
            HWPFFileSystem fileSys = new HWPFFileSystem();

            sectionTable.WriteTo(fileSys, 0);
            MemoryStream tableOut = fileSys.GetStream("1Table");
            MemoryStream mainOut  = fileSys.GetStream("WordDocument");

            byte[] newTableStream = tableOut.ToArray();
            byte[] newMainStream  = mainOut.ToArray();

            SectionTable newSectionTable = new SectionTable(
                newMainStream, newTableStream, 0,
                newTableStream.Length, 0, tpt, cps);

            List <SEPX> oldSections = sectionTable.GetSections();
            List <SEPX> newSections = newSectionTable.GetSections();

            Assert.AreEqual(oldSections.Count, newSections.Count);

            //test for proper char offset conversions
            PlexOfCps oldSedPlex = new PlexOfCps(tableStream, fib.GetFcPlcfsed(),
                                                 fib.GetLcbPlcfsed(), 12);
            PlexOfCps newSedPlex = new PlexOfCps(newTableStream, 0,
                                                 newTableStream.Length, 12);

            Assert.AreEqual(oldSedPlex.Length, newSedPlex.Length);

            for (int x = 0; x < oldSedPlex.Length; x++)
            {
                Assert.AreEqual(oldSedPlex.GetProperty(x).Start, newSedPlex.GetProperty(x).Start);
                Assert.AreEqual(oldSedPlex.GetProperty(x).End, newSedPlex.GetProperty(x).End);
            }

            int size = oldSections.Count;

            for (int x = 0; x < size; x++)
            {
                PropertyNode oldNode = (PropertyNode)oldSections[x];
                PropertyNode newNode = (PropertyNode)newSections[x];
                Assert.AreEqual(oldNode, newNode);
            }
        }
Exemple #2
0
        public HeaderStories(HWPFDocument doc)
        {
            this.headerStories = doc.GetHeaderStoryRange();
            FileInformationBlock fib = doc.GetFileInformationBlock();

            // If there's no PlcfHdd, nothing to do
            if (fib.GetCcpHdd() == 0)
            {
                return;
            }
            if (fib.GetPlcfHddSize() == 0)
            {
                return;
            }

            // Handle the PlcfHdd
            plcfHdd = new PlexOfCps(
                doc.GetTableStream(), fib.GetPlcfHddOffset(),
                fib.GetPlcfHddSize(), 0
                );
        }