/// <summary> /// Creates the lowerlevel escher records for this shape. /// </summary> /// <param name="hssfShape">The HSSF shape.</param> /// <param name="shapeId">The shape id.</param> /// <returns></returns> private EscherContainerRecord CreateSpContainer(HSSFSimpleShape hssfShape, int shapeId) { HSSFShape shape = hssfShape; EscherContainerRecord spContainer = new EscherContainerRecord(); EscherSpRecord sp = new EscherSpRecord(); EscherOptRecord opt = new EscherOptRecord(); EscherClientDataRecord clientData = new EscherClientDataRecord(); spContainer.RecordId = EscherContainerRecord.SP_CONTAINER; spContainer.Options = (short)0x000F; sp.RecordId = EscherSpRecord.RECORD_ID; short shapeType = objTypeToShapeType(hssfShape.ShapeType); sp.Options = (short)((shapeType << 4) | 0x2); sp.ShapeId = shapeId; sp.Flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE; opt.RecordId = EscherOptRecord.RECORD_ID; AddStandardOptions(shape, opt); EscherRecord anchor = CreateAnchor(shape.Anchor); clientData.RecordId = EscherClientDataRecord.RECORD_ID; clientData.Options = (short)0x0000; spContainer.AddChildRecord(sp); spContainer.AddChildRecord(opt); spContainer.AddChildRecord(anchor); spContainer.AddChildRecord(clientData); return(spContainer); }
/** * Generates the escher shape records for this shape. */ private EscherContainerRecord CreateSpContainer(HSSFSimpleShape shape, int shapeId) { EscherContainerRecord spContainer = new EscherContainerRecord(); EscherSpRecord sp = new EscherSpRecord(); EscherOptRecord opt = new EscherOptRecord(); EscherClientDataRecord clientData = new EscherClientDataRecord(); spContainer.RecordId = (EscherContainerRecord.SP_CONTAINER); spContainer.Options = ((short)0x000F); sp.RecordId = (EscherSpRecord.RECORD_ID); sp.Options = ((short)((EscherAggregate.ST_HOSTCONTROL << 4) | 0x2)); sp.ShapeId = (shapeId); sp.Flags = (EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE); opt.RecordId = (EscherOptRecord.RECORD_ID); opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 17039620)); opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x00080008)); opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080000)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00020000)); HSSFClientAnchor userAnchor = (HSSFClientAnchor)shape.Anchor; userAnchor.AnchorType = 1; EscherRecord anchor = CreateAnchor(userAnchor); clientData.RecordId = (EscherClientDataRecord.RECORD_ID); clientData.Options = ((short)0x0000); spContainer.AddChildRecord(sp); spContainer.AddChildRecord(opt); spContainer.AddChildRecord(anchor); spContainer.AddChildRecord(clientData); return(spContainer); }
public void TestShapeId() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFComment comment = patriarch.CreateCellComment(new HSSFClientAnchor()) as HSSFComment; comment.ShapeId = 2024; /** * SpRecord.id == shapeId * ObjRecord.id == shapeId % 1024 * NoteRecord.id == ObjectRecord.id == shapeId % 1024 */ Assert.AreEqual(comment.ShapeId, 2024); CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord)comment.GetObjRecord().SubRecords[0]; Assert.AreEqual(cod.ObjectId, 1000); EscherSpRecord spRecord = (EscherSpRecord)comment.GetEscherContainer().GetChild(0); Assert.AreEqual(spRecord.ShapeId, 2024); Assert.AreEqual(comment.ShapeId, 2024); Assert.AreEqual(comment.NoteRecord.ShapeId, 1000); }
public void TestPolygonType() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFPolygon polygon = patriarch.CreatePolygon(new HSSFClientAnchor()); polygon.SetPolygonDrawArea(102, 101); polygon.SetPoints(new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sh = wb.GetSheetAt(0) as HSSFSheet; patriarch = sh.DrawingPatriarch as HSSFPatriarch; HSSFPolygon polygon1 = patriarch.CreatePolygon(new HSSFClientAnchor()); polygon1.SetPolygonDrawArea(102, 101); polygon1.SetPoints(new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }); EscherSpRecord spRecord = polygon1.GetEscherContainer().GetChildById(EscherSpRecord.RECORD_ID) as EscherSpRecord; spRecord.ShapeType = ((short)77 /**RANDOM**/); wb = HSSFTestDataSamples.WriteOutAndReadBack(wb); sh = wb.GetSheetAt(0) as HSSFSheet; patriarch = sh.DrawingPatriarch as HSSFPatriarch; Assert.AreEqual(patriarch.Children.Count, 2); Assert.IsTrue(patriarch.Children[0] is HSSFPolygon); Assert.IsTrue(patriarch.Children[1] is HSSFPolygon); }
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 TestCloneComment() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch p = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFComment c = p.CreateComment(new HSSFClientAnchor(0, 0, 100, 100, (short)0, 0, (short)5, 5)); c.Column = (1); c.Row = (2); c.String = (new HSSFRichTextString("qwertyuio")); HSSFSheet sh2 = wb.CloneSheet(0) as HSSFSheet; HSSFPatriarch p2 = sh2.DrawingPatriarch as HSSFPatriarch; HSSFComment c2 = (HSSFComment)p2.Children[0]; Assert.IsTrue(Arrays.Equals(c2.GetTextObjectRecord().Serialize(), c.GetTextObjectRecord().Serialize())); Assert.IsTrue(Arrays.Equals(c2.GetObjRecord().Serialize(), c.GetObjRecord().Serialize())); Assert.IsTrue(Arrays.Equals(c2.NoteRecord.Serialize(), c.NoteRecord.Serialize())); //everything except spRecord.shapeId must be the same Assert.IsFalse(Arrays.Equals(c2.GetEscherContainer().Serialize(), c.GetEscherContainer().Serialize())); EscherSpRecord sp = (EscherSpRecord)c2.GetEscherContainer().GetChild(0); sp.ShapeId = (1025); Assert.IsTrue(Arrays.Equals(c2.GetEscherContainer().Serialize(), c.GetEscherContainer().Serialize())); }
/** * Sets shape ID * * @param id of the shape */ public void SetShapeId(int id) { EscherSpRecord spRecord = _escherContainer.GetChildById(EscherSpRecord.RECORD_ID); if (spRecord != null) { spRecord.ShapeId = (id); } }
private EscherSpRecord CreateRecord() { EscherSpRecord r = new EscherSpRecord(); r.Options = (short)0x0002; r.RecordId = EscherSpRecord.RECORD_ID; r.ShapeId = 0x0400; r.Flags = 0x05; return(r); }
/// <summary> /// Create a new shape object used to Create the escher records. /// </summary> /// <param name="hssfShape">The simple shape this Is based on.</param> /// <param name="shapeId">The shape id.</param> /// <returns></returns> public static AbstractShape CreateShape(HSSFShape hssfShape, int shapeId) { AbstractShape shape; if (hssfShape is HSSFComment) { shape = new CommentShape((HSSFComment)hssfShape, shapeId); } else if (hssfShape is HSSFTextbox) { shape = new TextboxShape((HSSFTextbox)hssfShape, shapeId); } else if (hssfShape is HSSFPolygon) { shape = new PolygonShape((HSSFPolygon)hssfShape, shapeId); } else if (hssfShape is HSSFSimpleShape) { HSSFSimpleShape simpleShape = (HSSFSimpleShape)hssfShape; switch (simpleShape.ShapeType) { case HSSFSimpleShape.OBJECT_TYPE_PICTURE: shape = new PictureShape(simpleShape, shapeId); break; case HSSFSimpleShape.OBJECT_TYPE_LINE: shape = new LineShape(simpleShape, shapeId); break; case HSSFSimpleShape.OBJECT_TYPE_OVAL: case HSSFSimpleShape.OBJECT_TYPE_RECTANGLE: shape = new SimpleFilledShape(simpleShape, shapeId); break; case HSSFSimpleShape.OBJECT_TYPE_COMBO_BOX: shape = new ComboboxShape(simpleShape, shapeId); break; default: throw new ArgumentException("Do not know how to handle this type of shape"); } } else { throw new ArgumentException("Unknown shape type"); } EscherSpRecord sp = (EscherSpRecord)shape.SpContainer.GetChildById(EscherSpRecord.RECORD_ID); if (hssfShape.Parent != null) { sp.Flags = sp.Flags | EscherSpRecord.FLAG_CHILD; } return(shape); }
/// <summary> /// Creates the lowerlevel escher records for this shape. /// </summary> /// <param name="hssfShape">The HSSF shape.</param> /// <param name="shapeId">The shape id.</param> /// <returns></returns> private EscherContainerRecord CreateSpContainer(HSSFTextbox hssfShape, int shapeId) { HSSFTextbox shape = hssfShape; EscherContainerRecord spContainer = new EscherContainerRecord(); EscherSpRecord sp = new EscherSpRecord(); EscherOptRecord opt = new EscherOptRecord(); EscherRecord anchor = new EscherClientAnchorRecord(); EscherClientDataRecord clientData = new EscherClientDataRecord(); escherTextbox = new EscherTextboxRecord(); spContainer.RecordId = EscherContainerRecord.SP_CONTAINER; spContainer.Options = (short)0x000F; sp.RecordId = EscherSpRecord.RECORD_ID; sp.Options = (short)((EscherAggregate.ST_TEXTBOX << 4) | 0x2); sp.ShapeId = shapeId; sp.Flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE; opt.RecordId = EscherOptRecord.RECORD_ID; // opt.AddEscherProperty( new EscherBoolProperty( EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 262144 ) ); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTID, 0)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTLEFT, shape.MarginLeft)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTRIGHT, shape.MarginRight)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTBOTTOM, shape.MarginBottom)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTTOP, shape.MarginTop)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__WRAPTEXT, 0)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__ANCHORTEXT, 0)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00080000)); AddStandardOptions(shape, opt); HSSFAnchor userAnchor = shape.Anchor; // if (userAnchor.IsHorizontallyFlipped()) // sp.Flags(sp.Flags | EscherSpRecord.FLAG_FLIPHORIZ); // if (userAnchor.IsVerticallyFlipped()) // sp.Flags(sp.Flags | EscherSpRecord.FLAG_FLIPVERT); anchor = CreateAnchor(userAnchor); clientData.RecordId = EscherClientDataRecord.RECORD_ID; clientData.Options = (short)0x0000; escherTextbox.RecordId = EscherTextboxRecord.RECORD_ID; escherTextbox.Options = (short)0x0000; spContainer.AddChildRecord(sp); spContainer.AddChildRecord(opt); spContainer.AddChildRecord(anchor); spContainer.AddChildRecord(clientData); spContainer.AddChildRecord(escherTextbox); return(spContainer); }
private void SetFlipFlags(HSSFShape shape) { EscherSpRecord sp = (EscherSpRecord)shape.GetEscherContainer().GetChildById(EscherSpRecord.RECORD_ID); if (shape.Anchor.IsHorizontallyFlipped) { sp.Flags = (sp.Flags | EscherSpRecord.FLAG_FLIPHORIZ); } if (shape.Anchor.IsVerticallyFlipped) { sp.Flags = (sp.Flags | EscherSpRecord.FLAG_FLIPVERT); } }
/** * Generates the shape records for this shape. */ protected override EscherContainerRecord CreateSpContainer() { EscherContainerRecord spContainer = new EscherContainerRecord(); EscherSpRecord sp = new EscherSpRecord(); EscherOptRecord opt = new EscherOptRecord(); EscherClientDataRecord clientData = new EscherClientDataRecord(); spContainer.RecordId = (EscherContainerRecord.SP_CONTAINER); spContainer.Options = ((short)0x000F); sp.RecordId = (EscherSpRecord.RECORD_ID); sp.Options = ((short)((EscherAggregate.ST_NOT_PRIMATIVE << 4) | 0x2)); if (Parent == null) { sp.Flags = (EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE); } else { sp.Flags = (EscherSpRecord.FLAG_CHILD | EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE); } opt.RecordId = (EscherOptRecord.RECORD_ID); opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.TRANSFORM__ROTATION, false, false, 0)); opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, false, false, 100)); opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, false, false, 100)); opt.SetEscherProperty(new EscherShapePathProperty(EscherProperties.GEOMETRY__SHAPEPATH, EscherShapePathProperty.COMPLEX)); opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__FILLOK, false, false, 0x00010001)); opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINESTARTARROWHEAD, false, false, 0x0)); opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEENDARROWHEAD, false, false, 0x0)); opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEENDCAPSTYLE, false, false, 0x0)); opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, LINESTYLE_SOLID)); opt.SetEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008)); opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, LINEWIDTH_DEFAULT)); opt.SetEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, FILL__FILLCOLOR_DEFAULT)); opt.SetEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, LINESTYLE__COLOR_DEFAULT)); opt.SetEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, 1)); opt.SetEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x080000)); EscherRecord anchor = Anchor.GetEscherAnchor(); clientData.RecordId = (EscherClientDataRecord.RECORD_ID); clientData.Options = ((short)0x0000); spContainer.AddChildRecord(sp); spContainer.AddChildRecord(opt); spContainer.AddChildRecord(anchor); spContainer.AddChildRecord(clientData); return(spContainer); }
public void TestSerialize() { EscherSpRecord r = CreateRecord(); byte[] data = new byte[16]; int bytesWritten = r.Serialize(0, data); Assert.AreEqual(16, bytesWritten); Assert.AreEqual("[02, 00, " + "0A, F0, " + "08, 00, 00, 00, " + "00, 04, 00, 00, " + "05, 00, 00, 00, ]", HexDump.ToHex(data)); }
protected override EscherContainerRecord CreateSpContainer() { EscherContainerRecord spContainer = new EscherContainerRecord(); EscherSpRecord sp = new EscherSpRecord(); EscherOptRecord opt = new EscherOptRecord(); EscherClientDataRecord clientData = new EscherClientDataRecord(); EscherTextboxRecord escherTextbox = new EscherTextboxRecord(); spContainer.RecordId = (EscherContainerRecord.SP_CONTAINER); spContainer.Options = ((short)0x000F); sp.RecordId = (EscherSpRecord.RECORD_ID); sp.Options = ((short)((EscherAggregate.ST_TEXTBOX << 4) | 0x2)); sp.Flags = (EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE); opt.RecordId = (EscherOptRecord.RECORD_ID); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTID, 0)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__WRAPTEXT, 0)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__ANCHORTEXT, 0)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00080000)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTLEFT, 0)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTRIGHT, 0)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTTOP, 0)); opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.TEXT__TEXTBOTTOM, 0)); opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, LINESTYLE_SOLID)); opt.SetEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008)); opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, LINEWIDTH_DEFAULT)); opt.SetEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, FILL__FILLCOLOR_DEFAULT)); opt.SetEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, LINESTYLE__COLOR_DEFAULT)); opt.SetEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, NO_FILLHITTEST_FALSE)); opt.SetEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x080000)); EscherRecord anchor = Anchor.GetEscherAnchor(); clientData.RecordId = (EscherClientDataRecord.RECORD_ID); clientData.Options = ((short)0x0000); escherTextbox.RecordId = (EscherTextboxRecord.RECORD_ID); escherTextbox.Options = ((short)0x0000); spContainer.AddChildRecord(sp); spContainer.AddChildRecord(opt); spContainer.AddChildRecord(anchor); spContainer.AddChildRecord(clientData); spContainer.AddChildRecord(escherTextbox); return(spContainer); }
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 = "02 00 " + "0A F0 " + "08 00 00 00 " + "00 04 00 00 " + "05 00 00 00 "; byte[] data = HexRead.ReadFromString(hexData); EscherSpRecord r = new EscherSpRecord(); int bytesWritten = r.FillFields(data, new DefaultEscherRecordFactory()); Assert.AreEqual(16, bytesWritten); Assert.AreEqual(0x0400, r.ShapeId); Assert.AreEqual(0x05, r.Flags); }
protected override EscherContainerRecord CreateSpContainer() { EscherContainerRecord spgrContainer = new EscherContainerRecord(); EscherContainerRecord spContainer = new EscherContainerRecord(); EscherSpgrRecord spgr = new EscherSpgrRecord(); EscherSpRecord sp = new EscherSpRecord(); EscherOptRecord opt = new EscherOptRecord(); EscherRecord anchor; EscherClientDataRecord clientData = new EscherClientDataRecord(); spgrContainer.RecordId = (EscherContainerRecord.SPGR_CONTAINER); spgrContainer.Options = ((short)0x000F); spContainer.RecordId = (EscherContainerRecord.SP_CONTAINER); spContainer.Options = (short)0x000F; spgr.RecordId = (EscherSpgrRecord.RECORD_ID); spgr.Options = (short)0x0001; spgr.RectX1 = (0); spgr.RectY1 = (0); spgr.RectX2 = (1023); spgr.RectY2 = (255); sp.RecordId = (EscherSpRecord.RECORD_ID); sp.Options = (short)0x0002; if (this.Anchor is HSSFClientAnchor) { sp.Flags = (EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_HAVEANCHOR); } else { sp.Flags = (EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_CHILD); } opt.RecordId = (EscherOptRecord.RECORD_ID); opt.Options = ((short)0x0023); opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x00040004)); opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00080000)); anchor = Anchor.GetEscherAnchor(); clientData.RecordId = (EscherClientDataRecord.RECORD_ID); clientData.Options = ((short)0x0000); spgrContainer.AddChildRecord(spContainer); spContainer.AddChildRecord(spgr); spContainer.AddChildRecord(sp); spContainer.AddChildRecord(opt); spContainer.AddChildRecord(anchor); spContainer.AddChildRecord(clientData); return(spgrContainer); }
private EscherContainerRecord GetEscherShapeRecordContainer( int shapeId) { foreach (EscherContainerRecord spContainer in _escherRecordHolder .GetSpContainers()) { EscherSpRecord escherSpRecord = spContainer .GetChildById(unchecked ((short)0xF00A)); if (escherSpRecord != null && escherSpRecord.ShapeId == shapeId) { return(spContainer); } } return(null); }
public void TestSerialize() { EscherContainerRecord container1 = new EscherContainerRecord(); EscherContainerRecord spContainer1 = new EscherContainerRecord(); EscherContainerRecord spContainer2 = new EscherContainerRecord(); EscherContainerRecord spContainer3 = new EscherContainerRecord(); EscherSpRecord sp1 = new EscherSpRecord(); EscherSpRecord sp2 = new EscherSpRecord(); EscherSpRecord sp3 = new EscherSpRecord(); EscherClientDataRecord d2 = new EscherClientDataRecord(); EscherClientDataRecord d3 = new EscherClientDataRecord(); container1.Options = ((short)0x000F); spContainer1.Options = ((short)0x000F); spContainer1.RecordId = (EscherContainerRecord.SP_CONTAINER); spContainer2.Options = ((short)0x000F); spContainer2.RecordId = (EscherContainerRecord.SP_CONTAINER); spContainer3.Options = ((short)0x000F); spContainer3.RecordId = (EscherContainerRecord.SP_CONTAINER); d2.RecordId = (EscherClientDataRecord.RECORD_ID); d2.RemainingData = (new byte[0]); d3.RecordId = (EscherClientDataRecord.RECORD_ID); d3.RemainingData = (new byte[0]); container1.AddChildRecord(spContainer1); container1.AddChildRecord(spContainer2); container1.AddChildRecord(spContainer3); spContainer1.AddChildRecord(sp1); spContainer2.AddChildRecord(sp2); spContainer3.AddChildRecord(sp3); spContainer2.AddChildRecord(d2); spContainer3.AddChildRecord(d3); EscherAggregate aggregate = new EscherAggregate(null); aggregate.AddEscherRecord(container1); aggregate.AssoicateShapeToObjRecord(d2, new ObjRecord()); aggregate.AssoicateShapeToObjRecord(d3, new ObjRecord()); byte[] data = new byte[112]; int bytesWritten = aggregate.Serialize(0, data); Assert.AreEqual(112, bytesWritten); Assert.AreEqual("[EC, 00, 40, 00, 0F, 00, 00, 00, 58, 00, 00, 00, 0F, 00, 04, F0, 10, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0F, 00, 04, F0, 18, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 11, F0, 00, 00, 00, 00, 5D, 00, 00, 00, EC, 00, 20, 00, 0F, 00, 04, F0, 18, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 11, F0, 00, 00, 00, 00, 5D, 00, 00, 00, ]", HexDump.ToHex(data)); }
protected override EscherContainerRecord CreateSpContainer() { EscherContainerRecord spContainer = new EscherContainerRecord(); spContainer.RecordId = EscherContainerRecord.SP_CONTAINER; spContainer.Options = ((short)0x000F); EscherSpRecord sp = new EscherSpRecord(); sp.RecordId = (EscherSpRecord.RECORD_ID); sp.Flags = (EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE); sp.Version = ((short)0x2); EscherClientDataRecord clientData = new EscherClientDataRecord(); clientData.RecordId = (EscherClientDataRecord.RECORD_ID); clientData.Options = ((short)(0x0000)); EscherOptRecord optRecord = new EscherOptRecord(); optRecord.SetEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, LINESTYLE_SOLID)); optRecord.SetEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008)); // optRecord.SetEscherProperty(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, LINEWIDTH_DEFAULT)); optRecord.SetEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, FILL__FILLCOLOR_DEFAULT)); optRecord.SetEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, LINESTYLE__COLOR_DEFAULT)); optRecord.SetEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, NO_FILLHITTEST_FALSE)); optRecord.SetEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008)); optRecord.SetEscherProperty(new EscherShapePathProperty(EscherProperties.GEOMETRY__SHAPEPATH, EscherShapePathProperty.COMPLEX)); optRecord.SetEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x080000)); optRecord.RecordId = EscherOptRecord.RECORD_ID; EscherTextboxRecord escherTextbox = new EscherTextboxRecord(); escherTextbox.RecordId = (EscherTextboxRecord.RECORD_ID); escherTextbox.Options = (short)0x0000; spContainer.AddChildRecord(sp); spContainer.AddChildRecord(optRecord); spContainer.AddChildRecord(this.Anchor.GetEscherAnchor()); spContainer.AddChildRecord(clientData); spContainer.AddChildRecord(escherTextbox); return(spContainer); }
/// <summary> /// Creates the lowerlevel escher records for this shape. /// </summary> /// <param name="hssfShape">The HSSF shape.</param> /// <param name="shapeId">The shape id.</param> /// <returns></returns> private EscherContainerRecord CreateSpContainer(HSSFSimpleShape hssfShape, int shapeId) { HSSFPicture shape = (HSSFPicture)hssfShape; EscherContainerRecord spContainer = new EscherContainerRecord(); EscherSpRecord sp = new EscherSpRecord(); EscherOptRecord opt = new EscherOptRecord(); EscherRecord anchor; EscherClientDataRecord clientData = new EscherClientDataRecord(); spContainer.RecordId = EscherContainerRecord.SP_CONTAINER; spContainer.Options = (short)0x000F; sp.RecordId = EscherSpRecord.RECORD_ID; sp.Options = (short)((EscherAggregate.ST_PICTUREFRAME << 4) | 0x2); sp.ShapeId = shapeId; sp.Flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE; opt.RecordId = EscherOptRecord.RECORD_ID; // opt.AddEscherProperty( new EscherBoolProperty( EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x00800080 ) ; opt.AddEscherProperty(new EscherSimpleProperty(EscherProperties.BLIP__BLIPTODISPLAY, false, true, shape.PictureIndex)); // opt.AddEscherProperty( new EscherComplexProperty( EscherProperties.BLIP__BLIPFILENAME, true, new byte[] { (byte)0x74, (byte)0x00, (byte)0x65, (byte)0x00, (byte)0x73, (byte)0x00, (byte)0x74, (byte)0x00, (byte)0x00, (byte)0x00 } ) ; // opt.AddEscherProperty( new EscherSimpleProperty( EscherProperties.Fill__FillTYPE, 0x00000003 ) ; AddStandardOptions(shape, opt); HSSFAnchor userAnchor = shape.Anchor; if (userAnchor.IsHorizontallyFlipped) { sp.Flags = sp.Flags | EscherSpRecord.FLAG_FLIPHORIZ; } if (userAnchor.IsVerticallyFlipped) { sp.Flags = sp.Flags | EscherSpRecord.FLAG_FLIPVERT; } anchor = CreateAnchor(userAnchor); clientData.RecordId = EscherClientDataRecord.RECORD_ID; clientData.Options = (short)0x0000; spContainer.AddChildRecord(sp); spContainer.AddChildRecord(opt); spContainer.AddChildRecord(anchor); spContainer.AddChildRecord(clientData); return(spContainer); }
/** * Create a new Shape * * @param isChild <code>true</code> if the Line is inside a group, <code>false</code> otherwise * @return the record Container which holds this shape */ protected EscherContainerRecord CreateSpContainer(bool IsChild) { _escherContainer = new EscherContainerRecord(); _escherContainer.SetRecordId(EscherContainerRecord.SP_CONTAINER); _escherContainer.SetOptions((short)15); EscherSpRecord sp = new EscherSpRecord(); int flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE; if (isChild) { flags |= EscherSpRecord.FLAG_CHILD; } sp.SetFlags(flags); _escherContainer.AddChildRecord(sp); EscherOptRecord opt = new EscherOptRecord(); opt.SetRecordId(EscherOptRecord.RECORD_ID); _escherContainer.AddChildRecord(opt); EscherRecord anchor; if (isChild) { anchor = new EscherChildAnchorRecord(); } else { anchor = new EscherClientAnchorRecord(); //hack. internal variable EscherClientAnchorRecord.shortRecord can be //Initialized only in FillFields(). We need to Set shortRecord=false; byte[] header = new byte[16]; LittleEndian.PutUshort(header, 0, 0); LittleEndian.PutUshort(header, 2, 0); LittleEndian.PutInt(header, 4, 8); anchor.FillFields(header, 0, null); } _escherContainer.AddChildRecord(anchor); return(_escherContainer); }
/// <summary> /// Creates the lowerlevel escher records for this shape. /// </summary> /// <param name="hssfShape">The HSSF shape.</param> /// <param name="shapeId">The shape id.</param> /// <returns></returns> private EscherContainerRecord CreateSpContainer(HSSFSimpleShape hssfShape, int shapeId) { HSSFShape shape = hssfShape; EscherContainerRecord spContainer = new EscherContainerRecord(); EscherSpRecord sp = new EscherSpRecord(); EscherOptRecord opt = new EscherOptRecord(); EscherRecord anchor = new EscherClientAnchorRecord(); EscherClientDataRecord clientData = new EscherClientDataRecord(); spContainer.RecordId = EscherContainerRecord.SP_CONTAINER; spContainer.Options = (short)0x000F; sp.RecordId = EscherSpRecord.RECORD_ID; sp.Options = (short)((EscherAggregate.ST_LINE << 4) | 0x2); sp.ShapeId = shapeId; sp.Flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE; opt.RecordId = EscherOptRecord.RECORD_ID; opt.AddEscherProperty(new EscherShapePathProperty(EscherProperties.GEOMETRY__SHAPEPATH, EscherShapePathProperty.COMPLEX)); opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 1048592)); AddStandardOptions(shape, opt); HSSFAnchor userAnchor = shape.Anchor; if (userAnchor.IsHorizontallyFlipped) { sp.Flags = sp.Flags | EscherSpRecord.FLAG_FLIPHORIZ; } if (userAnchor.IsVerticallyFlipped) { sp.Flags = sp.Flags | EscherSpRecord.FLAG_FLIPVERT; } anchor = CreateAnchor(userAnchor); clientData.RecordId = EscherClientDataRecord.RECORD_ID; clientData.Options = ((short)0x0000); spContainer.AddChildRecord(sp); spContainer.AddChildRecord(opt); spContainer.AddChildRecord(anchor); spContainer.AddChildRecord(clientData); return(spContainer); }
/// <summary> /// Create a new simple shape Under this Group. /// </summary> /// <param name="anchor">the position of the shape.</param> /// <returns>the shape</returns> public HSSFSimpleShape CreateShape(HSSFChildAnchor anchor) { HSSFSimpleShape shape = new HSSFSimpleShape(this, anchor); shape.Parent = this; shape.Anchor = anchor; shapes.Add(shape); OnCreate(shape); EscherSpRecord sp = (EscherSpRecord)shape.GetEscherContainer().GetChildById(EscherSpRecord.RECORD_ID); if (shape.Anchor.IsHorizontallyFlipped) { sp.Flags = (sp.Flags | EscherSpRecord.FLAG_FLIPHORIZ); } if (shape.Anchor.IsVerticallyFlipped) { sp.Flags = (sp.Flags | EscherSpRecord.FLAG_FLIPVERT); } return(shape); }
public void TestRecordSize() { DrawingGroupRecord r = new DrawingGroupRecord(); Assert.AreEqual(4, r.RecordSize); EscherSpRecord sp = new EscherSpRecord(); sp.RecordId = (EscherSpRecord.RECORD_ID); sp.Options = ((short)0x1111); sp.Flags = (-1); sp.ShapeId = (-1); EscherContainerRecord dggContainer = new EscherContainerRecord(); dggContainer.Options = ((short)0x000F); dggContainer.RecordId = unchecked ((short)0xF000); dggContainer.AddChildRecord(sp); r.AddEscherRecord(dggContainer); Assert.AreEqual(28, r.RecordSize); byte[] data = new byte[28]; int size = r.Serialize(0, data); Assert.AreEqual("[EB, 00, 18, 00, 0F, 00, 00, F0, 10, 00, 00, 00, 11, 11, 0A, F0, 08, 00, 00, 00, FF, FF, FF, FF, FF, FF, FF, FF]", HexDump.ToHex(data)); Assert.AreEqual(28, size); Assert.AreEqual(24, dggContainer.RecordSize); r = new DrawingGroupRecord(); r.RawData = (new byte[MAX_DATA_SIZE]); Assert.AreEqual(MAX_RECORD_SIZE, r.RecordSize); r.RawData = (new byte[MAX_DATA_SIZE + 1]); Assert.AreEqual(MAX_RECORD_SIZE + 5, r.RecordSize); r.RawData = (new byte[MAX_DATA_SIZE * 2]); Assert.AreEqual(MAX_RECORD_SIZE * 2, r.RecordSize); r.RawData = (new byte[MAX_DATA_SIZE * 2 + 1]); Assert.AreEqual(MAX_RECORD_SIZE * 2 + 5, r.RecordSize); }
/** * Returns the anchor (the bounding box rectangle) of this shape. * All coordinates are expressed in points (72 dpi). * * @return the anchor of this shape */ //public Rectangle GetAnchor() //{ // Rectangle anchor2d = GetAnchor2D(); // return anchor2d.Bounds; //} /** * Returns the anchor (the bounding box rectangle) of this shape. * All coordinates are expressed in points (72 dpi). * * @return the anchor of this shape */ public Rectangle GetAnchor2D() { EscherSpRecord spRecord = _escherContainer.GetChildById(EscherSpRecord.RECORD_ID); int flags = spRecord.Flags; Rectangle anchor; if ((flags & EscherSpRecord.FLAG_CHILD) != 0) { EscherChildAnchorRecord rec = (EscherChildAnchorRecord)GetEscherChild(_escherContainer, EscherChildAnchorRecord.RECORD_ID); anchor = new Rectangle(); if (rec == null) { logger.Log(POILogger.WARN, "EscherSpRecord.FLAG_CHILD is Set but EscherChildAnchorRecord was not found"); EscherClientAnchorRecord clrec = (EscherClientAnchorRecord)GetEscherChild(_escherContainer, EscherClientAnchorRecord.RECORD_ID); anchor = new Rectangle(); anchor.X = clrec.Col1 * POINT_DPI / MASTER_DPI; anchor.Y = clrec.Flag * POINT_DPI / MASTER_DPI; anchor.Width = (clrec.Dx1 - clrec.Col1) * POINT_DPI / MASTER_DPI; anchor.Height = (clrec.Row1 - clrec.Flag) * POINT_DPI / MASTER_DPI; } else { anchor.X = rec.Dx1 * POINT_DPI / MASTER_DPI; anchor.Y = rec.Dy1 * POINT_DPI / MASTER_DPI; anchor.Width = (rec.Dx2 - rec.Dx1) * POINT_DPI / MASTER_DPI; anchor.Height = (rec.Dy2 - rec.Dy1) * POINT_DPI / MASTER_DPI; } } else { EscherClientAnchorRecord rec = (EscherClientAnchorRecord)GetEscherChild(_escherContainer, EscherClientAnchorRecord.RECORD_ID); anchor = new Rectangle(); anchor.X = rec.Col1 * POINT_DPI / MASTER_DPI; anchor.Y = rec.Flag * POINT_DPI / MASTER_DPI; anchor.Width = (rec.Dx1 - rec.Col1) * POINT_DPI / MASTER_DPI; anchor.Height = (rec.Row1 - rec.Flag) * POINT_DPI / MASTER_DPI; } return(anchor); }
/** * Sets the anchor (the bounding box rectangle) of this shape. * All coordinates should be expressed in points (72 dpi). * * @param anchor new anchor */ public void SetAnchor(Rectangle anchor) { EscherSpRecord spRecord = _escherContainer.GetChildById(EscherSpRecord.RECORD_ID); int flags = spRecord.Flags; if ((flags & EscherSpRecord.FLAG_CHILD) != 0) { EscherChildAnchorRecord rec = (EscherChildAnchorRecord)GetEscherChild(_escherContainer, EscherChildAnchorRecord.RECORD_ID); rec.Dx1 = ((int)(anchor.X * MASTER_DPI / POINT_DPI)); rec.Dy1 = ((int)(anchor.Y * MASTER_DPI / POINT_DPI)); rec.Dx2 = ((int)((anchor.Width + anchor.X) * MASTER_DPI / POINT_DPI)); rec.Dy2 = ((int)((anchor.Height + anchor.Y) * MASTER_DPI / POINT_DPI)); } else { EscherClientAnchorRecord rec = (EscherClientAnchorRecord)GetEscherChild(_escherContainer, EscherClientAnchorRecord.RECORD_ID); rec.Flag = ((short)(anchor.Y * MASTER_DPI / POINT_DPI)); rec.Col1 = ((short)(anchor.X * MASTER_DPI / POINT_DPI)); rec.Dx1 = ((short)(((anchor.Width + anchor.X) * MASTER_DPI / POINT_DPI))); rec.Row1 = ((short)(((anchor.Height + anchor.Y) * MASTER_DPI / POINT_DPI))); } }
private void ConvertPatriarch(HSSFPatriarch patriarch) { EscherContainerRecord dgContainer = new EscherContainerRecord(); EscherDgRecord dg; EscherContainerRecord spgrContainer = new EscherContainerRecord(); EscherContainerRecord spContainer1 = new EscherContainerRecord(); EscherSpgrRecord spgr = new EscherSpgrRecord(); EscherSpRecord sp1 = new EscherSpRecord(); dgContainer.RecordId = EscherContainerRecord.DG_CONTAINER; dgContainer.Options = (short)0x000F; dg = drawingManager.CreateDgRecord(); drawingGroupId = dg.DrawingGroupId; // dg.Options( (short) ( drawingId << 4 ) ); // dg.NumShapes( GetNumberOfShapes( patriarch ) ); // dg.LastMSOSPID( 0 ); // populated after all shape id's are assigned. spgrContainer.RecordId = EscherContainerRecord.SPGR_CONTAINER; spgrContainer.Options = (short)0x000F; spContainer1.RecordId = EscherContainerRecord.SP_CONTAINER; spContainer1.Options = (short)0x000F; spgr.RecordId = EscherSpgrRecord.RECORD_ID; spgr.Options = (short)0x0001; // version spgr.RectX1 = patriarch.X1; spgr.RectY1 = patriarch.Y1; spgr.RectX2 = patriarch.X2; spgr.RectY2 = patriarch.Y2; sp1.RecordId = EscherSpRecord.RECORD_ID; sp1.Options = (short)0x0002; sp1.ShapeId = drawingManager.AllocateShapeId(dg.DrawingGroupId); sp1.Flags = EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_PATRIARCH; dgContainer.AddChildRecord(dg); dgContainer.AddChildRecord(spgrContainer); spgrContainer.AddChildRecord(spContainer1); spContainer1.AddChildRecord(spgr); spContainer1.AddChildRecord(sp1); AddEscherRecord(dgContainer); }
/** * Create a new ShapeGroup and create an instance of <code>EscherSpgrContainer</code> which represents a group of shapes */ protected EscherContainerRecord CreateSpContainer(bool IsChild) { EscherContainerRecord spgr = new EscherContainerRecord(); spgr.SetRecordId(EscherContainerRecord.SPGR_CONTAINER); spgr.SetOptions((short)15); //The group itself is a shape, and always appears as the first EscherSpContainer in the group Container. EscherContainerRecord spcont = new EscherContainerRecord(); spcont.SetRecordId(EscherContainerRecord.SP_CONTAINER); spcont.SetOptions((short)15); EscherSpgrRecord spg = new EscherSpgrRecord(); spg.SetOptions((short)1); spcont.AddChildRecord(spg); EscherSpRecord sp = new EscherSpRecord(); short type = (ShapeTypes.NotPrimitive << 4) + 2; sp.SetOptions(type); sp.SetFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_GROUP); spcont.AddChildRecord(sp); EscherClientAnchorRecord anchor = new EscherClientAnchorRecord(); spcont.AddChildRecord(anchor); spgr.AddChildRecord(spcont); return spgr; }
/** * Converts the Records into UserModel * objects on the bound HSSFPatriarch */ public void ConvertRecordsToUserModel() { if (patriarch == null) { throw new InvalidOperationException("Must call SetPatriarch() first"); } // The top level container ought to have // the DgRecord and the container of one container // per shape Group (patriach overall first) EscherContainerRecord topContainer = (EscherContainerRecord)GetEscherContainer(); if (topContainer == null) { return; } topContainer = (EscherContainerRecord) topContainer.ChildContainers[0]; IList <EscherContainerRecord> tcc = topContainer.ChildContainers; if (tcc.Count == 0) { throw new InvalidOperationException("No child escher containers at the point that should hold the patriach data, and one container per top level shape!"); } // First up, Get the patriach position // This Is in the first EscherSpgrRecord, in // the first container, with a EscherSRecord too EscherContainerRecord patriachContainer = (EscherContainerRecord)tcc[0]; EscherSpgrRecord spgr = null; for (IEnumerator it = patriachContainer.ChildRecords.GetEnumerator(); it.MoveNext();) { EscherRecord r = (EscherRecord)it.Current; if (r is EscherSpgrRecord) { spgr = (EscherSpgrRecord)r; break; } } if (spgr != null) { patriarch.SetCoordinates( spgr.RectX1, spgr.RectY1, spgr.RectX2, spgr.RectY2 ); } // Now Process the containers for each Group // and objects for (int i = 1; i < tcc.Count; i++) { EscherContainerRecord shapeContainer = (EscherContainerRecord)tcc[i]; //Console.Error.WriteLine("\n\n*****\n\n"); //Console.Error.WriteLine(shapeContainer); // Could be a Group, or a base object if (shapeContainer.RecordId == EscherContainerRecord.SPGR_CONTAINER) { if (shapeContainer.ChildRecords.Count > 0) { // Group HSSFShapeGroup group = new HSSFShapeGroup(null, new HSSFClientAnchor()); patriarch.Children.Add(group); EscherContainerRecord groupContainer = (EscherContainerRecord)shapeContainer.GetChild(0); ConvertRecordsToUserModel(groupContainer, group); } } else if (shapeContainer.RecordId == EscherContainerRecord.SP_CONTAINER) { EscherSpRecord spRecord = shapeContainer.GetChildById(EscherSpRecord.RECORD_ID); int type = spRecord.Options >> 4; switch (type) { case ST_TEXTBOX: // TextBox HSSFTextbox box = new HSSFTextbox(null, new HSSFClientAnchor()); patriarch.Children.Add(box); ConvertRecordsToUserModel(shapeContainer, box); break; case ST_PICTUREFRAME: // Duplicated from // org.apache.poi.hslf.model.Picture.getPictureIndex() EscherOptRecord opt = (EscherOptRecord)GetEscherChild(shapeContainer, EscherOptRecord.RECORD_ID); EscherSimpleProperty prop = (EscherSimpleProperty)opt.Lookup(EscherProperties.BLIP__BLIPTODISPLAY); if (prop != null) { int pictureIndex = prop.PropertyValue; EscherClientAnchorRecord anchorRecord = (EscherClientAnchorRecord)GetEscherChild(shapeContainer, EscherClientAnchorRecord.RECORD_ID); HSSFClientAnchor anchor = new HSSFClientAnchor(); anchor.Col1 = anchorRecord.Col1; anchor.Col2 = anchorRecord.Col2; anchor.Dx1 = anchorRecord.Dx1; anchor.Dx2 = anchorRecord.Dx2; anchor.Dy1 = anchorRecord.Dy1; anchor.Dy2 = anchorRecord.Dy2; anchor.Row1 = anchorRecord.Row1; anchor.Row2 = anchorRecord.Row2; HSSFPicture picture = new HSSFPicture(null, anchor); picture.PictureIndex = pictureIndex; patriarch.AddShape(picture); } break; } } else { // Base level ConvertRecordsToUserModel(shapeContainer, patriarch); } } // Now, clear any trace of what records make up // the patriarch // Otherwise, everything will go horribly wrong // when we try to Write out again.... // clearEscherRecords(); drawingManager.GetDgg().FileIdClusters = new EscherDggRecord.FileIdCluster[0]; // TODO: Support Converting our records // back into shapes log.Log(POILogger.WARN, "Not Processing objects into Patriarch!"); }
private void ConvertGroup(HSSFShapeGroup shape, EscherContainerRecord escherParent, Hashtable shapeToObj) { EscherContainerRecord spgrContainer = new EscherContainerRecord(); EscherContainerRecord spContainer = new EscherContainerRecord(); EscherSpgrRecord spgr = new EscherSpgrRecord(); EscherSpRecord sp = new EscherSpRecord(); EscherOptRecord opt = new EscherOptRecord(); EscherRecord anchor; EscherClientDataRecord clientData = new EscherClientDataRecord(); spgrContainer.RecordId = EscherContainerRecord.SPGR_CONTAINER; spgrContainer.Options = (short)0x000F; spContainer.RecordId = EscherContainerRecord.SP_CONTAINER; spContainer.Options = (short)0x000F; spgr.RecordId = EscherSpgrRecord.RECORD_ID; spgr.Options = (short)0x0001; spgr.RectX1 = shape.X1; spgr.RectY1 = shape.Y1; spgr.RectX2 = shape.X2; spgr.RectY2 = shape.Y2; sp.RecordId = EscherSpRecord.RECORD_ID; sp.Options = (short)0x0002; int shapeId = drawingManager.AllocateShapeId(drawingGroupId); sp.ShapeId = shapeId; if (shape.Anchor is HSSFClientAnchor) { sp.Flags = EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_HAVEANCHOR; } else { sp.Flags = EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_CHILD; } opt.RecordId = EscherOptRecord.RECORD_ID; opt.Options = (short)0x0023; opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x00040004)); opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00080000)); anchor = ConvertAnchor.CreateAnchor(shape.Anchor); // clientAnchor.Col1( ( (HSSFClientAnchor) shape.Anchor ).Col1 ); // clientAnchor.Row1( (short) ( (HSSFClientAnchor) shape.Anchor ).Row1 ); // clientAnchor.Dx1( (short) shape.Anchor.Dx1 ); // clientAnchor.Dy1( (short) shape.Anchor.Dy1 ); // clientAnchor.Col2( ( (HSSFClientAnchor) shape.Anchor ).Col2 ); // clientAnchor.Row2( (short) ( (HSSFClientAnchor) shape.Anchor ).Row2 ); // clientAnchor.Dx2( (short) shape.Anchor.Dx2 ); // clientAnchor.Dy2( (short) shape.Anchor.Dy2 ); clientData.RecordId = (EscherClientDataRecord.RECORD_ID); clientData.Options = ((short)0x0000); spgrContainer.AddChildRecord(spContainer); spContainer.AddChildRecord(spgr); spContainer.AddChildRecord(sp); spContainer.AddChildRecord(opt); spContainer.AddChildRecord(anchor); spContainer.AddChildRecord(clientData); ObjRecord obj = new ObjRecord(); CommonObjectDataSubRecord cmo = new CommonObjectDataSubRecord(); cmo.ObjectType = CommonObjectType.GROUP; cmo.ObjectId = shapeId; cmo.IsLocked = true; cmo.IsPrintable = true; cmo.IsAutoFill = true; cmo.IsAutoline = true; GroupMarkerSubRecord gmo = new GroupMarkerSubRecord(); EndSubRecord end = new EndSubRecord(); obj.AddSubRecord(cmo); obj.AddSubRecord(gmo); obj.AddSubRecord(end); shapeToObj[clientData] = obj; escherParent.AddChildRecord(spgrContainer); ConvertShapes(shape, spgrContainer, shapeToObj); }