Пример #1
0
        public void TestWriteRead()
        {
            _plexOfCps = new PlexOfCps(4);

            int last = 0;
            for (int x = 0; x < 110; x++)
            {
                byte[] intHolder = new byte[4];
                int span = (int)(110.0f * (new Random((int)DateTime.Now.Ticks).Next(0,100)/100.0));
                LittleEndian.PutInt(intHolder, span);
                _plexOfCps.AddProperty(new GenericPropertyNode(last, last + span, intHolder));
                last += span;
            }

            byte[] output = _plexOfCps.ToByteArray();
            _plexOfCps = new PlexOfCps(output, 0, output.Length, 4);
            int len = _plexOfCps.Length;
            Assert.AreEqual(len, 110);

            last = 0;
            for (int x = 0; x < len; x++)
            {
                GenericPropertyNode node = _plexOfCps.GetProperty(x);
                Assert.AreEqual(node.Start, last);
                last = node.End;
                int span = LittleEndian.GetInt(node.Bytes);
                Assert.AreEqual(node.End - node.Start, span);
            }
        }
Пример #2
0
        public void TestWriteRead()
        {
            _plexOfCps = new PlexOfCps(4);

            int last = 0;

            for (int x = 0; x < 110; x++)
            {
                byte[] intHolder = new byte[4];
                int    span      = (int)(110.0f * (new Random((int)DateTime.Now.Ticks).Next(0, 100) / 100.0));
                LittleEndian.PutInt(intHolder, span);
                _plexOfCps.AddProperty(new GenericPropertyNode(last, last + span, intHolder));
                last += span;
            }

            byte[] output = _plexOfCps.ToByteArray();
            _plexOfCps = new PlexOfCps(output, 0, output.Length, 4);
            int len = _plexOfCps.Length;

            Assert.AreEqual(len, 110);

            last = 0;
            for (int x = 0; x < len; x++)
            {
                GenericPropertyNode node = _plexOfCps.GetProperty(x);
                Assert.AreEqual(node.Start, last);
                last = node.End;
                int span = LittleEndian.GetInt(node.Bytes);
                Assert.AreEqual(node.End - node.Start, span);
            }
        }
Пример #3
0
        public void WriteTo(HWPFFileSystem sys, int fcMin)
        {
            HWPFStream docStream   = sys.GetStream("WordDocument");
            Stream     tableStream = sys.GetStream("1Table");

            PlexOfCps binTable = new PlexOfCps(4);

            // each FKP must start on a 512 byte page.
            int docOffset = docStream.Offset;
            int mod       = docOffset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE;

            if (mod != 0)
            {
                byte[] pAdding = new byte[POIFSConstants.SMALLER_BIG_BLOCK_SIZE - mod];
                docStream.Write(pAdding);
            }

            // get the page number for the first fkp
            docOffset = docStream.Offset;
            int pageNum = docOffset / POIFSConstants.SMALLER_BIG_BLOCK_SIZE;

            // get the ending fc
            int endingFc = ((PropertyNode)_textRuns[_textRuns.Count - 1]).End;

            endingFc += fcMin;


            List <CHPX> overflow = _textRuns;

            do
            {
                PropertyNode startingProp = (PropertyNode)overflow[0];
                int          start        = startingProp.Start + fcMin;

                CHPFormattedDiskPage cfkp = new CHPFormattedDiskPage();
                cfkp.Fill(overflow);

                byte[] bufFkp = cfkp.ToArray(fcMin);
                docStream.Write(bufFkp);
                overflow = cfkp.GetOverflow();

                int end = endingFc;
                if (overflow != null)
                {
                    end = ((PropertyNode)overflow[0]).Start + fcMin;
                }

                byte[] intHolder = new byte[4];
                LittleEndian.PutInt(intHolder, pageNum++);
                binTable.AddProperty(new GenericPropertyNode(start, end, intHolder));
            }while (overflow != null);
            byte[] bytes = binTable.ToByteArray();
            tableStream.Write(bytes, 0, bytes.Length);
        }
