예제 #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
파일: PAPBinTable.cs 프로젝트: zzy092/npoi
        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
파일: SectionTable.cs 프로젝트: zzy092/npoi
        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());
        }
예제 #6
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();

        }
예제 #7
0
파일: NotesTables.cs 프로젝트: zzy092/npoi
 public NotesTables(NoteType noteType)
 {
     this.noteType = noteType;
     textPositions
     .AddProperty(new GenericPropertyNode(0, 1, new byte[0]));
 }
예제 #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());
        }