public void AddZoomToAreaAnimation(PowerPoint.Shape zoomShape) { PrepareForZoomToArea(zoomShape); PowerPoint.Shape shapeToZoom = null, referenceShape = null; if (!ZoomLabSettings.BackgroundZoomChecked) { shapeToZoom = GetShapeToZoom(zoomShape); referenceShape = GetReferenceShape(shapeToZoom); DefaultMotionAnimation.AddDefaultMotionAnimation(this, shapeToZoom, referenceShape, 0.5f, PowerPoint.MsoAnimTriggerType.msoAnimTriggerAfterPrevious); } else { shapeToZoom = zoomSlideCroppedShapes.Duplicate()[1]; DeleteShapeAnimations(shapeToZoom); LegacyShapeUtil.CopyShapePosition(zoomSlideCroppedShapes, ref shapeToZoom); referenceShape = GetReferenceShape(zoomShape); DefaultMotionAnimation.AddZoomToAreaMotionAnimation(this, shapeToZoom, zoomShape, referenceShape, 0.5f, PowerPoint.MsoAnimTriggerType.msoAnimTriggerAfterPrevious); } shapeToZoom.Name = "PPTLabsMagnifyAreaSlide" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); referenceShape.Delete(); zoomSlideCroppedShapes.Visible = Office.MsoTriState.msoFalse; indicatorShape.ZOrder(Office.MsoZOrderCmd.msoBringToFront); }
public static void SplitObject(PowerPoint.Selection selection) { PowerPoint.Shape shape = selection.ShapeRange[1]; // Get number of paragraphs and original height int n = shape.TextFrame2.TextRange.Paragraphs.Count; // Set height to 1 / [paragraph count] of original shape.Height = shape.Height / n; // For each additional paragraph: duplicate, set left and top, remove unnecessary paragraphs for (int i = 2; i <= n; i++) { // Duplicate original shape to create new shape PowerPoint.Shape s = shape.Duplicate()[1]; s.Left = shape.Left; s.Top = shape.Top + (i - 1) * shape.Height; // Go through paragraphs in new shape and only keep the one we are interested in for (int p = n; p > 0; p--) { if (i != p) { s.TextFrame2.TextRange.Paragraphs[p].Delete(); } } // Remove line break trimNewline(s.TextFrame2.TextRange.Paragraphs[1]); } // Remove paragraphs 2 - n from original for (int p = 2; p <= n; p++) { shape.TextFrame2.TextRange.Paragraphs[2].Delete(); } // Remove last empty line from original shape trimNewline(shape.TextFrame2.TextRange.Paragraphs[1]); }
// TODO: This could be an extension method of shape. public static bool HasDefaultName(Shape shape) { Shape copy = shape.Duplicate()[1]; bool hasDefaultName = copy.Name != shape.Name; copy.Delete(); return(hasDefaultName); }
private static void CreateSpotlightDuplicate(PowerPoint.Shape spotlightShape) { //Create hidden duplicate shape. This is needed for recreating spotlights PowerPoint.Shape duplicateShape = spotlightShape.Duplicate()[1]; duplicateShape.Visible = Office.MsoTriState.msoFalse; duplicateShape.Left = spotlightShape.Left; duplicateShape.Top = spotlightShape.Top; }
/// <summary> /// Preloads a shape within the slide to reduce lag. Call after the animations for the shape have been created. /// </summary> public static void PreloadShape(PowerPointSlide animationSlide, PowerPoint.Shape shape, bool addCoverImage = true) { // The cover image is used to cover the screen while the preloading happens behind the cover image. PowerPoint.Shape coverImage = null; if (addCoverImage) { coverImage = shape.Duplicate()[1]; coverImage.Left = shape.Left; coverImage.Top = shape.Top; animationSlide.RemoveAnimationsForShape(coverImage); } float originalWidth = shape.Width; float originalHeight = shape.Height; float originalLeft = shape.Left; float originalTop = shape.Top; // fit the shape exactly in the screen for preloading. float scaleRatio = Math.Min(PowerPointPresentation.Current.SlideWidth / shape.Width, PowerPointPresentation.Current.SlideHeight / shape.Height); animationSlide.RelocateShapeWithoutPath(shape, 0, 0, shape.Width * scaleRatio, shape.Height * scaleRatio); MsoAnimTriggerType trigger = PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious; Effect effectMotion = AddMotionAnimation(animationSlide, shape, shape.Left, shape.Top, originalLeft + (originalWidth - shape.Width) / 2, originalTop + (originalHeight - shape.Height) / 2, 0, ref trigger); Effect effectResize = AddResizeAnimation(animationSlide, shape, shape.Width, shape.Height, originalWidth, originalHeight, 0, ref trigger); // Make "cover" image disappear after preload. PowerPoint.Effect effectDisappear = null; if (addCoverImage) { Sequence sequence = animationSlide.TimeLine.MainSequence; effectDisappear = sequence.AddEffect(coverImage, PowerPoint.MsoAnimEffect.msoAnimEffectFade, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious); effectDisappear.Exit = Office.MsoTriState.msoTrue; effectDisappear.Timing.Duration = 0.01f; } int firstEffectIndex = animationSlide.IndexOfFirstEffect(shape); // Move the animations to just before the index of the first effect. if (effectDisappear != null) { effectDisappear.MoveTo(firstEffectIndex); } if (effectResize != null) { effectResize.MoveTo(firstEffectIndex); } if (effectMotion != null) { effectMotion.MoveTo(firstEffectIndex); } }
/// <summary> /// Create a duplicate of the specified Shape object and return a new shape. /// </summary> /// <returns></returns> public PPShape Duplicate() { var newShape = new PPShape(_shape.Duplicate()[1]) { Name = _shape.Name + "Copy" }; return(newShape); }
//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) { PowerPoint.Shape zoomShapeCopy = zoomShape.Duplicate()[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; } LegacyShapeUtil.CopyCenterShapePosition(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.Shape MakePivotCenteredLine(PowerPointSlide animationSlide, PowerPoint.Shape line) { // Add a 180 degree rotated line to offset its pivot shift caused by arrowhead PowerPoint.Shape transparentLine = line.Duplicate()[1]; transparentLine.Line.Transparency = 1.0f; transparentLine.Rotation = 180.0f; transparentLine.Left = line.Left; transparentLine.Top = line.Top; PowerPoint.Shape tempAnimationHolder = line.Duplicate()[1]; animationSlide.TransferAnimation(line, tempAnimationHolder); List <PowerPoint.Shape> toGroup = new List <PowerPoint.Shape> { line, transparentLine }; PowerPoint.Shape newLine = animationSlide.ToShapeRange(toGroup).Group(); animationSlide.TransferAnimation(tempAnimationHolder, newLine); tempAnimationHolder.SafeDelete(); return(newLine); }
private static PowerPoint.Shape DuplicateShapeInPlace(PowerPoint.Shape shape) { var duplicateShape = shape.Duplicate()[1]; duplicateShape.Left = shape.Left; duplicateShape.Top = shape.Top; var match = System.Text.RegularExpressions.Regex.Match(duplicateShape.Name, @"\d+$"); if (!match.Success || int.Parse(match.Value) != duplicateShape.Id - 1) { duplicateShape.Name += " " + (duplicateShape.Id - 1); } return(duplicateShape); }
/// <summary> /// Useful when shape has text with more than one color /// Getting color in that case without a workabout will return black /// Assumes that shape has a TextRange /// </summary> /// <param name="shape">RGB color, seems to be the color of the last character</param> /// <returns></returns> public static int GuessTextColor(Shape shape) { // clear the text, to clear presence of more than 1 color // TextRange.Font.Color.RGB then returns the same color of as new text that is added to the shape // // Unsuccessful workabouts: // Taking a sub TextRange of the shape // Trimming text to the first character Shape duplicate = shape.Duplicate()[1]; duplicate.TextFrame.TextRange.Text = ""; int color = duplicate.TextFrame.TextRange.Font.Color.RGB; duplicate.Delete(); return(color); }
/// <summary> /// Creates a cover image from a copy of the shape to obstruct the viewer while preloading images in the background. /// </summary> public static void DuplicateAsCoverImage(PowerPointSlide animationSlide, PowerPoint.Shape shape) { Shape coverImage = shape.Duplicate()[1]; coverImage.Left = shape.Left; coverImage.Top = shape.Top; animationSlide.RemoveAnimationsForShape(coverImage); Sequence sequence = animationSlide.TimeLine.MainSequence; Effect effectDisappear = sequence.AddEffect(coverImage, PowerPoint.MsoAnimEffect.msoAnimEffectFade, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious); effectDisappear.Exit = Office.MsoTriState.msoTrue; effectDisappear.Timing.Duration = 0.01f; effectDisappear.MoveTo(1); }
private void button2_Click(object sender, EventArgs e) { PowerPoint.Selection sel = app.ActiveWindow.Selection; if (sel.Type == PowerPoint.PpSelectionType.ppSelectionNone || sel.ShapeRange.Count > 1) { forms.MessageBox.Show("只支持单个图形的旋转复制"); } else { PowerPoint.ShapeRange range = sel.ShapeRange; if (sel.HasChildShapeRange) { range = sel.ChildShapeRange; } else { range = sel.ShapeRange; } PowerPoint.Shape shape = range[1]; int n = int.Parse(textBox1.Text.Trim()) - 1; float r0 = float.Parse(textBox2.Text.Trim()); for (int i = 1; i <= n; i++) { PowerPoint.Shape nshape = shape.Duplicate()[1]; nshape.ThreeD.IncrementRotationY(-r0 * i); if (checkBox1.Checked) { float a = shape.ThreeD.BevelTopDepth; float b = shape.ThreeD.BevelBottomDepth; float c = shape.ThreeD.Depth; if (shape.ThreeD.Visible != Office.MsoTriState.msoTrue) { shape.ThreeD.Visible = Office.MsoTriState.msoTrue; c = shape.ThreeD.Depth - 36; } shape.ThreeD.Z = (float)(shape.Width / 2 / Math.Tan(r0 * Math.PI / 360)) + a + b + c; nshape.ThreeD.Z = shape.ThreeD.Z; } nshape.Left = shape.Left; nshape.Top = shape.Top; nshape.ZOrder(Office.MsoZOrderCmd.msoSendToBack); } } }
//Return shape which helps to calculate the amount of zoom-in animation private PowerPoint.Shape GetReferenceShape(PowerPoint.Shape shapeToZoom) { PowerPoint.Shape referenceShape = shapeToZoom.Duplicate()[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); }
protected PowerPoint.ShapeRange DuplicateShapes(PowerPoint.ShapeRange range) { int totalShapes = PpOperations.GetCurrentSlide().Shapes.Count; int[] duplicatedShapeIndices = new int[range.Count]; for (int i = 1; i <= range.Count; i++) { Shape shape = range[i]; Shape duplicated = shape.Duplicate()[1]; duplicated.Name = shape.Id + ""; duplicated.Left = shape.Left; duplicated.Top = shape.Top; duplicatedShapeIndices[i - 1] = totalShapes + i; } return(PpOperations.GetCurrentSlide().Shapes.Range(duplicatedShapeIndices)); }
// TODO: This could be an extension method of shape. public static bool HasDefaultName(Shape shape) { var copy = shape.Duplicate()[1]; bool hasDefaultName = copy.Name != shape.Name; copy.Delete(); return hasDefaultName; }
private int IsValidShapes(PowerPoint.ShapeRange selectedShapes) { PowerPoint.Shape referenceShape = selectedShapes[1]; if (referenceShape.Type == Microsoft.Office.Core.MsoShapeType.msoGroup) { return(ResizeLabErrorHandler.ErrorCodeGroupShapeNotSupported); } PowerPoint.Adjustments referenceAdjustments = referenceShape.Adjustments; bool isAutoShapeOrCallout = referenceShape.Type == Microsoft.Office.Core.MsoShapeType.msoAutoShape || referenceShape.Type == Microsoft.Office.Core.MsoShapeType.msoCallout; bool isFreeform = referenceShape.Type == Microsoft.Office.Core.MsoShapeType.msoFreeform; Utils.PPShape referencePPShape; List <System.Drawing.PointF> referenceShapePoints = null; if (isFreeform) { referencePPShape = new Utils.PPShape(referenceShape, false); referenceShapePoints = referencePPShape.Points; } for (int i = 2; i <= selectedShapes.Count; i++) { PowerPoint.Shape currentShape = selectedShapes[i]; if (currentShape.Type == Microsoft.Office.Core.MsoShapeType.msoGroup) { return(ResizeLabErrorHandler.ErrorCodeGroupShapeNotSupported); } if (currentShape.Type != referenceShape.Type || currentShape.AutoShapeType != referenceShape.AutoShapeType) { return(ResizeLabErrorHandler.ErrorCodeNotSameShapes); } if (isAutoShapeOrCallout) { PowerPoint.Adjustments currentAdjustments = currentShape.Adjustments; if (currentAdjustments.Count != referenceAdjustments.Count) { return(ResizeLabErrorHandler.ErrorCodeNotSameShapes); } for (int j = 1; j <= referenceAdjustments.Count; j++) { if (currentAdjustments[j] != referenceAdjustments[j]) { return(ResizeLabErrorHandler.ErrorCodeNotSameShapes); } } } else if (isFreeform) { Microsoft.Office.Core.MsoTriState isAspectRatio = selectedShapes.LockAspectRatio; selectedShapes.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoFalse; PowerPoint.Shape duplicateCurrentShape = currentShape.Duplicate()[1]; duplicateCurrentShape.Width = referenceShape.Width; duplicateCurrentShape.Height = referenceShape.Height; duplicateCurrentShape.Rotation = referenceShape.Rotation; duplicateCurrentShape.Left = referenceShape.Left; duplicateCurrentShape.Top = referenceShape.Top; Utils.PPShape currentPPShape = new Utils.PPShape(duplicateCurrentShape, false); List <System.Drawing.PointF> currentShapePoints = currentPPShape.Points; duplicateCurrentShape.Delete(); selectedShapes.LockAspectRatio = isAspectRatio; if (!currentShapePoints.SequenceEqual(referenceShapePoints)) { return(ResizeLabErrorHandler.ErrorCodeNotSameShapes); } } } return(-1); }
private void button1_Click(object sender, EventArgs e) { PowerPoint.Slide slide = app.ActiveWindow.View.Slide; PowerPoint.Selection sel = app.ActiveWindow.Selection; if (sel.Type == PowerPoint.PpSelectionType.ppSelectionNone) { MessageBox.Show("请先选中形状或单字符文本框"); } else { int row = int.Parse(textBox1.Text.Trim()); int column = int.Parse(textBox2.Text.Trim()); if (radioButton1.Checked) { PowerPoint.ShapeRange range = sel.ShapeRange; if (sel.HasChildShapeRange) { range = sel.ChildShapeRange; } else { range = sel.ShapeRange; } for (int k = 1; k <= range.Count; k++) { PowerPoint.Shape shape = range[k]; for (int i = 1; i <= row; i++) { for (int j = 1; j <= column; j++) { PowerPoint.Shape nshape = shape.Duplicate()[1]; nshape.Top = shape.Top + shape.Height * (i - 1); nshape.Left = shape.Left + shape.Width * j; } } } } if (radioButton2.Checked) { PowerPoint.ShapeRange range = sel.ShapeRange; if (sel.HasChildShapeRange) { range = sel.ChildShapeRange; } else { range = sel.ShapeRange; } for (int k = 1; k <= range.Count; k++) { PowerPoint.Shape shape = range[k]; string txt = shape.TextFrame.TextRange.Text; PowerPoint.Shape nshape = slide.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, shape.Left + shape.Width, shape.Top, shape.Width, shape.Height); int count = row * column; string result = txt.PadLeft(count, '$').Replace("$", txt); for (int i = 1; i < row; i++) { result = result.Insert(txt.Length * column * i + 2 * (i - 1), Environment.NewLine); } nshape.TextFrame.TextRange.Text = result; } } } }
private void button1_Click(object sender, EventArgs e) { PowerPoint.Selection sel = app.ActiveWindow.Selection; if (sel.Type == PowerPoint.PpSelectionType.ppSelectionShapes) { PowerPoint.Slide slide = app.ActiveWindow.View.Slide; PowerPoint.ShapeRange range = sel.ShapeRange; int count = range.Count; for (int i = 1; i <= count; i++) { PowerPoint.Shape pic = range[i]; if (pic.Type == Office.MsoShapeType.msoPicture) { PowerPoint.Shape npic = pic.Duplicate()[1]; float pw = app.ActivePresentation.PageSetup.SlideWidth; float ph = app.ActivePresentation.PageSetup.SlideHeight; if (checkBox1.Checked) { if (npic.LockAspectRatio == Office.MsoTriState.msoTrue) { npic.LockAspectRatio = Office.MsoTriState.msoFalse; } npic.Width = pw; npic.Height = ph; npic.Left = 0; npic.Top = 0; pic.ZOrder(Office.MsoZOrderCmd.msoBringToFront); } else { npic.Width = pic.Width * 1.5f; npic.Height = pic.Height * 1.5f; pic.ZOrder(Office.MsoZOrderCmd.msoBringToFront); } if (checkBox2.Checked) { if (npic.Fill.PictureEffects.Count == 0) { Office.PictureEffect piceff = npic.Fill.PictureEffects.Insert(Office.MsoPictureEffectType.msoEffectBlur, 0); piceff.EffectParameters[1].Value = 30f; } else { int en = -1; for (int j = 1; j <= npic.Fill.PictureEffects.Count; j++) { if (npic.Fill.PictureEffects[j].Type == Office.MsoPictureEffectType.msoEffectBlur) { Office.PictureEffect piceff = npic.Fill.PictureEffects[j]; piceff.EffectParameters[1].Value = 30f; en = 1; } } if (en == -1) { Office.PictureEffect piceff = npic.Fill.PictureEffects.Insert(Office.MsoPictureEffectType.msoEffectBlur, 0); piceff.EffectParameters[1].Value = 30f; } } } if (checkBox3.Checked) { if (npic.Fill.PictureEffects.Count == 0) { Office.PictureEffect piceff = npic.Fill.PictureEffects.Insert(Office.MsoPictureEffectType.msoEffectBrightnessContrast, 0); piceff.EffectParameters[1].Value = -0.43f; } else { int en = -1; for (int j = 1; j <= npic.Fill.PictureEffects.Count; j++) { if (npic.Fill.PictureEffects[j].Type == Office.MsoPictureEffectType.msoEffectBrightnessContrast) { Office.PictureEffect piceff = npic.Fill.PictureEffects[j]; piceff.EffectParameters[1].Value = -0.43f; en = 1; } } if (en == -1) { Office.PictureEffect piceff = npic.Fill.PictureEffects.Insert(Office.MsoPictureEffectType.msoEffectBrightnessContrast, 0); piceff.EffectParameters[1].Value = -0.43f; } } } List <string> name = new List <string>(); name.Add(npic.Name); name.Add(pic.Name); if (radioButton1.Checked) { if (checkBox1.Checked) { slide.Shapes.Range(name.ToArray()).Align(Office.MsoAlignCmd.msoAlignMiddles, Office.MsoTriState.msoFalse); slide.Shapes.Range(name.ToArray()).Align(Office.MsoAlignCmd.msoAlignCenters, Office.MsoTriState.msoFalse); } else { npic.Left = pic.Left + pic.Width / 2 - npic.Width / 2; npic.Top = pic.Top + pic.Height / 2 - npic.Height / 2; } } else if (radioButton2.Checked) { if (checkBox1.Checked) { slide.Shapes.Range(name.ToArray()).Align(Office.MsoAlignCmd.msoAlignRights, Office.MsoTriState.msoFalse); slide.Shapes.Range(name.ToArray()).Align(Office.MsoAlignCmd.msoAlignBottoms, Office.MsoTriState.msoFalse); } else { npic.Left = pic.Left + pic.Width - npic.Width; npic.Top = pic.Top + pic.Height - npic.Height; } } slide.Shapes.Range(name.ToArray()).Group(); } } } else { MessageBox.Show("请选中图片"); } }
/// <summary> /// Fake a copy by creating a similar object with the same formats /// Copy/Pasting MsoPlaceHolder doesn't work. /// Note: Shapes.AddPlaceholder(..) does not work as well. /// It restores a deleted placeholder to the slide, not create a shape /// </summary> /// <param name="formats"></param> /// <param name="msoPlaceHolder"></param> /// <param name="shapesSource">Shapes object, source of shapes</param> /// <returns>returns null if input placeholder is not supported</returns> public static Shape CopyMsoPlaceHolder(Format[] formats, Shape msoPlaceHolder, Shapes shapesSource) { PpPlaceholderType realType = msoPlaceHolder.PlaceholderFormat.Type; // charts, tables, pictures & smart shapes may return a general type, // ppPlaceHolderObject or ppPlaceHolderVerticalObject bool isGeneralType = realType == PpPlaceholderType.ppPlaceholderObject || realType == PpPlaceholderType.ppPlaceholderVerticalObject; if (isGeneralType) { realType = GetSpecificPlaceholderType(msoPlaceHolder); } // create an appropriate shape, based on placeholder type Shape shapeTemplate = null; switch (realType) { // the type never seems to be anything other than subtitle, center title, title, body or object. // still, place the rest here to be safe. case PpPlaceholderType.ppPlaceholderBody: case PpPlaceholderType.ppPlaceholderCenterTitle: case PpPlaceholderType.ppPlaceholderTitle: case PpPlaceholderType.ppPlaceholderSubtitle: case PpPlaceholderType.ppPlaceholderVerticalBody: case PpPlaceholderType.ppPlaceholderVerticalTitle: // not safe to do shape.Duplicate(), the duplicated textbox has differences in configuration // width is one example. more investigation is required to find out the exact differences shapeTemplate = shapesSource.AddTextbox( msoPlaceHolder.TextFrame.Orientation, msoPlaceHolder.Left, msoPlaceHolder.Top, msoPlaceHolder.Width, msoPlaceHolder.Height); break; case PpPlaceholderType.ppPlaceholderChart: case PpPlaceholderType.ppPlaceholderOrgChart: // not much value in copying charts, differed for now break; case PpPlaceholderType.ppPlaceholderTable: // not much value in copying tables, differed for now break; case PpPlaceholderType.ppPlaceholderPicture: case PpPlaceholderType.ppPlaceholderBitmap: // must use duplicate. there is no way to create a replacement picture // as the image's source is not obtainable through the Shape API var tempShape = msoPlaceHolder.Duplicate()[1]; tempShape.Copy(); shapeTemplate = shapesSource.Paste()[1]; tempShape.Delete(); break; case PpPlaceholderType.ppPlaceholderVerticalObject: case PpPlaceholderType.ppPlaceholderObject: // already narrowed down the type // should only perform actions valid for all placeholder objects here // do nothing for now break; default: // types not listed above are types that do not make sense to be copied in pptlabs // eg. footer, header, date placeholders break; } if (shapeTemplate == null) { // placeholder type is not supported, no copy made return(null); } ApplyFormats(formats, msoPlaceHolder, shapeTemplate); return(shapeTemplate); }
private static void AddFrameAnimationEffects(PowerPointSlide animationSlide, PowerPoint.Shape initialShape, float incrementLeft, float incrementTop, float incrementWidth, float incrementHeight, float incrementRotation, float incrementFont, float duration, int numFrames) { PowerPoint.Shape lastShape = initialShape; PowerPoint.Sequence sequence = animationSlide.TimeLine.MainSequence; for (int i = 1; i <= numFrames; i++) { PowerPoint.Shape dupShape = initialShape.Duplicate()[1]; if (i != 1 && animationType != FrameMotionAnimationType.kZoomToAreaDeMagnify) { sequence[sequence.Count].Delete(); } if (animationType == FrameMotionAnimationType.kInSlideAnimate || animationType == FrameMotionAnimationType.kZoomToAreaPan || animationType == FrameMotionAnimationType.kZoomToAreaDeMagnify) { animationSlide.DeleteShapeAnimations(dupShape); } if (animationType == FrameMotionAnimationType.kZoomToAreaPan) { dupShape.Name = "PPTLabsMagnifyPanAreaGroup" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); } dupShape.LockAspectRatio = Office.MsoTriState.msoFalse; dupShape.Left = initialShape.Left; dupShape.Top = initialShape.Top; if (incrementWidth != 0.0f) { dupShape.ScaleWidth((1.0f + (incrementWidth * i)), Office.MsoTriState.msoFalse, Office.MsoScaleFrom.msoScaleFromMiddle); } if (incrementHeight != 0.0f) { dupShape.ScaleHeight((1.0f + (incrementHeight * i)), Office.MsoTriState.msoFalse, Office.MsoScaleFrom.msoScaleFromMiddle); } if (incrementRotation != 0.0f) { dupShape.Rotation += (incrementRotation * i); } if (incrementLeft != 0.0f) { dupShape.Left += (incrementLeft * i); } if (incrementTop != 0.0f) { dupShape.Top += (incrementTop * i); } if (incrementFont != 0.0f) { dupShape.TextFrame.TextRange.Font.Size += (incrementFont * i); } if (i == 1 && (animationType == FrameMotionAnimationType.kInSlideAnimate || animationType == FrameMotionAnimationType.kZoomToAreaPan)) { PowerPoint.Effect appear = sequence.AddEffect(dupShape, PowerPoint.MsoAnimEffect.msoAnimEffectAppear, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, PowerPoint.MsoAnimTriggerType.msoAnimTriggerOnPageClick); } else { PowerPoint.Effect appear = sequence.AddEffect(dupShape, PowerPoint.MsoAnimEffect.msoAnimEffectAppear, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious); appear.Timing.TriggerDelayTime = ((duration / numFrames) * i); } PowerPoint.Effect disappear = sequence.AddEffect(lastShape, PowerPoint.MsoAnimEffect.msoAnimEffectAppear, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious); disappear.Exit = Office.MsoTriState.msoTrue; disappear.Timing.TriggerDelayTime = ((duration / numFrames) * i); lastShape = dupShape; } if (animationType == FrameMotionAnimationType.kInSlideAnimate || animationType == FrameMotionAnimationType.kZoomToAreaPan || animationType == FrameMotionAnimationType.kZoomToAreaDeMagnify) { PowerPoint.Effect disappearLast = sequence.AddEffect(lastShape, PowerPoint.MsoAnimEffect.msoAnimEffectAppear, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, PowerPoint.MsoAnimTriggerType.msoAnimTriggerAfterPrevious); disappearLast.Exit = Office.MsoTriState.msoTrue; disappearLast.Timing.TriggerDelayTime = duration; } }
public static PowerPoint.ShapeRange Crop(PowerPoint.ShapeRange shapeRange) { bool hasChange = false; for (int i = 1; i <= shapeRange.Count; i++) { PowerPoint.Shape shape = shapeRange[i]; // Store initial properties float currentRotation = shape.Rotation; float cropLeft = shape.PictureFormat.CropLeft; float cropRight = shape.PictureFormat.CropRight; float cropTop = shape.PictureFormat.CropTop; float cropBottom = shape.PictureFormat.CropBottom; // Set properties to zero to do proper calculations shape.PictureFormat.CropLeft = 0; shape.PictureFormat.CropRight = 0; shape.PictureFormat.CropTop = 0; shape.PictureFormat.CropBottom = 0; shape.Rotation = 0; // Get unscaled dimensions PowerPoint.ShapeRange origShape = shape.Duplicate(); origShape.ScaleWidth(1, Office.MsoTriState.msoTrue); origShape.ScaleHeight(1, Office.MsoTriState.msoTrue); float origWidth = origShape.Width; float origHeight = origShape.Height; origShape.SafeDelete(); Rectangle origImageRect = new Rectangle(); Rectangle croppedImageRect = new Rectangle(); Utils.GraphicsUtil.ExportShape(shape, TempPngFileExportPath); using (Bitmap shapeBitmap = new Bitmap(TempPngFileExportPath)) { origImageRect = new Rectangle(0, 0, shapeBitmap.Width, shapeBitmap.Height); try { croppedImageRect = GetImageBoundingRect(shapeBitmap, shape.Name); } catch (NotSupportedException e) { throw e; } } float cropRatioLeft = croppedImageRect.Left / (float)origImageRect.Width; float cropRatioRight = (origImageRect.Width - croppedImageRect.Width) / (float)origImageRect.Width; float cropRatioTop = croppedImageRect.Top / (float)origImageRect.Height; float cropRatioBottom = (origImageRect.Height - croppedImageRect.Height) / (float)origImageRect.Height; float newCropLeft = Math.Max(origWidth * cropRatioLeft, cropLeft); float newCropRight = Math.Max(origWidth * cropRatioRight, cropRight); float newCropTop = Math.Max(origHeight * cropRatioTop, cropTop); float newCropBottom = Math.Max(origHeight * cropRatioBottom, cropBottom); if (!hasChange && (!IsApproximatelySame(newCropLeft, cropLeft) || !IsApproximatelySame(newCropRight, cropRight) || !IsApproximatelySame(newCropTop, cropTop) || !IsApproximatelySame(newCropBottom, cropBottom))) { hasChange = true; } shape.Rotation = currentRotation; shape.PictureFormat.CropLeft = newCropLeft; shape.PictureFormat.CropRight = newCropRight; shape.PictureFormat.CropTop = newCropTop; shape.PictureFormat.CropBottom = newCropBottom; } if (!hasChange) { throw new CropLabException(CropLabErrorHandler.ErrorCodeNoPaddingCropped.ToString()); } return(shapeRange); }