Пример #4
0
        public void WriteTo(HWPFStream docStream,
                            HWPFStream tableStream, CharIndexTranslator translator)

        {
            PlexOfCps binTable = new PlexOfCps(4);

            // each FKP must start on a 512 byte page.
            int docOffset = docStream.Offset;
            int mod       = docOffset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE;

            if (mod != 0)
            {
                byte[] pAdding = new byte[POIFSConstants.SMALLER_BIG_BLOCK_SIZE - mod];
                docStream.Write(pAdding);
            }

            // get the page number for the first fkp
            docOffset = docStream.Offset;
            int pageNum = docOffset / POIFSConstants.SMALLER_BIG_BLOCK_SIZE;

            // get the ending fc
            int endingFc = ((PropertyNode)_paragraphs[_paragraphs.Count - 1]).End;


            List <PAPX> overflow = _paragraphs;

            do
            {
                PropertyNode startingProp = (PropertyNode)overflow[0];
                int          start        = translator.GetByteIndex(startingProp.Start);

                PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(_dataStream);
                pfkp.Fill(overflow);

                byte[] bufFkp = pfkp.ToByteArray(tableStream, translator);
                docStream.Write(bufFkp);
                overflow = pfkp.GetOverflow();

                int end = endingFc;
                if (overflow != null)
                {
                    end = translator.GetByteIndex(overflow[0].Start);
                }

                byte[] intHolder = new byte[4];
                LittleEndian.PutInt(intHolder, pageNum++);
                binTable.AddProperty(new GenericPropertyNode(start, end, intHolder));
            }while (overflow != null);
            byte[] bytes = binTable.ToByteArray();
            tableStream.Write(bytes, 0, bytes.Length);
        }
Пример #5
0
        public void WriteRef(FileInformationBlock fib, HWPFStream tableStream)
        {
            if (descriptors == null || descriptors.Length == 0)
            {
                fib.SetNotesDescriptorsOffset(noteType, tableStream.Offset);
                fib.SetNotesDescriptorsSize(noteType, 0);
                return;
            }

            int start = tableStream.Offset;

            byte[] data = descriptors.ToByteArray();
            tableStream.Write(data);
            int end = tableStream.Offset;

            fib.SetNotesDescriptorsOffset(noteType, start);
            fib.SetNotesDescriptorsSize(noteType, end - start);
        }
Пример #6
0
        public void WriteTxt(FileInformationBlock fib, HWPFStream tableStream)
        {
            if (textPositions == null || textPositions.Length == 0)
            {
                fib.SetNotesTextPositionsOffset(noteType, tableStream.Offset);
                fib.SetNotesTextPositionsSize(noteType, 0);
                return;
            }

            int start = tableStream.Offset;

            byte[] data = textPositions.ToByteArray();
            tableStream.Write(data);
            int end = tableStream.Offset;

            fib.SetNotesTextPositionsOffset(noteType, start);
            fib.SetNotesTextPositionsSize(noteType, end - start);
        }
Пример #7
0
        public void WritePlcfBkmkl(FileInformationBlock fib,
                                   HWPFStream tableStream)
        {
            if (descriptorsLim == null || descriptorsLim.Length == 0)
            {
                fib.SetFcPlcfbkl(0);
                fib.SetLcbPlcfbkl(0);
                return;
            }

            int start = tableStream.Offset;

            tableStream.Write(descriptorsLim.ToByteArray());
            int end = tableStream.Offset;

            fib.SetFcPlcfbkl(start);
            fib.SetLcbPlcfbkl(end - start);
        }
Пример #8
0
        public void WriteTo(HWPFFileSystem sys, int fcMin)
        {
            HWPFStream docStream   = sys.GetStream("WordDocument");
            HWPFStream tableStream = sys.GetStream("1Table");

            int       offset = docStream.Offset;
            int       len    = _sections.Count;
            PlexOfCps plex   = new PlexOfCps(SED_SIZE);

            for (int x = 0; x < len; x++)
            {
                SEPX   sepx   = _sections[x];
                byte[] grpprl = sepx.GetGrpprl();

                // write the sepx to the document stream. starts with a 2 byte size
                // followed by the grpprl
                byte[] shortBuf = new byte[2];
                LittleEndian.PutShort(shortBuf, (short)grpprl.Length);

                docStream.Write(shortBuf);
                docStream.Write(grpprl);

                // set the fc in the section descriptor
                SectionDescriptor sed = sepx.GetSectionDescriptor();
                sed.SetFc(offset);

                // add the section descriptor bytes to the PlexOfCps.


                // original line -
                //GenericPropertyNode property = new GenericPropertyNode(sepx.Start, sepx.End, sed.ToArray());

                // Line using Ryan's FCtoCP() conversion method -
                // unable to observe any effect on our testcases when using this code - piers
                GenericPropertyNode property = new GenericPropertyNode(tpt.GetCharIndex(sepx.StartBytes), tpt.GetCharIndex(sepx.EndBytes), sed.ToArray());


                plex.AddProperty(property);

                offset = docStream.Offset;
            }
            tableStream.Write(plex.ToByteArray());
        }
