/// <summary>
        ///     Clone an existing slide (make a copy)
        /// </summary>
        /// <param name="presentation">PPT.Presentation object instance</param>
        /// <param name="slide">PPT.Slide instance that is to be cloned</param>
        /// <param name="destination">Destination for the cloned slide</param>
        /// <param name="locationIndex">Optional index for the new slide (slide.Index)</param>
        /// <returns></returns>
        public PPT.SlideRange CloneSlide(
                PPT.Presentation presentation,
                PPT.Slide slide,
                Locations.Location destination,
                int locationIndex = 0)
        {
            PPT.SlideRange dupeSlide = slide.Duplicate();

            switch (destination)
            {
                case Locations.Location.First:
                    dupeSlide.MoveTo(1);
                    break;

                case Locations.Location.Last:
                    dupeSlide.MoveTo((presentation.Slides.Count));
                    break;

                case Locations.Location.Custom:
                    dupeSlide.MoveTo(locationIndex);
                    break;
            }

            return dupeSlide;
        }
Beispiel #2
0
 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;
 }
        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;
            }
        }
        /// <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)
        {
            var coverImage = shape.Duplicate()[1];
            coverImage.Left = shape.Left;
            coverImage.Top = shape.Top;
            animationSlide.RemoveAnimationsForShape(coverImage);

            var sequence = animationSlide.TimeLine.MainSequence;
            var 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);
        }
        /// <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);

            var trigger = PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious;
            var effectMotion = AddMotionAnimation(animationSlide, shape, shape.Left, shape.Top, originalLeft + (originalWidth - shape.Width) / 2, originalTop + (originalHeight - shape.Height) / 2, 0, ref trigger);
            var 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)
            {
                var 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);
        }