/** * 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); }
/** * Collapses the drawing records into an aggregate. * read Drawing, Obj, TxtObj, Note and Continue records into single byte array, * create Escher tree from byte array, create map <EscherRecord, Record> * * @param records - list of all records inside sheet * @param locFirstDrawingRecord - location of the first DrawingRecord inside sheet * @return new EscherAggregate create from all aggregated records which belong to drawing layer */ public static EscherAggregate CreateAggregate(List<RecordBase> records, int locFirstDrawingRecord) { // 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. List<EscherRecord> shapeRecords = new List<EscherRecord>(); IEscherRecordFactory recordFactory = new CustomEscherRecordFactory(shapeRecords); // Create one big buffer MemoryStream stream = new MemoryStream(); EscherAggregate agg = new EscherAggregate(false); int loc = locFirstDrawingRecord; while (loc + 1 < records.Count && (IsDrawingLayerRecord(GetSid(records, loc)))) { try { if (!(GetSid(records, loc) == DrawingRecord.sid || GetSid(records, loc) == ContinueRecord.sid)) { loc++; continue; } if (GetSid(records, loc) == DrawingRecord.sid) { byte[] data = ((DrawingRecord)records[loc]).Data; stream.Write(data, 0, data.Length); } else { byte[] data = ((ContinueRecord)records[loc]).Data; stream.Write(data, 0, data.Length); } } catch (IOException e) { throw new RuntimeException("Couldn't get data from drawing/continue records", e); } loc++; } // Decode the shapes // agg.escherRecords = new ArrayList(); int pos = 0; byte[] buffer = stream.ToArray(); while (pos < buffer.Length) { 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 + 1; int shapeIndex = 0; while (loc < records.Count && IsDrawingLayerRecord(GetSid(records, loc))) { if (!IsObjectRecord(records, loc)) { loc++; continue; } Record objRecord = (Record)records[loc]; agg.shapeToObj[shapeRecords[shapeIndex++]] = objRecord; loc++; } // any NoteRecords that follow the drawing block must be aggregated and and saved in the tailRec collection //put noterecord into tailsRec while (loc < records.Count) { if (GetSid(records, loc) == NoteRecord.sid) { NoteRecord r = (NoteRecord)records[(loc)]; agg.tailRec[r.ShapeId] = r; } else { break; } loc++; } int locLastDrawingRecord = loc; //records.SubList(locFirstDrawingRecord, locLastDrawingRecord).Clear(); records.RemoveRange(locFirstDrawingRecord, locLastDrawingRecord - locFirstDrawingRecord); records.Insert(locFirstDrawingRecord, agg); return agg; }
/** * 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; }