protected override EscherContainerRecord CreateSpContainer() { EscherContainerRecord spContainer = base.CreateSpContainer(); EscherOptRecord opt = (EscherOptRecord)spContainer.GetChildById(EscherOptRecord.RECORD_ID); opt.RemoveEscherProperty(EscherProperties.LINESTYLE__LINEDASHING); opt.RemoveEscherProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH); spContainer.RemoveChildRecord(spContainer.GetChildById(EscherTextboxRecord.RECORD_ID)); return(spContainer); }
public static HSSFAnchor CreateAnchorFromEscher(EscherContainerRecord container) { if (null != container.GetChildById(EscherChildAnchorRecord.RECORD_ID)) { return(new HSSFChildAnchor((EscherChildAnchorRecord)container.GetChildById(EscherChildAnchorRecord.RECORD_ID))); } else { if (null != container.GetChildById(EscherClientAnchorRecord.RECORD_ID)) { return(new HSSFClientAnchor((EscherClientAnchorRecord)container.GetChildById(EscherClientAnchorRecord.RECORD_ID))); } return(null); } }
//int lineStyleColor = 0x08000040; //int fillColor = 0x08000009; //int lineWidth = LINEWIDTH_DEFAULT; //LineStyle lineStyle = LineStyle.Solid; //bool noFill = false; /** * creates shapes from existing file * @param spContainer * @param objRecord */ public HSSFShape(EscherContainerRecord spContainer, ObjRecord objRecord) { this._escherContainer = spContainer; this._objRecord = objRecord; this._optRecord = (EscherOptRecord)spContainer.GetChildById(EscherOptRecord.RECORD_ID); this.anchor = HSSFAnchor.CreateAnchorFromEscher(spContainer); }
internal override void AfterInsert(HSSFPatriarch patriarch) { EscherAggregate agg = patriarch.GetBoundAggregate(); EscherContainerRecord containerRecord = (EscherContainerRecord)GetEscherContainer().GetChildById(EscherContainerRecord.SP_CONTAINER); agg.AssociateShapeToObjRecord(containerRecord.GetChildById(EscherClientDataRecord.RECORD_ID), GetObjRecord()); }
public void TestHSSFShapeCompatibility() { HSSFSimpleShape shape = new HSSFSimpleShape(null, new HSSFClientAnchor()); shape.ShapeType = (HSSFSimpleShape.OBJECT_TYPE_LINE); Assert.AreEqual(0x08000040, shape.LineStyleColor); Assert.AreEqual(0x08000009, shape.FillColor); Assert.AreEqual(HSSFShape.LINEWIDTH_DEFAULT, shape.LineWidth); Assert.AreEqual(HSSFShape.LINESTYLE_SOLID, shape.LineStyle); Assert.IsFalse(shape.IsNoFill); AbstractShape sp = AbstractShape.CreateShape(shape, 1); EscherContainerRecord spContainer = sp.SpContainer; EscherOptRecord opt = spContainer.GetChildById(EscherOptRecord.RECORD_ID) as EscherOptRecord; Assert.AreEqual(7, opt.EscherProperties.Count); Assert.AreEqual(true, ((EscherBoolProperty)opt.Lookup(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE)).IsTrue); Assert.AreEqual(0x00000004, ((EscherSimpleProperty)opt.Lookup(EscherProperties.GEOMETRY__SHAPEPATH)).PropertyValue); Assert.AreEqual(0x08000009, ((EscherSimpleProperty)opt.Lookup(EscherProperties.FILL__FILLCOLOR)).PropertyValue); Assert.AreEqual(true, ((EscherBoolProperty)opt.Lookup(EscherProperties.FILL__NOFILLHITTEST)).IsTrue); Assert.AreEqual(0x08000040, ((EscherSimpleProperty)opt.Lookup(EscherProperties.LINESTYLE__COLOR)).PropertyValue); Assert.AreEqual(true, ((EscherBoolProperty)opt.Lookup(EscherProperties.LINESTYLE__NOLINEDRAWDASH)).IsTrue); Assert.AreEqual(true, ((EscherBoolProperty)opt.Lookup(EscherProperties.GROUPSHAPE__PRINT)).IsTrue); }
private int GetTertiaryPropertyValue(int propertyId, int defaultValue) { EscherContainerRecord shapeDescription = od.GetEscherShapeRecordContainer(GetShapeId()); if (shapeDescription == null) { return(defaultValue); } EscherRecord escherTertiaryOptRecord = (EscherRecord)shapeDescription .GetChildById(EscherTertiaryOptRecord.RECORD_ID); if (escherTertiaryOptRecord == null) { return(defaultValue); } EscherSimpleProperty escherProperty = (EscherSimpleProperty)((EscherOptRecord)escherTertiaryOptRecord) .Lookup(propertyId); if (escherProperty == null) { return(defaultValue); } int value = escherProperty.PropertyValue; return(value); }
public byte[] GetPictureData() { EscherContainerRecord shapeDescription = od.GetEscherShapeRecordContainer(GetShapeId()); if (shapeDescription == null) { return(null); } EscherRecord escherOptRecord = (EscherRecord)shapeDescription .GetChildById(EscherOptRecord.RECORD_ID); if (escherOptRecord == null) { return(null); } EscherSimpleProperty escherProperty = (EscherSimpleProperty)((EscherOptRecord)escherOptRecord) .Lookup(EscherProperties.BLIP__BLIPTODISPLAY); if (escherProperty == null) { return(null); } int bitmapIndex = escherProperty.PropertyValue; EscherBlipRecord escherBlipRecord = od.GetBitmapRecord(bitmapIndex); if (escherBlipRecord == null) { return(null); } return(escherBlipRecord.PictureData); }
public void TestCorrectOrderInOptRecord() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch() as HSSFPatriarch; HSSFTextbox textbox = patriarch.CreateTextbox(new HSSFClientAnchor()) as HSSFTextbox; EscherOptRecord opt = HSSFTestHelper.GetOptRecord(textbox); String opt1Str = opt.ToXml(); textbox.FillColor = textbox.FillColor; EscherContainerRecord Container = HSSFTestHelper.GetEscherContainer(textbox); EscherOptRecord optRecord = Container.GetChildById(EscherOptRecord.RECORD_ID) as EscherOptRecord; Assert.AreEqual(opt1Str, optRecord.ToXml()); textbox.LineStyle = textbox.LineStyle; Assert.AreEqual(opt1Str, optRecord.ToXml()); textbox.LineWidth = textbox.LineWidth; Assert.AreEqual(opt1Str, optRecord.ToXml()); textbox.LineStyleColor = textbox.LineStyleColor; Assert.AreEqual(opt1Str, optRecord.ToXml()); wb.Close(); }
/// <summary> /// Create a new shape with the specified parent and anchor. /// </summary> /// <param name="parent">The parent.</param> /// <param name="anchor">The anchor.</param> public HSSFShape(HSSFShape parent, HSSFAnchor anchor) { this.parent = parent; this.anchor = anchor; this._escherContainer = CreateSpContainer(); _optRecord = (EscherOptRecord)_escherContainer.GetChildById(EscherOptRecord.RECORD_ID); _objRecord = CreateObjRecord(); }
/// <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) { _boundAggregate = boundAggregate; _sheet = sheet; _mainSpgrContainer = _boundAggregate.GetEscherContainer().ChildContainers[0]; EscherContainerRecord spContainer = (EscherContainerRecord)_boundAggregate.GetEscherContainer() .ChildContainers[0].GetChild(0); _spgrRecord = (EscherSpgrRecord)spContainer.GetChildById(EscherSpgrRecord.RECORD_ID); BuildShapeTree(); }
public static Shape CreateSimpeShape(EscherContainerRecord spContainer, Shape parent){ Shape shape = null; EscherSpRecord spRecord = spContainer.GetChildById(EscherSpRecord.RECORD_ID); int type = spRecord.GetOptions() >> 4; switch (type){ case ShapeTypes.TextBox: shape = new TextBox(spContainer, parent); break; case ShapeTypes.HostControl: case ShapeTypes.PictureFrame: { InteractiveInfo info = (InteractiveInfo)getClientDataRecord(spContainer, RecordTypes.InteractiveInfo.typeID); OEShapeAtom oes = (OEShapeAtom)getClientDataRecord(spContainer, RecordTypes.OEShapeAtom.typeID); if(info != null && info.GetInteractiveInfoAtom() != null){ switch(info.GetInteractiveInfoAtom().GetAction()){ case InteractiveInfoAtom.ACTION_OLE: shape = new OLEShape(spContainer, parent); break; case InteractiveInfoAtom.ACTION_MEDIA: shape = new MovieShape(spContainer, parent); break; default: break; } } else if (oes != null){ shape = new OLEShape(spContainer, parent); } if(shape == null) shape = new Picture(spContainer, parent); break; } case ShapeTypes.Line: shape = new Line(spContainer, parent); break; case ShapeTypes.NotPrimitive: { EscherOptRecord opt = (EscherOptRecord)Shape.GetEscherChild(spContainer, EscherOptRecord.RECORD_ID); EscherProperty prop = Shape.GetEscherProperty(opt, EscherProperties.GEOMETRY__VERTICES); if(prop != null) shape = new Freeform(spContainer, parent); else { logger.log(POILogger.WARN, "Creating AutoShape for a NotPrimitive shape"); shape = new AutoShape(spContainer, parent); } break; } default: shape = new AutoShape(spContainer, parent); break; } return shape; }
protected override EscherContainerRecord CreateSpContainer() { EscherContainerRecord spContainer = base.CreateSpContainer(); EscherOptRecord opt = (EscherOptRecord)spContainer.GetChildById(EscherOptRecord.RECORD_ID); opt.RemoveEscherProperty(EscherProperties.TEXT__TEXTLEFT); opt.RemoveEscherProperty(EscherProperties.TEXT__TEXTRIGHT); opt.RemoveEscherProperty(EscherProperties.TEXT__TEXTTOP); opt.RemoveEscherProperty(EscherProperties.TEXT__TEXTBOTTOM); opt.SetEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, false, false, GROUP_SHAPE_PROPERTY_DEFAULT_VALUE)); return(spContainer); }
/** * 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!"); }
/** * Adds a new OLE Package Shape * * @param anchor the client anchor describes how this picture is * attached to the sheet. * @param storageId the storageId returned by {@Link HSSFWorkbook.AddOlePackage} * @param pictureIndex the index of the picture (used as preview image) in the * workbook collection of pictures. * * @return newly Created shape */ public HSSFObjectData CreateObjectData(HSSFClientAnchor anchor, int storageId, int pictureIndex) { ObjRecord obj = new ObjRecord(); CommonObjectDataSubRecord ftCmo = new CommonObjectDataSubRecord(); ftCmo.ObjectType = (/*setter*/ CommonObjectType.Picture); // ftCmo.ObjectId=(/*setter*/oleShape.ShapeId); ... will be Set by onCreate(...) ftCmo.IsLocked = (/*setter*/ true); ftCmo.IsPrintable = (/*setter*/ true); ftCmo.IsAutoFill = (/*setter*/ true); ftCmo.IsAutoline = (/*setter*/ true); ftCmo.Reserved1 = (/*setter*/ 0); ftCmo.Reserved2 = (/*setter*/ 0); ftCmo.Reserved3 = (/*setter*/ 0); obj.AddSubRecord(ftCmo); // FtCf (pictFormat) FtCfSubRecord ftCf = new FtCfSubRecord(); HSSFPictureData pictData = Sheet.Workbook.GetAllPictures()[(pictureIndex - 1)] as HSSFPictureData; switch ((PictureType)pictData.Format) { case PictureType.WMF: case PictureType.EMF: // this needs patch #49658 to be applied to actually work ftCf.Flags = (/*setter*/ FtCfSubRecord.METAFILE_BIT); break; case PictureType.DIB: case PictureType.PNG: case PictureType.JPEG: case PictureType.PICT: ftCf.Flags = (/*setter*/ FtCfSubRecord.BITMAP_BIT); break; } obj.AddSubRecord(ftCf); // FtPioGrbit (pictFlags) FtPioGrbitSubRecord ftPioGrbit = new FtPioGrbitSubRecord(); ftPioGrbit.SetFlagByBit(FtPioGrbitSubRecord.AUTO_PICT_BIT, true); obj.AddSubRecord(ftPioGrbit); EmbeddedObjectRefSubRecord ftPictFmla = new EmbeddedObjectRefSubRecord(); ftPictFmla.SetUnknownFormulaData(new byte[] { 2, 0, 0, 0, 0 }); ftPictFmla.OLEClassName = (/*setter*/ "Paket"); ftPictFmla.SetStorageId(storageId); obj.AddSubRecord(ftPictFmla); obj.AddSubRecord(new EndSubRecord()); String entryName = "MBD" + HexDump.ToHex(storageId); DirectoryEntry oleRoot; try { DirectoryNode dn = (_sheet.Workbook as HSSFWorkbook).RootDirectory; if (dn == null) { throw new FileNotFoundException(); } oleRoot = (DirectoryEntry)dn.GetEntry(entryName); } catch (FileNotFoundException e) { throw new InvalidOperationException("trying to add ole shape without actually Adding data first - use HSSFWorkbook.AddOlePackage first", e); } // create picture shape, which need to be minimal modified for oleshapes HSSFPicture shape = new HSSFPicture(null, anchor); shape.PictureIndex = (/*setter*/ pictureIndex); EscherContainerRecord spContainer = shape.GetEscherContainer(); EscherSpRecord spRecord = spContainer.GetChildById(EscherSpRecord.RECORD_ID) as EscherSpRecord; spRecord.Flags = (/*setter*/ spRecord.Flags | EscherSpRecord.FLAG_OLESHAPE); HSSFObjectData oleShape = new HSSFObjectData(spContainer, obj, oleRoot); AddShape(oleShape); OnCreate(oleShape); return(oleShape); }
/** * build shape tree from escher container * @param container root escher container from which escher records must be taken * @param agg - EscherAggregate * @param out - shape container to which shapes must be added * @param root - node to create HSSFObjectData shapes */ public static void CreateShapeTree(EscherContainerRecord container, EscherAggregate agg, HSSFShapeContainer out1, DirectoryNode root) { if (container.RecordId == EscherContainerRecord.SPGR_CONTAINER) { ObjRecord obj = null; EscherClientDataRecord clientData = (EscherClientDataRecord)((EscherContainerRecord)container.GetChild(0)).GetChildById(EscherClientDataRecord.RECORD_ID); if (null != clientData) { obj = (ObjRecord)agg.GetShapeToObjMapping()[clientData]; } HSSFShapeGroup group = new HSSFShapeGroup(container, obj); IList <EscherContainerRecord> children = container.ChildContainers; // skip the first child record, it is group descriptor for (int i = 0; i < children.Count; i++) { EscherContainerRecord spContainer = children[(i)]; if (i != 0) { CreateShapeTree(spContainer, agg, group, root); } } out1.AddShape(group); } else if (container.RecordId == EscherContainerRecord.SP_CONTAINER) { Dictionary <EscherRecord, Record.Record> shapeToObj = agg.GetShapeToObjMapping(); ObjRecord objRecord = null; TextObjectRecord txtRecord = null; foreach (EscherRecord record in container.ChildRecords) { switch (record.RecordId) { case EscherClientDataRecord.RECORD_ID: objRecord = (ObjRecord)shapeToObj[(record)]; break; case EscherTextboxRecord.RECORD_ID: txtRecord = (TextObjectRecord)shapeToObj[(record)]; break; } } if (IsEmbeddedObject(objRecord)) { HSSFObjectData objectData = new HSSFObjectData(container, objRecord, root); out1.AddShape(objectData); return; } CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord)objRecord.SubRecords[0]; HSSFShape shape; switch (cmo.ObjectType) { case CommonObjectType.Picture: shape = new HSSFPicture(container, objRecord); break; case CommonObjectType.Rectangle: shape = new HSSFSimpleShape(container, objRecord, txtRecord); break; case CommonObjectType.Line: shape = new HSSFSimpleShape(container, objRecord); break; case CommonObjectType.ComboBox: shape = new HSSFCombobox(container, objRecord); break; case CommonObjectType.MicrosoftOfficeDrawing: EscherOptRecord optRecord = (EscherOptRecord)container.GetChildById(EscherOptRecord.RECORD_ID); EscherProperty property = optRecord.Lookup(EscherProperties.GEOMETRY__VERTICES); if (null != property) { shape = new HSSFPolygon(container, objRecord, txtRecord); } else { shape = new HSSFSimpleShape(container, objRecord, txtRecord); } break; case CommonObjectType.Text: shape = new HSSFTextbox(container, objRecord, txtRecord); break; case CommonObjectType.Comment: shape = new HSSFComment(container, objRecord, txtRecord, agg.GetNoteRecordByObj(objRecord)); break; default: shape = new HSSFSimpleShape(container, objRecord, txtRecord); break; } out1.AddShape(shape); } }
/** * @return type of the shape. * @see NPOI.HSLF.record.RecordTypes */ public int GetShapeType() { EscherSpRecord spRecord = _escherContainer.GetChildById(EscherSpRecord.RECORD_ID); return(spRecord.Options >> 4); }