Пример #9
0
        private int SavePlex(FileInformationBlock fib, FieldsDocumentPart part,
                             PlexOfCps plexOfCps, HWPFStream outputStream)
        {
            if (plexOfCps == null || plexOfCps.Length == 0)
            {
                fib.SetFieldsPlcfOffset(part, outputStream.Offset);
                fib.SetFieldsPlcfLength(part, 0);
                return(0);
            }

            byte[] data = plexOfCps.ToByteArray();

            int start  = outputStream.Offset;
            int length = data.Length;

            outputStream.Write(data);

            fib.SetFieldsPlcfOffset(part, start);
            fib.SetFieldsPlcfLength(part, length);

            return(length);
        }
Пример #10
0
        public byte[] WriteTo(HWPFStream docStream)
        {

            PlexOfCps textPlex = new PlexOfCps(PieceDescriptor.SizeInBytes);
            // int fcMin = docStream.Getoffset();

            int size = _textPieces.Count;
            for (int x = 0; x < size; x++)
            {
                TextPiece next = _textPieces[x];
                PieceDescriptor pd = next.PieceDescriptor;

                int offset = docStream.Offset;
                int mod = (offset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE);
                if (mod != 0)
                {
                    mod = POIFSConstants.SMALLER_BIG_BLOCK_SIZE - mod;
                    byte[] buf = new byte[mod];
                    docStream.Write(buf);
                }

                // set the text piece position to the current docStream offset.
                pd.FilePosition = (docStream.Offset);

                // write the text to the docstream and save the piece descriptor to
                // the
                // plex which will be written later to the tableStream.
                docStream.Write(next.RawBytes);

                // The TextPiece is already in characters, which
                // Makes our life much easier
                int nodeStart = next.Start;
                int nodeEnd = next.End;
                textPlex.AddProperty(new GenericPropertyNode(nodeStart, nodeEnd, pd.ToByteArray()));
            }

            return textPlex.ToByteArray();

        }
Пример #11
0
        public void WriteTo(HWPFFileSystem sys, int fcMin)
        {
            HWPFStream docStream = sys.GetStream("WordDocument");
            HWPFStream tableStream = sys.GetStream("1Table");

            int offset = docStream.Offset;
            int len = _sections.Count;
            PlexOfCps plex = new PlexOfCps(SED_SIZE);

            for (int x = 0; x < len; x++)
            {
                SEPX sepx = _sections[x];
                byte[] grpprl = sepx.GetGrpprl();

                // write the sepx to the document stream. starts with a 2 byte size
                // followed by the grpprl
                byte[] shortBuf = new byte[2];
                LittleEndian.PutShort(shortBuf, (short)grpprl.Length);

                docStream.Write(shortBuf);
                docStream.Write(grpprl);

                // set the fc in the section descriptor
                SectionDescriptor sed = sepx.GetSectionDescriptor();
                sed.SetFc(offset);

                // add the section descriptor bytes to the PlexOfCps.


                // original line -
                //GenericPropertyNode property = new GenericPropertyNode(sepx.Start, sepx.End, sed.ToArray());

                // Line using Ryan's FCtoCP() conversion method -
                // unable to observe any effect on our testcases when using this code - piers
                GenericPropertyNode property = new GenericPropertyNode(tpt.GetCharIndex(sepx.StartBytes), tpt.GetCharIndex(sepx.EndBytes), sed.ToArray());


                plex.AddProperty(property);

                offset = docStream.Offset;
            }
            tableStream.Write(plex.ToByteArray());
        }
Пример #12
0
        private int SavePlex(FileInformationBlock fib, FieldsDocumentPart part,
                PlexOfCps plexOfCps, HWPFStream outputStream)
        {
            if (plexOfCps == null || plexOfCps.Length == 0)
            {
                fib.SetFieldsPlcfOffset(part, outputStream.Offset);
                fib.SetFieldsPlcfLength(part, 0);
                return 0;
            }

            byte[] data = plexOfCps.ToByteArray();

            int start = outputStream.Offset;
            int length = data.Length;

            outputStream.Write(data);

            fib.SetFieldsPlcfOffset(part, start);
            fib.SetFieldsPlcfLength(part, length);

            return length;
        }