Пример #1
0
        public override bool Equals(Object o)
        {
            SEPX sepx = (SEPX)o;

            if (base.Equals(o))
            {
                return(sepx._sed.Equals(_sed));
            }
            return(false);
        }
Пример #2
0
        public void AdjustForInsert(int listIndex, int Length)
        {
            int  size = _sections.Count;
            SEPX sepx = _sections[listIndex];

            sepx.End = (sepx.End + Length);

            for (int x = listIndex + 1; x < size; x++)
            {
                sepx       = _sections[x];
                sepx.Start = (sepx.Start + Length);
                sepx.End   = (sepx.End + Length);
            }
        }
Пример #3
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());
        }
Пример #4
0
        public OldSectionTable(byte[] documentStream, int offset, int size)
        {
            PlexOfCps sedPlex = new PlexOfCps(documentStream, offset, size, 12);

            int length = sedPlex.Length;

            for (int x = 0; x < length; x++)
            {
                GenericPropertyNode node = sedPlex.GetProperty(x);
                SectionDescriptor   sed  = new SectionDescriptor(node.Bytes, 0);

                int fileOffset = sed.GetFc();
                int startAt    = node.Start;
                int endAt      = node.End;

                SEPX sepx;
                // check for the optimization
                if (fileOffset == unchecked ((int)0xffffffff))
                {
                    sepx = new SEPX(sed, startAt, endAt, new byte[0]);
                }
                else
                {
                    // The first short at the offset is the size of the grpprl.
                    int sepxSize = LittleEndian.GetShort(documentStream, fileOffset);
                    // Because we don't properly know about all the details of the old
                    //  section properties, and we're trying to decode them as if they
                    //  were the new ones, we sometimes "need" more data than we have.
                    // As a workaround, have a few extra 0 bytes on the end!
                    byte[] buf = new byte[sepxSize + 2];
                    fileOffset += LittleEndianConsts.SHORT_SIZE;
                    Array.Copy(documentStream, fileOffset, buf, 0, buf.Length >= documentStream.Length - fileOffset?documentStream.Length - fileOffset: buf.Length);
                    sepx = new SEPX(sed, startAt, endAt, buf);
                }
                _sections.Add(sepx);
            }

            _sections.Sort(PropertyNode.SEPXComparator.instance);
        }
Пример #5
0
        public OldSectionTable(byte[] documentStream, int offset, int size)
        {
            PlexOfCps sedPlex = new PlexOfCps(documentStream, offset, size, 12);

            int length = sedPlex.Length;

            for (int x = 0; x < length; x++)
            {
                GenericPropertyNode node = sedPlex.GetProperty(x);
                SectionDescriptor sed = new SectionDescriptor(node.Bytes, 0);

                int fileOffset = sed.GetFc();
                int startAt = node.Start;
                int endAt = node.End;

                SEPX sepx;
                // check for the optimization
                if (fileOffset == unchecked((int)0xffffffff))
                {
                    sepx = new SEPX(sed, startAt, endAt, new byte[0]);
                }
                else
                {
                    // The first short at the offset is the size of the grpprl.
                    int sepxSize = LittleEndian.GetShort(documentStream, fileOffset);
                    // Because we don't properly know about all the details of the old
                    //  section properties, and we're trying to decode them as if they
                    //  were the new ones, we sometimes "need" more data than we have.
                    // As a workaround, have a few extra 0 bytes on the end!
                    byte[] buf = new byte[sepxSize+2];
                    fileOffset += LittleEndianConsts.SHORT_SIZE;
                    Array.Copy(documentStream, fileOffset, buf, 0, buf.Length>=documentStream.Length - fileOffset?documentStream.Length - fileOffset: buf.Length);
                    sepx = new SEPX(sed, startAt, endAt,buf);
                }
                _sections.Add(sepx);
            }

            _sections.Sort(PropertyNode.SEPXComparator.instance);
        }
Пример #6
0
        public Section(SEPX sepx, Range parent)
            : base(Math.Max(parent._start, sepx.Start), Math.Min(parent._end, sepx.End), parent)
        {

            _props = sepx.GetSectionProperties();
        }
Пример #7
0
        public SectionTable(byte[] documentStream, byte[] tableStream, int OffSet,
                            int size, int fcMin,
                            TextPieceTable tpt, int mainLength)
        {
            PlexOfCps sedPlex = new PlexOfCps(tableStream, OffSet, size, SED_SIZE);

            this.tpt   = tpt;
            this._text = tpt.TextPieces;

            int length = sedPlex.Length;

            for (int x = 0; x < length; x++)
            {
                GenericPropertyNode node = sedPlex.GetProperty(x);
                SectionDescriptor   sed  = new SectionDescriptor(node.Bytes, 0);

                int fileOffset = sed.GetFc();
                //int startAt = CPtoFC(node.Start);
                //int endAt = CPtoFC(node.End);
                int startAt = node.Start;
                int endAt   = node.End;

                // check for the optimization
                if (fileOffset == unchecked ((int)0xffffffff))
                {
                    _sections.Add(new SEPX(sed, startAt, endAt, new byte[0]));
                }
                else
                {
                    // The first short at the offset is the size of the grpprl.
                    int    sepxSize = LittleEndian.GetShort(documentStream, fileOffset);
                    byte[] buf      = new byte[sepxSize];
                    fileOffset += LittleEndianConsts.SHORT_SIZE;
                    Array.Copy(documentStream, fileOffset, buf, 0, buf.Length);
                    _sections.Add(new SEPX(sed, startAt, endAt, buf));
                }
            }

            // Some files seem to lie about their unicode status, which
            //  is very very pesky. Try to work around these, but this
            //  is Getting on for black magic...
            int  mainEndsAt = mainLength;
            bool matchAt    = false;
            bool matchHalf  = false;

            for (int i = 0; i < _sections.Count; i++)
            {
                SEPX s = _sections[i];
                if (s.End == mainEndsAt)
                {
                    matchAt = true;
                }
                else if (s.End == mainEndsAt || s.End == mainEndsAt - 1)
                {
                    matchHalf = true;
                }
            }
            if (!matchAt && matchHalf)
            {
                //System.err.println("Your document seemed to be mostly unicode, but the section defInition was in bytes! Trying anyway, but things may well go wrong!");
                for (int i = 0; i < _sections.Count; i++)
                {
                    SEPX s = _sections[i];
                    GenericPropertyNode node = sedPlex.GetProperty(i);

                    int startAt = node.Start;
                    int endAt   = node.End;
                    s.Start = (startAt);
                    s.End   = (endAt);
                }
            }
        }