Esempio n. 1
0
 private void mapAnimationToShape(PowerPoint.Sequence effects, Dictionary <int, TildaShape> shapeMap)
 {
     foreach (PowerPoint.Effect effect in effects)
     {
         shapeMap[effect.Shape.Id].animations.Add(new TildaAnimation(effect, shapeMap[effect.Shape.Id]));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Takes the effects in the sequence in the range [startIndex,endIndex) and puts them into a list in the same order.
        /// </summary>
        private static List <PowerPoint.Effect> AsList(PowerPoint.Sequence sequence, int startIndex, int endIndex)
        {
            var list = new List <PowerPoint.Effect>();

            for (int i = startIndex; i < endIndex; ++i)
            {
                list.Add(sequence[i]);
            }
            return(list);
        }
Esempio n. 3
0
        private static bool IsFirstShape(PowerPointSlide currentSlide)
        {
            PowerPoint.Sequence sequence = currentSlide.TimeLine.MainSequence;
            bool isFirstShape            = true;

            if (sequence.Count != 0)
            {
                isFirstShape = (sequence[sequence.Count].EffectType == PowerPoint.MsoAnimEffect.msoAnimEffectChangeFontColor) ? false : true;
                if (sequence[1].EffectType == PowerPoint.MsoAnimEffect.msoAnimEffectChangeFontColor)
                {
                    sequence[1].Timing.TriggerType = PowerPoint.MsoAnimTriggerType.msoAnimTriggerOnPageClick;
                }
            }
            return(isFirstShape);
        }
Esempio n. 4
0
        public static void AddHighlightBulletsText()
        {
            try
            {
                var currentSlide = PowerPointCurrentPresentationInfo.CurrentSlide as PowerPointSlide;

                PowerPoint.ShapeRange selectedShapes = null;
                Office.TextRange2     selectedText   = null;

                //Get shapes to consider for animation
                List <PowerPoint.Shape> shapesToUse = null;
                switch (userSelection)
                {
                case HighlightTextSelection.kShapeSelected:
                    selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange;
                    shapesToUse    = GetShapesToUse(currentSlide, selectedShapes);
                    break;

                case HighlightTextSelection.kTextSelected:
                    selectedShapes = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange;
                    selectedText   = Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange2.TrimText();
                    shapesToUse    = GetShapesToUse(currentSlide, selectedShapes);
                    break;

                case HighlightTextSelection.kNoneSelected:
                    currentSlide.DeleteIndicator();
                    currentSlide.DeleteShapesWithPrefix("PPTLabsHighlightBackgroundShape");
                    shapesToUse = GetAllUsableShapesInSlide(currentSlide);
                    break;

                default:
                    break;
                }

                if (currentSlide.Name.Contains("PPTLabsHighlightBulletsSlide"))
                {
                    ProcessExistingHighlightSlide(currentSlide, shapesToUse);
                }

                if (shapesToUse == null || shapesToUse.Count == 0)
                {
                    return;
                }

                currentSlide.Name = "PPTLabsHighlightBulletsSlide" + DateTime.Now.ToString("yyyyMMddHHmmssffff");

                PowerPoint.Sequence sequence = currentSlide.TimeLine.MainSequence;
                bool isFirstShape            = IsFirstShape(currentSlide);

                foreach (PowerPoint.Shape sh in shapesToUse)
                {
                    if (!sh.Name.Contains("HighlightTextShape"))
                    {
                        sh.Name = "HighlightTextShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff");
                    }

                    //Add Font Appear effect for all paragraphs within shape
                    int currentIndex = sequence.Count;
                    sequence.AddEffect(sh, PowerPoint.MsoAnimEffect.msoAnimEffectChangeFontColor, PowerPoint.MsoAnimateByLevel.msoAnimateTextByFifthLevel, PowerPoint.MsoAnimTriggerType.msoAnimTriggerOnPageClick);
                    var appearEffects = AsList(sequence, currentIndex + 1, sequence.Count + 1);

                    //Add Font Disappear effect for all paragraphs within shape
                    currentIndex = sequence.Count;
                    sequence.AddEffect(sh, PowerPoint.MsoAnimEffect.msoAnimEffectChangeFontColor, PowerPoint.MsoAnimateByLevel.msoAnimateTextByFifthLevel, PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious);
                    var disappearEffects = AsList(sequence, currentIndex + 1, sequence.Count + 1);

                    //Remove effects for paragraphs without bullet points
                    var markedForRemoval = GetParagraphsToRemove(sh, selectedText);
                    // assert appearEffects.Count == disappearEffects.Count;
                    // assert markedForRemoval.Count <= appearEffects.Count;
                    for (int i = markedForRemoval.Count - 1; i >= 0; --i)
                    {
                        // delete from back.
                        int index = markedForRemoval[i];
                        appearEffects[index].Delete();
                        appearEffects.RemoveAt(index);
                        disappearEffects[index].Delete();
                        disappearEffects.RemoveAt(index);
                    }

                    if (appearEffects.Count == 0)
                    {
                        continue;
                    }

                    RearrangeEffects(appearEffects, disappearEffects);
                    FormatAppearEffects(appearEffects, isFirstShape);
                    FormatDisappearEffects(disappearEffects);
                    isFirstShape = false;
                }

                Globals.ThisAddIn.Application.CommandBars.ExecuteMso("AnimationPreview");
                PowerPointPresentation.Current.AddAckSlide();
            }
            catch (Exception e)
            {
                Logger.LogException(e, "AddHighlightBulletsText");
                throw;
            }
        }
        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;
            }
        }
Esempio n. 6
0
        public MainWindow()
        {
            InitializeComponent();
            return;

            //open(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) +
            //     "\\블록 RPG 과거 구현.pptm");

            Stopwatch sw = new Stopwatch();

            sw.Start();

            List <POWERPNT.Shape> shapes = new List <POWERPNT.Shape>();

            POWERPNT.Application  pptApplication  = new POWERPNT.Application();
            POWERPNT.Presentation pptPresentation = pptApplication.Presentations.Open(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) +
                                                                                      "\\도형+그룹.pptx", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); //,

            //MessageBox.Show(pptPresentation.ReadOnly.ToString());
            foreach (POWERPNT.Slide slide in pptPresentation.Slides)
            {
                var layout = slide.Layout;
                //MessageBox.Show(layout.ToString());
                GetAllShapes(slide.Shapes, ref shapes);



                POWERPNT.Sequence ms = slide.TimeLine.MainSequence;



                foreach (POWERPNT.Effect animation in ms)
                {
                    //MessageBox.Show(animation.Shape.Name);
                }
            }

            int ctr = 0;

            foreach (var shape in shapes)
            {
                try
                {
                    //MessageBox.Show(shape.Name);
                    shape.Delete();
                    //shape.Left = 500;
                }
                catch (Exception)
                {
                    ctr++;
                }
            }

            MessageBox.Show(shapes.Count + " :: " + sw.ElapsedMilliseconds + " :: " + ctr);


            //pptPresentation.Save();
            //pptPresentation.Close();
            //pptPresentation.Close();

            //pptApplication.Quit();
        }