Пример #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);
            }
        }
Пример #2
0
        /**
         * Get the string that's pointed to by the
         *  given plcfHdd index
         */
        private String GetAt(int plcfHddIndex)
        {
            if (plcfHdd == null)
            {
                return(null);
            }

            GenericPropertyNode prop = plcfHdd.GetProperty(plcfHddIndex);

            if (prop.Start == prop.End)
            {
                // Empty story
                return("");
            }
            if (prop.End < prop.Start)
            {
                // Broken properties?
                return("");
            }

            // Ensure we're Getting a sensible length
            String rawText = headerStories.Text;
            int    start   = Math.Min(prop.Start, rawText.Length);
            int    end     = Math.Min(prop.End, rawText.Length);

            // Grab the contents
            String text = rawText.Substring(start, end - start);

            // Strip off fields and macros if requested
            if (stripFields)
            {
                return(Range.StripFields(text));
            }
            // If you create a header/footer, then remove it again, word
            //  will leave \r\r. Turn these back into an empty string,
            //  which is more what you'd expect
            if (text.Equals("\r\r"))
            {
                return("");
            }

            return(text);
        }