public override int Serialize(int offset, byte [] data)
        {
            LittleEndian.PutShort(data, 0 + offset, Sid);
            LittleEndian.PutShort(data, 2 + offset, (short)(RecordSize - 4));
            if (escherRecords.Count == 0 && rawData != null)
            {
                LittleEndian.PutShort(data, 0 + offset, Sid);
                LittleEndian.PutShort(data, 2 + offset, (short)(RecordSize - 4));
                Array.Copy(rawData, 0, data, 4 + offset, rawData.Length);
                return(rawData.Length + 4);
            }
            else
            {
                LittleEndian.PutShort(data, 0 + offset, Sid);
                LittleEndian.PutShort(data, 2 + offset, (short)(RecordSize - 4));

                int pos = offset + 4;
                for (IEnumerator iterator = escherRecords.GetEnumerator(); iterator.MoveNext();)
                {
                    EscherRecord r = (EscherRecord)iterator.Current;
                    pos += r.Serialize(pos, data);
                }
            }
            return(RecordSize);
        }
示例#2
0
        public override byte[] GetBytes()
        {
            EscherRecord record = (EscherRecord)this.Record;

            byte[] bytes = new byte[record.RecordSize];
            record.Serialize(0, bytes);
            return(bytes);
        }
示例#3
0
        public override int Serialize(int offset, byte [] data)
        {
            byte[] rawData = RawData;
            if (EscherRecords.Count == 0 && rawData != null)
            {
                return(WriteData(offset, data, rawData));
            }
            else
            {
                byte[] buffer = new byte[RawDataSize];
                int    pos    = 0;
                for (IEnumerator iterator = EscherRecords.GetEnumerator(); iterator.MoveNext();)
                {
                    EscherRecord r = (EscherRecord)iterator.Current;
                    pos += r.Serialize(pos, buffer, new NullEscherSerializationListener());
                }

                return(WriteData(offset, data, buffer));
            }
        }
示例#4
0
 /**
  * Search for EscherClientDataRecord, if found, convert its contents into an array of HSLF records
  *
  * @return an array of HSLF records Contained in the shape's EscherClientDataRecord or <code>null</code>
  */
 protected Record[] GetClientRecords()
 {
     if (_clientData == null)
     {
         EscherRecord r = Shape.GetEscherChild(GetSpContainer(), EscherClientDataRecord.RECORD_ID);
         //ddf can return EscherContainerRecord with recordId=EscherClientDataRecord.RECORD_ID
         //convert in to EscherClientDataRecord on the fly
         if (r != null && !(r is EscherClientDataRecord))
         {
             byte[] data = r.Serialize();
             r = new EscherClientDataRecord();
             r.FillFields(data, 0, new DefaultEscherRecordFactory());
         }
         _clientData = (EscherClientDataRecord)r;
     }
     if (_clientData != null && _clientRecords == null)
     {
         byte[] data = _clientData.GetRemainingData();
         _clientRecords = Record.FindChildRecords(data, 0, data.Length);
     }
     return(_clientRecords);
 }
        /**
         * Serializes this aggregate to a byte array.  Since this Is an aggregate
         * record it will effectively Serialize the aggregated records.
         *
         * @param offset    The offset into the start of the array.
         * @param data      The byte array to Serialize to.
         * @return          The number of bytes Serialized.
         */
        public override int Serialize(int offset, byte [] data)
        {
            ConvertUserModelToRecords();

            // Determine buffer size
            IList records = EscherRecords;
            int   size    = GetEscherRecordSize(records);

            byte[] buffer = new byte[size];


            // Serialize escher records into one big data structure and keep note of ending offsets.
            spEndingOffsets = new ArrayList();
            shapes          = new ArrayList();
            int pos = 0;

            for (IEnumerator iterator = records.GetEnumerator(); iterator.MoveNext();)
            {
                EscherRecord e = (EscherRecord)iterator.Current;
                pos += e.Serialize(pos, buffer, new SerializationListener(ref spEndingOffsets, ref shapes));
            }
            // todo: fix this
            shapes.Insert(0, null);
            spEndingOffsets.Insert(0, null);

            // Split escher records into Separate MSODRAWING and OBJ, TXO records.  (We don't break on
            // the first one because it's the patriach).
            pos = offset;
            for (int i = 1; i < shapes.Count; i++)
            {
                int endOffset = (int)spEndingOffsets[i] - 1;
                int startOffset;
                if (i == 1)
                {
                    startOffset = 0;
                }
                else
                {
                    startOffset = (int)spEndingOffsets[i - 1];
                }

                // Create and Write a new MSODRAWING record
                DrawingRecord drawing     = new DrawingRecord();
                byte[]        drawingData = new byte[endOffset - startOffset + 1];
                Array.Copy(buffer, startOffset, drawingData, 0, drawingData.Length);
                drawing.Data = drawingData;
                int temp = drawing.Serialize(pos, data);
                pos += temp;

                // Write the matching OBJ record
                Record obj = (Record)shapeToObj[shapes[i]];
                temp = obj.Serialize(pos, data);
                pos += temp;
            }

            // Write records that need to be Serialized after all drawing Group records
            for (int i = 0; i < tailRec.Count; i++)
            {
                Record rec = (Record)tailRec[i];
                pos += rec.Serialize(pos, data);
            }

            int bytesWritten = pos - offset;

            if (bytesWritten != RecordSize)
            {
                throw new RecordFormatException(bytesWritten + " bytes written but RecordSize reports " + RecordSize);
            }
            return(bytesWritten);
        }