public void TestGetPatriarch() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; Assert.IsNull(sh.DrawingPatriarch); HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; Assert.IsNotNull(patriarch); patriarch.CreateSimpleShape(new HSSFClientAnchor()); patriarch.CreateSimpleShape(new HSSFClientAnchor()); Assert.AreSame(patriarch, sh.DrawingPatriarch); EscherAggregate agg = patriarch.GetBoundAggregate(); EscherDgRecord dg = agg.GetEscherContainer().GetChildById(EscherDgRecord.RECORD_ID) as EscherDgRecord; int lastId = dg.LastMSOSPID; Assert.AreSame(patriarch, sh.CreateDrawingPatriarch()); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sh = wb.GetSheetAt(0) as HSSFSheet; patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; dg = patriarch.GetBoundAggregate().GetEscherContainer().GetChildById(EscherDgRecord.RECORD_ID) as EscherDgRecord; Assert.AreEqual(lastId, dg.LastMSOSPID); }
public void TestAllocateShapeId() { EscherDgRecord dgRecord1 = drawingManager2.CreateDgRecord(); EscherDgRecord dgRecord2 = drawingManager2.CreateDgRecord(); Assert.AreEqual(1024, drawingManager2.AllocateShapeId((short)1)); Assert.AreEqual(1024, dgRecord1.LastMSOSPID); Assert.AreEqual(1025, dgg.ShapeIdMax); Assert.AreEqual(1025, drawingManager2.AllocateShapeId((short)1)); Assert.AreEqual(1025, dgRecord1.LastMSOSPID); Assert.AreEqual(1026, dgg.ShapeIdMax); Assert.AreEqual(1026, drawingManager2.AllocateShapeId((short)1)); Assert.AreEqual(1026, dgRecord1.LastMSOSPID); Assert.AreEqual(1027, dgg.ShapeIdMax); Assert.AreEqual(2048, drawingManager2.AllocateShapeId((short)2)); Assert.AreEqual(2048, dgRecord2.LastMSOSPID); Assert.AreEqual(2049, dgg.ShapeIdMax); for (int i = 0; i < 1021; i++) { drawingManager2.AllocateShapeId((short)1); Assert.AreEqual(2049, dgg.ShapeIdMax); } Assert.AreEqual(3072, drawingManager2.AllocateShapeId((short)1)); Assert.AreEqual(3073, dgg.ShapeIdMax); Assert.AreEqual(2, dgg.DrawingsSaved); Assert.AreEqual(4, dgg.NumIdClusters); Assert.AreEqual(1026, dgg.NumShapesSaved); }
/** * Allocates new shape id for the new drawing Group id. * * @return a new shape id. */ public int AllocateShapeId(short drawingGroupId) { // Get the last shape id for this drawing Group. EscherDgRecord dg = (EscherDgRecord)dgMap[drawingGroupId]; int lastShapeId = dg.LastMSOSPID; // Have we run out of shapes for this cluster? int newShapeId = 0; if (lastShapeId % 1024 == 1023) { // Yes: // Find the starting shape id of the next free cluster newShapeId = FindFreeSPIDBlock(); // Create a new cluster in the dgg record. dgg.AddCluster(drawingGroupId, 1); } else { // No: // Find the cluster for this drawing Group with free space. for (int i = 0; i < dgg.FileIdClusters.Length; i++) { EscherDggRecord.FileIdCluster c = dgg.FileIdClusters[i]; if (c.DrawingGroupId == drawingGroupId) { if (c.NumShapeIdsUsed != 1024) { // Increment the number of shapes used for this cluster. c.IncrementShapeId(); } } // If the last shape id = -1 then we know to Find a free block; if (dg.LastMSOSPID == -1) { newShapeId = FindFreeSPIDBlock(); } else { // The new shape id to be the last shapeid of this cluster + 1 newShapeId = dg.LastMSOSPID + 1; } } } // Increment the total number of shapes used in the dgg. dgg.NumShapesSaved = (dgg.NumShapesSaved + 1); // Is the new shape id >= max shape id for dgg? if (newShapeId >= dgg.ShapeIdMax) { // Yes: // Set the max shape id = new shape id + 1 dgg.ShapeIdMax = newShapeId + 1; } // Set last shape id for this drawing Group. dg.LastMSOSPID = newShapeId; // Increased the number of shapes used for this drawing Group. dg.IncrementShapeCount(); return(newShapeId); }
/// <summary> /// Allocates new shape id for the new drawing group id. /// </summary> /// <param name="drawingGroupId"></param> /// <param name="dg"></param> /// <returns>a new shape id.</returns> public virtual int AllocateShapeId(short drawingGroupId, EscherDgRecord dg) { dgg.NumShapesSaved = (dgg.NumShapesSaved + 1); // Add to existing cluster if space available for (int i = 0; i < dgg.FileIdClusters.Length; i++) { EscherDggRecord.FileIdCluster c = dgg.FileIdClusters[i]; if (c.DrawingGroupId == drawingGroupId && c.NumShapeIdsUsed != 1024) { int result = c.NumShapeIdsUsed + (1024 * (i + 1)); c.IncrementShapeId(); dg.NumShapes = (dg.NumShapes + 1); dg.LastMSOSPID = (result); if (result >= dgg.ShapeIdMax) { dgg.ShapeIdMax = (result + 1); } return(result); } } // Create new cluster dgg.AddCluster(drawingGroupId, 0); dgg.FileIdClusters[dgg.FileIdClusters.Length - 1].IncrementShapeId(); dg.NumShapes = (dg.NumShapes + 1); int result2 = (1024 * dgg.FileIdClusters.Length); dg.LastMSOSPID = (result2); if (result2 >= dgg.ShapeIdMax) { dgg.ShapeIdMax = (result2 + 1); } return(result2); }
public void TestCloneSheetWithEmptyDrawingAggregate() { HSSFWorkbook b = new HSSFWorkbook(); HSSFSheet s = b.CreateSheet("Test") as HSSFSheet; HSSFPatriarch patriarch = s.CreateDrawingPatriarch() as HSSFPatriarch; EscherAggregate agg1 = patriarch.GetBoundAggregate(); HSSFSheet s2 = s.CloneSheet(b) as HSSFSheet; patriarch = s2.DrawingPatriarch as HSSFPatriarch; EscherAggregate agg2 = patriarch.GetBoundAggregate(); EscherSpRecord sp1 = (EscherSpRecord)agg1.GetEscherContainer().GetChild(1).GetChild(0).GetChild(1); EscherSpRecord sp2 = (EscherSpRecord)agg2.GetEscherContainer().GetChild(1).GetChild(0).GetChild(1); Assert.AreEqual(sp1.ShapeId, 1024); Assert.AreEqual(sp2.ShapeId, 2048); EscherDgRecord dg = (EscherDgRecord)agg2.GetEscherContainer().GetChild(0); Assert.AreEqual(dg.LastMSOSPID, 2048); Assert.AreEqual(dg.Instance, 0x2); //everything except id and DgRecord.lastMSOSPID and DgRecord.Instance must be the same sp2.ShapeId = (1024); dg.LastMSOSPID = (1024); dg.Instance =((short)0x1); Assert.AreEqual(agg1.Serialize().Length, agg2.Serialize().Length); Assert.AreEqual(agg1.ToXml(""), agg2.ToXml("")); Assert.IsTrue(Arrays.Equals(agg1.Serialize(), agg2.Serialize())); }
public void TestCloneSheetWithDrawings() { HSSFWorkbook wb1 = HSSFTestDataSamples.OpenSampleWorkbook("45720.xls"); HSSFSheet sheet1 = (HSSFSheet)wb1.GetSheetAt(0); wb1.Workbook.FindDrawingGroup(); DrawingManager2 dm1 = wb1.Workbook.DrawingManager; wb1.CloneSheet(0); HSSFWorkbook wb2 = HSSFTestDataSamples.WriteOutAndReadBack(wb1); wb2.Workbook.FindDrawingGroup(); DrawingManager2 dm2 = wb2.Workbook.DrawingManager; //Check EscherDggRecord - a workbook-level registry of drawing objects Assert.AreEqual(dm1.GetDgg().MaxDrawingGroupId + 1, dm2.GetDgg().MaxDrawingGroupId); HSSFSheet sheet2 = (HSSFSheet)wb2.GetSheetAt(1); //Check that id of the drawing Group was updated EscherDgRecord dg1 = (EscherDgRecord)(sheet1.DrawingPatriarch as HSSFPatriarch).GetBoundAggregate().FindFirstWithId(EscherDgRecord.RECORD_ID); EscherDgRecord dg2 = (EscherDgRecord)(sheet2.DrawingPatriarch as HSSFPatriarch).GetBoundAggregate().FindFirstWithId(EscherDgRecord.RECORD_ID); int dg_id_1 = dg1.Options >> 4; int dg_id_2 = dg2.Options >> 4; Assert.AreEqual(dg_id_1 + 1, dg_id_2); //TODO: Check shapeId in the Cloned sheet }
internal int NewShapeId() { DrawingManager2 dm = ((HSSFWorkbook)_sheet.Workbook).Workbook.DrawingManager; EscherDgRecord dg = (EscherDgRecord)_boundAggregate.GetEscherContainer().GetChildById(EscherDgRecord.RECORD_ID); short drawingGroupId = dg.DrawingGroupId; return(dm.AllocateShapeId(drawingGroupId, dg)); }
private EscherDgRecord CreateRecord() { EscherDgRecord r = new EscherDgRecord(); r.Options = (short)0x0010; r.RecordId = EscherDgRecord.RECORD_ID; r.NumShapes = 2; r.LastMSOSPID = 1025; return(r); }
public override EscherDgRecord CreateDgRecord() { EscherDgRecord dg = new EscherDgRecord(); dg.RecordId = (EscherDgRecord.RECORD_ID); dg.Options = ((short)(16)); dg.NumShapes = (1); dg.LastMSOSPID = (1024); return(dg); }
public void TestDgRecordNumShapes() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch; EscherAggregate aggregate = HSSFTestHelper.GetEscherAggregate(patriarch); EscherDgRecord dgRecord = (EscherDgRecord)aggregate.GetEscherRecord(0).GetChild(0) as EscherDgRecord; Assert.AreEqual(dgRecord.NumShapes, 1); }
public void TestSerialize() { EscherDgRecord r = CreateRecord(); byte[] data = new byte[16]; int bytesWritten = r.Serialize(0, data); Assert.AreEqual(16, bytesWritten); Assert.AreEqual("[10, 00, " + "08, F0, " + "08, 00, 00, 00, " + "02, 00, 00, 00, " + // num shapes in drawing "01, 04, 00, 00]", // The last MSOSPID given to an SP in this DG HexDump.ToHex(data)); }
public EscherDgRecord CreateDgRecord() { EscherDgRecord dg = new EscherDgRecord(); dg.RecordId = (EscherDgRecord.RECORD_ID); short dgId = FindNewDrawingGroupId(); dg.Options = ((short)(dgId << 4)); dg.NumShapes = (0); dg.LastMSOSPID = (-1); dgg.AddCluster(dgId, 0); dgg.DrawingsSaved = (dgg.DrawingsSaved + 1); dgMap[dgId] = dg; return(dg); }
public virtual EscherDgRecord CreateDgRecord() { EscherDgRecord dg = new EscherDgRecord(); dg.RecordId = EscherDgRecord.RECORD_ID; short dgId = FindNewDrawingGroupId(); dg.Options = (short)(dgId << 4); dg.NumShapes = 0; dg.LastMSOSPID = (-1); drawingGroups.Add(dg); dgg.AddCluster(dgId, 0); dgg.DrawingsSaved = dgg.DrawingsSaved + 1; return(dg); }
public void TestCreateDgRecord() { EscherDggRecord dgg = new EscherDggRecord(); dgg.DrawingsSaved=(0); dgg.FileIdClusters=(new EscherDggRecord.FileIdCluster[] { }); DrawingManager dm = new DrawingManager(dgg); EscherDgRecord dgRecord = dm.CreateDgRecord(); Assert.AreEqual(-1, dgRecord.LastMSOSPID); Assert.AreEqual(0, dgRecord.NumShapes); Assert.AreEqual(1, dm.Dgg.DrawingsSaved); Assert.AreEqual(1, dm.Dgg.FileIdClusters.Length); Assert.AreEqual(1, dm.Dgg.FileIdClusters[0].DrawingGroupId); Assert.AreEqual(0, dm.Dgg.FileIdClusters[0].NumShapeIdsUsed); }
public void TestShapeIds() { HSSFWorkbook wb1 = new HSSFWorkbook(); HSSFSheet sheet1 = wb1.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch1 = sheet1.CreateDrawingPatriarch() as HSSFPatriarch; for (int i = 0; i < 2; i++) { patriarch1.CreateSimpleShape(new HSSFClientAnchor()); } HSSFWorkbook wb2 = HSSFTestDataSamples.WriteOutAndReadBack(wb1); wb1.Close(); sheet1 = wb2.GetSheetAt(0) as HSSFSheet; patriarch1 = sheet1.DrawingPatriarch as HSSFPatriarch; EscherAggregate agg1 = HSSFTestHelper.GetEscherAggregate(patriarch1); // last shape ID cached in EscherDgRecord EscherDgRecord dg1 = agg1.GetEscherContainer().GetChildById(EscherDgRecord.RECORD_ID) as EscherDgRecord; Assert.AreEqual(1026, dg1.LastMSOSPID); // iterate over shapes and check shapeId EscherContainerRecord spgrContainer = agg1.GetEscherContainer().ChildContainers[0] as EscherContainerRecord; // root spContainer + 2 spContainers for shapes Assert.AreEqual(3, spgrContainer.ChildRecords.Count); EscherSpRecord sp0 = ((EscherContainerRecord)spgrContainer.GetChild(0)).GetChildById(EscherSpRecord.RECORD_ID) as EscherSpRecord; Assert.AreEqual(1024, sp0.ShapeId); EscherSpRecord sp1 = ((EscherContainerRecord)spgrContainer.GetChild(1)).GetChildById(EscherSpRecord.RECORD_ID) as EscherSpRecord; Assert.AreEqual(1025, sp1.ShapeId); EscherSpRecord sp2 = ((EscherContainerRecord)spgrContainer.GetChild(2)).GetChildById(EscherSpRecord.RECORD_ID) as EscherSpRecord; Assert.AreEqual(1026, sp2.ShapeId); wb2.Close(); }
public void TestFillFields() { String hexData = "10 00 " + "08 F0 " + "08 00 00 00 " + "02 00 00 00 " + "01 04 00 00 "; byte[] data = HexRead.ReadFromString(hexData); EscherDgRecord r = new EscherDgRecord(); int bytesWritten = r.FillFields(data, new DefaultEscherRecordFactory()); Assert.AreEqual(16, bytesWritten); Assert.AreEqual(2, r.NumShapes); Assert.AreEqual(1025, r.LastMSOSPID); }
public void TestAllocateShapeId() { EscherDggRecord dgg = new EscherDggRecord(); dgg.DrawingsSaved=(0); dgg.FileIdClusters=(new EscherDggRecord.FileIdCluster[] { }); DrawingManager dm = new DrawingManager(dgg); EscherDgRecord dg = dm.CreateDgRecord(); int shapeId = dm.AllocateShapeId(dg.DrawingGroupId); Assert.AreEqual(1024, shapeId); Assert.AreEqual(1025, dgg.ShapeIdMax); Assert.AreEqual(1, dgg.DrawingsSaved); Assert.AreEqual(1, dgg.FileIdClusters[0].DrawingGroupId); Assert.AreEqual(1, dgg.FileIdClusters[0].NumShapeIdsUsed); Assert.AreEqual(1024, dg.LastMSOSPID); Assert.AreEqual(1, dg.NumShapes); }
public void TestCreateDgRecord() { EscherDgRecord dgRecord1 = drawingManager2.CreateDgRecord(); Assert.AreEqual(1, dgRecord1.DrawingGroupId); Assert.AreEqual(-1, dgRecord1.LastMSOSPID); EscherDgRecord dgRecord2 = drawingManager2.CreateDgRecord(); Assert.AreEqual(2, dgRecord2.DrawingGroupId); Assert.AreEqual(-1, dgRecord2.LastMSOSPID); Assert.AreEqual(2, dgg.DrawingsSaved); Assert.AreEqual(2, dgg.FileIdClusters.Length); Assert.AreEqual(3, dgg.NumIdClusters); Assert.AreEqual(0, dgg.NumShapesSaved); }
public virtual int AllocateShapeId(short drawingGroupId, EscherDgRecord dg) { return(1025); }
public override int AllocateShapeId(short drawingGroupId, EscherDgRecord dg) { return(1025); }
/// <summary> /// Allocates new shape id for the new drawing Group id. /// </summary> /// <param name="drawingGroupId"></param> /// <returns>a new shape id.</returns> public virtual int AllocateShapeId(short drawingGroupId) { EscherDgRecord dg = GetDrawingGroup(drawingGroupId); return(AllocateShapeId(drawingGroupId, dg)); }