private PowerPoint.Shape ApplyCircleOverlayEffect(string color, int transparency, float left, float top, float width, float height, bool isOutline) { float radius = (float)Math.Sqrt(width * width / 4 + height * height / 4); float circleLeft = left - radius + width / 2; float circleTop = top - radius + height / 2; float circleWidth = radius * 2; PowerPoint.Shape overlayShape = Shapes.AddShape(MsoAutoShapeType.msoShapeOval, circleLeft, circleTop, circleWidth, circleWidth); overlayShape.Fill.Solid(); overlayShape.Fill.ForeColor.RGB = GraphicsUtil.ConvertColorToRgb(StringUtil.GetColorFromHexValue(color)); overlayShape.Fill.Transparency = (float)transparency / 100; overlayShape.Line.ForeColor.RGB = GraphicsUtil.ConvertColorToRgb(StringUtil.GetColorFromHexValue(color)); overlayShape.Line.Transparency = (float)transparency / 100; overlayShape.Line.Weight = 5; if (isOutline) { overlayShape.Fill.Visible = MsoTriState.msoFalse; overlayShape.Line.Visible = MsoTriState.msoTrue; } else { overlayShape.Fill.Visible = MsoTriState.msoTrue; overlayShape.Line.Visible = MsoTriState.msoFalse; } // as picture shape overlayShape.Cut(); overlayShape = Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; overlayShape.Left = circleLeft; overlayShape.Top = circleTop; ChangeName(overlayShape, EffectName.Overlay); return(overlayShape); }
//Stores slide-size crop of the current slide as a global variable private void AddZoomSlideCroppedPicture(float magnifyRatio = 1.0f) { PowerPointSlide zoomSlideCopy = this.Duplicate(); Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(zoomSlideCopy.Index); PowerPoint.Shape cropShape = zoomSlideCopy.Shapes.AddShape(Office.MsoAutoShapeType.msoShapeRectangle, 0, 0, PowerPointPresentation.Current.SlideWidth - 0.01f, PowerPointPresentation.Current.SlideHeight - 0.01f); cropShape.Select(); PowerPoint.Selection sel = Globals.ThisAddIn.Application.ActiveWindow.Selection; PowerPoint.Shape croppedShape = CropToShape.Crop(zoomSlideCopy, sel, magnifyRatio: magnifyRatio); croppedShape.Cut(); zoomSlideCroppedShapes = _slide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; zoomSlideCroppedShapes.Name = "PPTLabsMagnifyAreaGroup" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); Utils.ShapeUtil.FitShapeToSlide(ref zoomSlideCroppedShapes); zoomSlideCopy.Delete(); }
private static Shape ImportPictureToSlide(Shape shapeToAdd, Slide targetSlide, string tempFilePath) { // The AccessViolationException is no longer catchable if (!FileDir.IsFileReadable(tempFilePath)) { return(PPLClipboard.Instance.LockAndRelease(() => { shapeToAdd.Cut(); return targetSlide.Shapes.PasteSpecial(PpPasteDataType.ppPastePNG)[1]; })); } else { shapeToAdd.Delete(); return(targetSlide.Shapes.AddPicture2(tempFilePath, MsoTriState.msoFalse, MsoTriState.msoTrue, 0, 0)); } }
//Stores slide-size crop of the current slide as a global variable private void AddZoomSlideCroppedPicture(float magnifyRatio = 1.0f) { PowerPointSlide zoomSlideCopy = this.Duplicate(); Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(zoomSlideCopy.Index); PowerPoint.Shape cropShape = zoomSlideCopy.Shapes.AddShape(Office.MsoAutoShapeType.msoShapeRectangle, 0, 0, PowerPointPresentation.Current.SlideWidth - 0.01f, PowerPointPresentation.Current.SlideHeight - 0.01f); cropShape.Select(); PowerPoint.Selection sel = Globals.ThisAddIn.Application.ActiveWindow.Selection; PowerPoint.Shape croppedShape = CropToShape.Crop(zoomSlideCopy, sel, magnifyRatio: magnifyRatio); try { string tempFilePath = FileDir.GetTemporaryPngFilePath(); Utils.GraphicsUtil.ExportShape(croppedShape, tempFilePath); zoomSlideCroppedShapes = _slide.Shapes.AddPicture2(tempFilePath, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue, 0, 0); croppedShape.Delete(); try { FileDir.DeleteFile(tempFilePath); } catch (Exception) { // If the file cannot be deleted, we continue without deletion. } } catch (Exception) { // Revert to normal copy and pasting if unable to create file. croppedShape.Cut(); zoomSlideCroppedShapes = _slide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; } zoomSlideCroppedShapes.Name = "PPTLabsMagnifyAreaGroup" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); Utils.ShapeUtil.FitShapeToSlide(ref zoomSlideCroppedShapes); zoomSlideCopy.Delete(); }
public static Shape CorruptionCorrection(Shape shape, PowerPointSlide ownerSlide) { // in case of random corruption of shape, cut-paste a shape before using its property shape.Cut(); return ownerSlide.Shapes.Paste()[1]; }
/// <summary> /// To avoid corrupted shape. /// Corrupted shape is produced when delete or cut a shape programmatically, but then users undo it. /// After that, most of operations on corrupted shapes will throw an exception. /// One solution for this is to re-allocate its memory: simply cut/copy and paste. /// </summary> /// <param name="shape"></param> /// <returns></returns> private static PowerPoint.Shape CutPasteShape(PowerPoint.Shape shape) { shape.Cut(); shape = PowerPointCurrentPresentationInfo.CurrentSlide.Shapes.Paste()[1]; return(shape); }