/// <summary> /// Creates a simple shape. This includes such shapes as lines, rectangles, /// and ovals. /// </summary> /// <param name="anchor">the client anchor describes how this Group is attached /// to the sheet.</param> /// <returns>the newly created shape.</returns> public HSSFSimpleShape CreateSimpleShape(HSSFClientAnchor anchor) { HSSFSimpleShape shape = new HSSFSimpleShape(null, anchor); shape.Anchor = anchor; AddShape(shape); return shape; }
/// <summary> /// Creates a new Group record stored Under this patriarch. /// </summary> /// <param name="anchor">the client anchor describes how this Group is attached /// to the sheet.</param> /// <returns>the newly created Group.</returns> public HSSFShapeGroup CreateGroup(HSSFClientAnchor anchor) { HSSFShapeGroup group = new HSSFShapeGroup(null, anchor); group.Anchor = anchor; AddShape(group); return group; }
/// <summary> /// Creates a simple shape. This includes such shapes as lines, rectangles, /// and ovals. /// </summary> /// <param name="anchor">the client anchor describes how this Group is attached /// to the sheet.</param> /// <returns>the newly created shape.</returns> public HSSFSimpleShape CreateSimpleShape(HSSFClientAnchor anchor) { HSSFSimpleShape shape = new HSSFSimpleShape(null, anchor); shape.Anchor = anchor; AddShape(shape); return(shape); }
/// <summary> /// Creates a new Group record stored Under this patriarch. /// </summary> /// <param name="anchor">the client anchor describes how this Group is attached /// to the sheet.</param> /// <returns>the newly created Group.</returns> public HSSFShapeGroup CreateGroup(HSSFClientAnchor anchor) { HSSFShapeGroup group = new HSSFShapeGroup(null, anchor); group.Anchor = anchor; AddShape(group); return(group); }
/// <summary> /// Calculate the preferred size for this picture. /// </summary> /// <param name="scale">the amount by which image dimensions are multiplied relative to the original size.</param> /// <returns>HSSFClientAnchor with the preferred size for this image</returns> public HSSFClientAnchor GetPreferredSize(double scale) { HSSFClientAnchor anchor = (HSSFClientAnchor)Anchor; Size size = GetImageDimension(); double scaledWidth = size.Width * scale; double scaledHeight = size.Height * scale; float w = 0; //space in the leftmost cell w += GetColumnWidthInPixels(anchor.Col1) * (1 - (float)anchor.Dx1 / 1024); short col2 = (short)(anchor.Col1 + 1); int dx2 = 0; while (w < scaledWidth) { w += GetColumnWidthInPixels(col2++); } if (w > scaledWidth) { //calculate dx2, offset in the rightmost cell col2--; double cw = GetColumnWidthInPixels(col2); double delta = w - scaledWidth; dx2 = (int)((cw - delta) / cw * 1024); } anchor.Col2 = col2; anchor.Dx2 = dx2; float h = 0; h += (1 - (float)anchor.Dy1 / 256) * GetRowHeightInPixels(anchor.Row1); int row2 = anchor.Row1 + 1; int dy2 = 0; while (h < scaledHeight) { h += GetRowHeightInPixels(row2++); } if (h > scaledHeight) { row2--; double ch = GetRowHeightInPixels(row2); double delta = h - scaledHeight; dy2 = (int)((ch - delta) / ch * 256); } anchor.Row2 = row2; anchor.Dy2 = dy2; return(anchor); }
/// <summary> /// Creates a picture. /// </summary> /// <param name="anchor">the client anchor describes how this Group is attached /// to the sheet.</param> /// <param name="pictureIndex">Index of the picture.</param> /// <returns>the newly created shape.</returns> public IPicture CreatePicture(HSSFClientAnchor anchor, int pictureIndex) { HSSFPicture shape = new HSSFPicture(null, (HSSFClientAnchor)anchor); shape.PictureIndex = pictureIndex; shape.Anchor = (HSSFClientAnchor)anchor; AddShape(shape); EscherBSERecord bse = (_sheet.Workbook as HSSFWorkbook).Workbook.GetBSERecord(pictureIndex); bse.Ref = (bse.Ref + 1); return(shape); }
/// <summary> /// Reset the image to the original size. /// </summary> public void Resize(double scale) { HSSFClientAnchor anchor = (HSSFClientAnchor)Anchor; anchor.AnchorType = 2; IClientAnchor pref = GetPreferredSize(scale); int row2 = anchor.Row1 + (pref.Row2 - pref.Row1); int col2 = anchor.Col1 + (pref.Col2 - pref.Col1); anchor.Col2 = col2; anchor.Dx1 = 0; anchor.Dx2 = pref.Dx2; anchor.Row2 = row2; anchor.Dy1 = 0; anchor.Dy2 = pref.Dy2; }
/// <summary> /// Creates a picture. /// </summary> /// <param name="anchor">the client anchor describes how this Group is attached /// to the sheet.</param> /// <param name="pictureIndex">Index of the picture.</param> /// <returns>the newly created shape.</returns> public IPicture CreatePicture(HSSFClientAnchor anchor, int pictureIndex) { HSSFPicture shape = new HSSFPicture(null, (HSSFClientAnchor)anchor); shape.PictureIndex=pictureIndex; shape.Anchor = (HSSFClientAnchor)anchor; AddShape(shape); EscherBSERecord bse = (_sheet.Workbook as HSSFWorkbook).Workbook.GetBSERecord(pictureIndex); bse.Ref = (bse.Ref + 1); return shape; }
/** * 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!"); }