コード例 #1
0
        /**
         * Collapses the drawing records into an aggregate.
         */
        public static EscherAggregate CreateAggregate(IList records, int locFirstDrawingRecord, DrawingManager2 drawingManager)
        {
            // Keep track of any shape records Created so we can match them back to the object id's.
            // Textbox objects are also treated as shape objects.
            IList shapeRecords = new ArrayList();
            EscherRecordFactory recordFactory = new CustomEscherRecordFactory(ref shapeRecords);

            // Calculate the size of the buffer
            EscherAggregate agg      = new EscherAggregate(drawingManager);
            int             loc      = locFirstDrawingRecord;
            int             dataSize = 0;

            while (loc + 1 < records.Count &&
                   GetSid(records, loc) == DrawingRecord.sid &&
                   IsObjectRecord(records, loc + 1))
            {
                dataSize += ((DrawingRecord)records[loc]).Data.Length;
                loc      += 2;
            }

            // Create one big buffer
            byte[] buffer = new byte[dataSize];
            int    offset = 0;

            loc = locFirstDrawingRecord;
            while (loc + 1 < records.Count &&
                   GetSid(records, loc) == DrawingRecord.sid &&
                   IsObjectRecord(records, loc + 1))
            {
                DrawingRecord drawingRecord = (DrawingRecord)records[loc];
                Array.Copy(drawingRecord.Data, 0, buffer, offset, drawingRecord.Data.Length);
                offset += drawingRecord.Data.Length;
                loc    += 2;
            }

            // Decode the shapes
            //        agg.escherRecords = new ArrayList();
            int pos = 0;

            while (pos < dataSize)
            {
                EscherRecord r         = recordFactory.CreateRecord(buffer, pos);
                int          bytesRead = r.FillFields(buffer, pos, recordFactory);
                agg.AddEscherRecord(r);
                pos += bytesRead;
            }

            // Associate the object records with the shapes
            loc = locFirstDrawingRecord;
            int shapeIndex = 0;

            agg.shapeToObj = new Hashtable();
            while (loc + 1 < records.Count &&
                   GetSid(records, loc) == DrawingRecord.sid &&
                   IsObjectRecord(records, loc + 1))
            {
                Record objRecord = (Record)records[loc + 1];
                agg.shapeToObj[shapeRecords[shapeIndex++]] = objRecord;
                loc += 2;
            }

            return(agg);
        }
コード例 #2
0
        /**
         * Collapses the drawing records into an aggregate.
         */
        public static EscherAggregate CreateAggregate(IList records, int locFirstDrawingRecord, DrawingManager2 drawingManager)
        {
            // Keep track of any shape records Created so we can match them back to the object id's.
            // Textbox objects are also treated as shape objects.
            IList shapeRecords = new ArrayList();
            EscherRecordFactory recordFactory = new CustomEscherRecordFactory(ref shapeRecords);

            // Calculate the size of the buffer
            EscherAggregate agg = new EscherAggregate(drawingManager);
            int loc = locFirstDrawingRecord;
            int dataSize = 0;
            while (loc + 1 < records.Count
                    && GetSid(records, loc) == DrawingRecord.sid
                    && IsObjectRecord(records, loc + 1))
            {
                dataSize += ((DrawingRecord)records[loc]).Data.Length;
                loc += 2;
            }

            // Create one big buffer
            byte[] buffer = new byte[dataSize];
            int offset = 0;
            loc = locFirstDrawingRecord;
            while (loc + 1 < records.Count
                    && GetSid(records, loc) == DrawingRecord.sid
                    && IsObjectRecord(records, loc + 1))
            {
                DrawingRecord drawingRecord = (DrawingRecord)records[loc];
                Array.Copy(drawingRecord.Data, 0, buffer, offset, drawingRecord.Data.Length);
                offset += drawingRecord.Data.Length;
                loc += 2;
            }

            // Decode the shapes
            //        agg.escherRecords = new ArrayList();
            int pos = 0;
            while (pos < dataSize)
            {
                EscherRecord r = recordFactory.CreateRecord(buffer, pos);
                int bytesRead = r.FillFields(buffer, pos, recordFactory);
                agg.AddEscherRecord(r);
                pos += bytesRead;
            }

            // Associate the object records with the shapes
            loc = locFirstDrawingRecord;
            int shapeIndex = 0;
            agg.shapeToObj = new Hashtable();
            while (loc + 1 < records.Count
                    && GetSid(records, loc) == DrawingRecord.sid
                    && IsObjectRecord(records, loc + 1))
            {
                Record objRecord = (Record)records[loc + 1];
                agg.shapeToObj[shapeRecords[shapeIndex++]]= objRecord;
                loc += 2;
            }

            return agg;

        }
コード例 #3
0
 /// <summary>
 /// Creates the patriarch.
 /// </summary>
 /// <param name="sheet">the sheet this patriarch is stored in.</param>
 /// <param name="boundAggregate">The bound aggregate.</param>
 public HSSFPatriarch(HSSFSheet sheet, EscherAggregate boundAggregate)
 {
     this._boundAggregate = boundAggregate;
     this._sheet = sheet;
 }
コード例 #4
0
        /**
         * Finds the DrawingRecord for our sheet, and
         *  attaches it to the DrawingManager (which knows about
         *  the overall DrawingGroup for our workbook).
         * If requested, will Create a new DrawRecord
         *  if none currently exist
         * @param drawingManager The DrawingManager2 for our workbook
         * @param CreateIfMissing Should one be Created if missing?
         */
        public int AggregateDrawingRecords(DrawingManager2 drawingManager, bool CreateIfMissing)
        {
            int loc = FindFirstRecordLocBySid(DrawingRecord.sid);
            bool noDrawingRecordsFound = (loc == -1);
            if (noDrawingRecordsFound)
            {
                if (!CreateIfMissing)
                {
                    // None found, and not allowed to Add in
                    return -1;
                }

                EscherAggregate aggregate = new EscherAggregate(drawingManager);
                loc = FindFirstRecordLocBySid(EscherAggregate.sid);
                if (loc == -1)
                {
                    loc = FindFirstRecordLocBySid(WindowTwoRecord.sid);
                }
                else
                {
                    Records.RemoveAt(loc);
                }
                Records.Insert(loc, aggregate);
                return loc;
            }
            else
            {
                IList records = Records;
                EscherAggregate r = EscherAggregate.CreateAggregate(records, loc, drawingManager);
                int startloc = loc;
                while (loc + 1 < records.Count
                        && records[loc] is DrawingRecord
                        && (records[loc + 1] is ObjRecord ||
                            records[loc + 1] is TextObjectRecord)
                        )
                {
                    loc += 2;
                    if (records[loc] is NoteRecord) loc ++;
                }
                int endloc = loc - 1;
                for (int i = 0; i < (endloc - startloc + 1); i++)
                {
                    records.RemoveAt(startloc);
                }
                records.Insert(startloc, r);

                return startloc;
            }
        }