//Edit selected spotlight shape to fit within the current slide public PowerPoint.Shape CreateSpotlightShape(PowerPoint.Shape spotShape) { spotShape.Copy(); bool isCallout = false; PowerPoint.Shape spotlightShape; if (spotShape.Type == Office.MsoShapeType.msoCallout) isCallout = true; if (isCallout) { spotlightShape = this.Shapes.Paste()[1]; PowerPointLabsGlobals.CopyShapePosition(spotShape, ref spotlightShape); } else { spotlightShape = this.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; PowerPointLabsGlobals.CopyShapePosition(spotShape, ref spotlightShape); CropSpotlightPictureToSlide(ref spotlightShape); } PrepareSpotlightShape(ref spotlightShape); return spotlightShape; }
private static void ConvertToPictureForShape(PowerPoint.Shape shape) { float rotation = 0; try { rotation = shape.Rotation; shape.Rotation = 0; } catch (Exception e) { PowerPointLabsGlobals.LogException(e, "Chart cannot be rotated."); } shape.Copy(); float x = shape.Left; float y = shape.Top; float width = shape.Width; float height = shape.Height; shape.Delete(); var pic = PowerPointCurrentPresentationInfo.CurrentSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; pic.Left = x + (width - pic.Width) / 2; pic.Top = y + (height - pic.Height) / 2; pic.Rotation = rotation; pic.Select(); }
private PowerPoint.Shape GetReferenceShape(PowerPoint.Shape shapeToZoom) { shapeToZoom.Copy(); PowerPoint.Shape referenceShape = _slide.Shapes.Paste()[1]; referenceShape.LockAspectRatio = Office.MsoTriState.msoTrue; if (referenceShape.Width > referenceShape.Height) referenceShape.Width = PowerPointPresentation.Current.SlideWidth; else referenceShape.Height = PowerPointPresentation.Current.SlideHeight; referenceShape.Left = (PowerPointPresentation.Current.SlideWidth / 2) - (referenceShape.Width / 2); referenceShape.Top = (PowerPointPresentation.Current.SlideHeight / 2) - (referenceShape.Height / 2); return referenceShape; }
//Return zoomed version of cropped slide picture to be used for zoom out animation private void GetShapeToZoomWithBackground(PowerPoint.Shape zoomShape) { PowerPoint.Shape referenceShape = GetReferenceShape(zoomShape); float finalWidthMagnify = referenceShape.Width; float initialWidthMagnify = zoomShape.Width; float finalHeightMagnify = referenceShape.Height; float initialHeightMagnify = zoomShape.Height; zoomShape.Copy(); PowerPoint.Shape zoomShapeCopy = _slide.Shapes.Paste()[1]; LegacyShapeUtil.CopyShapeAttributes(zoomShape, ref zoomShapeCopy); Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(_slide.SlideIndex); zoomSlideCroppedShapes.Select(); zoomShapeCopy.Visible = Office.MsoTriState.msoTrue; zoomShapeCopy.Select(Office.MsoTriState.msoFalse); PowerPoint.ShapeRange selection = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange; PowerPoint.Shape groupShape = selection.Group(); groupShape.Width *= (finalWidthMagnify / initialWidthMagnify); groupShape.Height *= (finalHeightMagnify / initialHeightMagnify); groupShape.Ungroup(); zoomSlideCroppedShapes.Left += (referenceShape.Left - zoomShapeCopy.Left); zoomSlideCroppedShapes.Top += (referenceShape.Top - zoomShapeCopy.Top); zoomShapeCopy.Delete(); referenceShape.Delete(); }
private static PowerPoint.Shape GetStepBackWithBackgroundShapeToZoom(PowerPointSlide currentSlide, PowerPointSlide addedSlide, PowerPoint.Shape previousSlidePicture, out PowerPoint.Shape backgroundShape) { currentSlide.Copy(); PowerPoint.Shape currentSlideCopy = addedSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; Utils.Graphics.FitShapeToSlide(ref currentSlideCopy); currentSlideCopy.Name = "PPTZoomOutShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); previousSlidePicture.Copy(); PowerPoint.Shape previousSlidePictureCopy = addedSlide.Shapes.Paste()[1]; Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(addedSlide.Index); // Scale everything up by this ratio. float ratio = PowerPointPresentation.Current.SlideWidth / previousSlidePictureCopy.Width; currentSlideCopy.Width *= ratio; currentSlideCopy.Height *= ratio; currentSlideCopy.Left = -ratio * previousSlidePictureCopy.Left; currentSlideCopy.Top = -ratio * previousSlidePictureCopy.Top; // for some reason height is locked to width, so we only need to change width here. previousSlidePictureCopy.Width *= ratio; previousSlidePictureCopy.Left = 0; previousSlidePictureCopy.Top = 0; backgroundShape = currentSlideCopy; return previousSlidePictureCopy; }
//Return picture copy of next slide where shapes with exit animations have been deleted private static PowerPoint.Shape GetNextSlidePictureWithoutBackground(PowerPointSlide currentSlide, PowerPointSlide nextSlide, out PowerPoint.Shape pictureOnNextSlide) { Globals.ThisAddIn.Application.ActiveWindow.Selection.Unselect(); Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(nextSlide.Index); List<PowerPoint.Shape> shapesOnNextSlide = new List<PowerPoint.Shape>(); foreach (PowerPoint.Shape sh in nextSlide.Shapes) { if (!nextSlide.HasEntryAnimation(sh) && !Graphics.IsHidden(sh)) shapesOnNextSlide.Add(sh); } var copiedShapes = new List<PowerPoint.Shape>(); foreach (PowerPoint.Shape sh in shapesOnNextSlide) { sh.Copy(); var shapeCopy = nextSlide.Shapes.Paste()[1]; PowerPointLabsGlobals.CopyShapeAttributes(sh, ref shapeCopy); copiedShapes.Add(shapeCopy); } SelectAllShape(copiedShapes); PowerPoint.Selection sel = Globals.ThisAddIn.Application.ActiveWindow.Selection; PowerPoint.Shape shapeGroup = null; if (sel.ShapeRange.Count > 1) shapeGroup = sel.ShapeRange.Group(); else shapeGroup = sel.ShapeRange[1]; shapeGroup.Copy(); pictureOnNextSlide = nextSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; PowerPointLabsGlobals.CopyShapePosition(shapeGroup, ref pictureOnNextSlide); shapeGroup.Delete(); pictureOnNextSlide.Copy(); PowerPoint.Shape slidePicture = currentSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1]; return slidePicture; }
//Shape dimensions should match the slide dimensions and the shape should be within the slide private static PowerPoint.Shape GetBestFitShape(PowerPointSlide currentSlide, PowerPoint.Shape zoomShape) { zoomShape.Copy(); PowerPoint.Shape zoomShapeCopy = currentSlide.Shapes.Paste()[1]; zoomShapeCopy.LockAspectRatio = Office.MsoTriState.msoFalse; if (zoomShape.Width > zoomShape.Height) { zoomShapeCopy.Width = zoomShape.Width; zoomShapeCopy.Height = PowerPointPresentation.Current.SlideHeight * zoomShapeCopy.Width / PowerPointPresentation.Current.SlideWidth; } else { zoomShapeCopy.Height = zoomShape.Height; zoomShapeCopy.Width = PowerPointPresentation.Current.SlideWidth * zoomShapeCopy.Height / PowerPointPresentation.Current.SlideHeight; } PowerPointLabsGlobals.CopyShapePosition(zoomShape, ref zoomShapeCopy); if (zoomShapeCopy.Width > PowerPointPresentation.Current.SlideWidth) zoomShapeCopy.Width = PowerPointPresentation.Current.SlideWidth; if (zoomShapeCopy.Height > PowerPointPresentation.Current.SlideHeight) zoomShapeCopy.Height = PowerPointPresentation.Current.SlideHeight; if (zoomShapeCopy.Left < 0) zoomShapeCopy.Left = 0; if (zoomShapeCopy.Left + zoomShapeCopy.Width > PowerPointPresentation.Current.SlideWidth) zoomShapeCopy.Left = PowerPointPresentation.Current.SlideWidth - zoomShapeCopy.Width; if (zoomShapeCopy.Top < 0) zoomShapeCopy.Top = 0; if (zoomShapeCopy.Top + zoomShapeCopy.Height > PowerPointPresentation.Current.SlideHeight) zoomShapeCopy.Top = PowerPointPresentation.Current.SlideHeight - zoomShapeCopy.Height; return zoomShapeCopy; }
private static PowerPoint.ShapeRange MakeCopyForShapeRange(PowerPoint.ShapeRange rangeOriginal) { //Change shape's name in rangeOriginal, so that shape's name in rangeCopy is the same. //This is a naming mechanism in office: //When shape's name is the default one, its copy's name will be different (e.g. index got changed). //When shape's name is not the default one, its copy's name will be the same as the original shape's //use Guid here to ensure that name is unique var appendString = Guid.NewGuid().ToString() + "temp"; ModifyNameForShapeRange(rangeOriginal, appendString); rangeOriginal.Copy(); var rangeCopy = PowerPointCurrentPresentationInfo.CurrentSlide.Shapes.Paste(); AdjustSamePositionForShapeRange(rangeOriginal, rangeCopy); appendString = "_Copy"; ModifyNameForShapeRange(rangeCopy, appendString); return rangeCopy; }
private static PowerPoint.Shape FillInShapeWithScreenshot(PowerPoint.Shape shape, double magnifyRatio = 1.0) { if (shape.Type != Office.MsoShapeType.msoGroup) { CreateFillInBackgroundForShape(shape, magnifyRatio); shape.Fill.UserPicture(FillInBackgroundPicture); } else { using (var slideImage = (Bitmap)Image.FromFile(SlidePicture)) { foreach (var shapeGroupItem in (from PowerPoint.Shape sh in shape.GroupItems select sh)) { CreateFillInBackground(shapeGroupItem, slideImage); shapeGroupItem.Fill.UserPicture(FillInBackgroundPicture); } } } shape.Line.Visible = Office.MsoTriState.msoFalse; shape.Copy(); var shapeToReturn = PowerPointCurrentPresentationInfo.CurrentSlide.Shapes.Paste()[1]; shape.Delete(); return shapeToReturn; }
private static void RecreateCorruptedShape(PowerPoint.Shape s) { s.Copy(); PowerPoint.Shape newShape = PowerPointCurrentPresentationInfo.CurrentSlide.Shapes.Paste()[1]; newShape.Select(); newShape.Name = s.Name; newShape.Left = s.Left; newShape.Top = s.Top; while (newShape.ZOrderPosition > s.ZOrderPosition) { newShape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBackward); } s.Delete(); }