Exemple #1
0
        private static void UpdateBeamOnSlide(PowerPointSlide slide, Shape refBeamShape)
        {
            RemoveBeamAgendaFromSlide(slide);
            refBeamShape.Copy();
            var beamShape = slide.Shapes.Paste();
            var section   = GetSlideSection(slide);

            beamShape.GroupItems.Cast <Shape>()
            .Where(AgendaShape.WithPurpose(ShapePurpose.BeamShapeHighlightedText))
            .ToList()
            .ForEach(shape => shape.Delete());

            if (section.Index == 1)
            {
                return;
            }

            var beamFormats           = BeamFormats.ExtractFormats(refBeamShape);
            var currentSectionTextBox = beamShape.GroupItems
                                        .Cast <Shape>()
                                        .Where(AgendaShape.MeetsConditions(shape => shape.ShapePurpose == ShapePurpose.BeamShapeText &&
                                                                           shape.Section.Index == section.Index))
                                        .FirstOrDefault();
            var currentSectionText = currentSectionTextBox.TextFrame2.TextRange;

            Graphics.SyncTextRange(beamFormats.Highlighted, currentSectionText, pickupTextContent: false);
        }
Exemple #2
0
        //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;
            }
            LegacyShapeUtil.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;
        }
        /// <summary>
        /// A better version of SyncShape, but cannot do a partial sync like SyncShape can.
        /// SyncShape cannot operate on Groups and Charts. If those are detected, SyncWholeShape resorts to deleting
        /// candidateShape and replacing it with a copy of refShape instead of syncing.
        /// </summary>
        public static void SyncWholeShape(Shape refShape, ref Shape candidateShape, PowerPointSlide candidateSlide)
        {
            bool succeeded = true;

            try
            {
                SyncShape(refShape, candidateShape);
            }
            catch (UnauthorizedAccessException)
            {
                succeeded = false;
            }
            catch (ArgumentException)
            {
                succeeded = false;
            }
            catch (COMException)
            {
                succeeded = false;
            }
            if (succeeded)
            {
                return;
            }

            candidateShape.Delete();
            refShape.Copy();
            candidateShape      = candidateSlide.Shapes.Paste()[1];
            candidateShape.Name = refShape.Name;
        }
        //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];
                LegacyShapeUtil.CopyShapePosition(spotShape, ref spotlightShape);
            }
            else
            {
                spotlightShape = this.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1];
                LegacyShapeUtil.CopyShapePosition(spotShape, ref spotlightShape);
                CropSpotlightPictureToSlide(ref spotlightShape);
            }

            PrepareSpotlightShape(ref spotlightShape);
            return(spotlightShape);
        }
Exemple #5
0
    static void FixSlideNotesPages(Presentation presentation)
    {
        Shape FindNotesFooter()
        {
            var footerShape = presentation.NotesMaster.Shapes.OfType <Shape>().Where(
                shape => shape.Type == MsoShapeType.msoPlaceholder &&
                shape.PlaceholderFormat.Type == PpPlaceholderType.ppPlaceholderFooter)
                              .FirstOrDefault();

            return(footerShape);
        }

        Console.WriteLine("Fixing slide notes pages...");

        Shape footerFromNotesMaster = FindNotesFooter();

        footerFromNotesMaster.Copy();

        for (int slideNum = 1; slideNum <= presentation.Slides.Count; slideNum++)
        {
            Slide slide = presentation.Slides[slideNum];
            if (slide.HasNotesPage == MsoTriState.msoTrue)
            {
                var slideNotesFooter = slide.NotesPage.Shapes.OfType <Shape>().Where(
                    shape => shape.Type == MsoShapeType.msoPlaceholder &&
                    shape.PlaceholderFormat.Type == PpPlaceholderType.ppPlaceholderFooter)
                                       .FirstOrDefault();
                if (slideNotesFooter != null)
                {
                    slideNotesFooter.Delete();
                }
                slide.NotesPage.Shapes.Paste();
            }
        }
    }
Exemple #6
0
        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);
        }
        /// <summary>
        /// Saves shape in storage
        /// Returns a key to find the shape by,
        /// or null if the shape cannot be copied
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="formats">Required for msoPlaceholder</param>
        /// <returns>identifier of copied shape</returns>
        public string CopyShape(Shape shape, Format[] formats)
        {
            Shape copiedShape = null;

            if (shape.Type == MsoShapeType.msoPlaceholder)
            {
                copiedShape = ShapeUtil.CopyMsoPlaceHolder(formats, shape, GetTemplateShapes());
            }
            else
            {
                try
                {
                    shape.Copy();
                    copiedShape = Slides[0].Shapes.Paste()[1];
                }
                catch
                {
                    copiedShape = null;
                }
            }

            if (copiedShape == null)
            {
                return(null);
            }

            string shapeKey = nextKey.ToString();

            nextKey++;
            copiedShape.Name = shapeKey;
            ForceSave();
            return(shapeKey);
        }
Exemple #8
0
        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();
        }
        //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();
        }
Exemple #10
0
        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];
            ShapeUtil.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);
        }
Exemple #11
0
        /// <summary>
        /// Insert shape which is copied from `templatedShape` to slide
        /// Precondition: shapeName must not exist in slide before applying the method
        /// </summary>
        /// <param name="slide"></param>
        /// <param name="templatedShape">Shape whose format is to be copied over</param>
        /// <param name="shapeName"></param>
        /// <param name="text"></param>
        /// <returns>the copied shape</returns>
        public static Shape InsertTemplatedShapeToSlide(PowerPointSlide slide, Shape templatedShape, string shapeName, string text)
        {
            float slideWidth            = PowerPointPresentation.Current.SlideWidth;
            float slideHeight           = PowerPointPresentation.Current.SlideHeight;
            PowerPointPresentation pres = ActionFrameworkExtensions.GetCurrentPresentation();
            Shape copiedShape;

            // templatedShape and its associated animations are duplicated
            if (templatedShape == null)
            {
                throw new Exception("Templated shape is null");
            }
            try
            {
                copiedShape = ClipboardUtil.RestoreClipboardAfterAction(() =>
                {
                    templatedShape.Copy();
                    return(slide.Shapes.Paste()[1]);
                }, pres, slide);
            }
            catch
            {
                throw new Exception("Error copy and paste shape.");
            }
            if (copiedShape == null)
            {
                throw new Exception("Copied shape is null");
            }
            copiedShape.Name = shapeName;
            // copy shape to the default callout / caption position
            if (StringUtility.ExtractFunctionFromString(copiedShape.Name) == ELearningLabText.CalloutIdentifier)
            {
                copiedShape.Left = 10;
                copiedShape.Top  = 10;
                copiedShape.TextEffect.Alignment = MsoTextEffectAlignment.msoTextEffectAlignmentLeft;
            }
            else if (StringUtility.ExtractFunctionFromString(copiedShape.Name) == ELearningLabText.CaptionIdentifier)
            {
                copiedShape.Left   = 0;
                copiedShape.Top    = slideHeight - 100;
                copiedShape.Width  = slideWidth;
                copiedShape.Height = 100;
                copiedShape.Top    = slideHeight - copiedShape.Height;
                copiedShape.TextEffect.Alignment = MsoTextEffectAlignment.msoTextEffectAlignmentCentered;
            }

            copiedShape.TextFrame.AutoSize       = PpAutoSize.ppAutoSizeShapeToFitText;
            copiedShape.TextFrame.TextRange.Text = text;
            copiedShape.TextFrame.WordWrap       = MsoTriState.msoTrue;
            // remove associated animation with copiedShape because we only want the shape to be copied.
            slide.RemoveAnimationsForShape(copiedShape);
            if (StringUtility.ExtractFunctionFromString(copiedShape.Name) == ELearningLabText.CaptionIdentifier)
            {
                copiedShape.Top = slideHeight - copiedShape.Height;
            }
            return(copiedShape);
        }
Exemple #12
0
 /// <summary>
 /// Copies the shape into this slide, without the usual position offset when an existing shape is already there.
 /// </summary>
 public Shape CopyShapeToSlide(Shape shape)
 {
     try
     {
         shape.Copy();
         var newShape = _slide.Shapes.Paste()[1];
         newShape.Left = shape.Left;
         newShape.Top  = shape.Top;
         return(newShape);
     }
     catch (COMException)
     {
         // invalid shape for copy paste (e.g. a placeholder title box with no content)
         return(null);
     }
 }
Exemple #13
0
        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();
        }
Exemple #14
0
        //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) && !ShapeUtil.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];
                LegacyShapeUtil.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];
            LegacyShapeUtil.CopyShapePosition(shapeGroup, ref pictureOnNextSlide);
            shapeGroup.Delete();

            pictureOnNextSlide.Copy();
            PowerPoint.Shape slidePicture = currentSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1];
            return(slidePicture);
        }
Exemple #15
0
        public static PowerPoint.Shape FillInShapeWithImage(string imageFile, PowerPoint.Shape shape, bool isInPlace = false)
        {
            CreateFillInBackgroundForShape(imageFile, shape);
            shape.Fill.UserPicture(FillInBackgroundPicture);

            shape.Line.Visible = Office.MsoTriState.msoFalse;

            if (isInPlace)
            {
                return(shape);
            }

            shape.Copy();
            var shapeToReturn = PowerPointCurrentPresentationInfo.CurrentSlide.Shapes.Paste()[1];

            shape.Delete();
            return(shapeToReturn);
        }
        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);
        }
Exemple #17
0
        private static void ConvertToPictureForShape(PowerPointPresentation pres, PowerPointSlide slide, PowerPoint.Shape shape, int originalZOrder)
        {
            float rotation = 0;

            try
            {
                rotation       = shape.Rotation;
                shape.Rotation = 0;
            }
            catch (Exception e)
            {
                Logger.LogException(e, "Chart cannot be rotated.");
            }

            ClipboardUtil.RestoreClipboardAfterAction(() =>
            {
                shape.Copy();
                float x      = shape.Left;
                float y      = shape.Top;
                float width  = shape.Width;
                float height = shape.Height;
                shape.Delete();
                PowerPoint.Shape pic = slide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1];
                pic.Left             = x + (width - pic.Width) / 2;
                pic.Top      = y + (height - pic.Height) / 2;
                pic.Rotation = rotation;
                // move picture to original z-order
                while (pic.ZOrderPosition > originalZOrder)
                {
                    pic.ZOrder(Office.MsoZOrderCmd.msoSendBackward);
                }
                while (pic.ZOrderPosition < originalZOrder)
                {
                    pic.ZOrder(Office.MsoZOrderCmd.msoBringForward);
                }
                pic.Select();
                return(pic);
            }, pres, slide);
        }
Exemple #18
0
        //arrange guest seating plan
        private void arrangeGuestSP(PowerPoint.Shape guestSideGroup, PowerPoint.Slide slide, LinkedList <string> guestList)
        {
            //copy first group
            guestSideGroup.Copy();

            //get coordinate of first group
            float refGroupTop  = guestSideGroup.Top;
            float refGroupLeft = guestSideGroup.Left;

            //populate the first group
            insertNameIntoTextBox(guestSideGroup, guestList.First.Value);

            //continue with the rest of the delegation
            PowerPoint.Shape s;
            int counter = 0;

            foreach (string official in guestList)
            {
                //note-takers are out of scope for SP as they have special seats (TODO: do the same for interpreters)
                if (official.ToLower().Contains("note-taker"))
                {
                    continue;
                }

                counter++;
                if (counter == 1)
                {
                    //the first man is done
                    continue;
                }
                else
                {
                    s      = slide.Shapes.Paste()[1];
                    s.Top  = refGroupTop + 60 * (counter - 1);
                    s.Left = refGroupLeft;
                    insertNameIntoTextBox(s, official);
                }
            }
        }
Exemple #19
0
        private static PowerPoint.Shape GetStepBackWithoutBackgroundShapeToZoom(PowerPointSlide addedSlide, PowerPointSlide previousSlide)
        {
            Globals.ThisAddIn.Application.ActiveWindow.Selection.Unselect();
            Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(addedSlide.Index);

            var copiedShapes = new List <PowerPoint.Shape>();

            foreach (PowerPoint.Shape sh in previousSlide.Shapes)
            {
                if (!previousSlide.HasExitAnimation(sh) && !ShapeUtil.IsHidden(sh))
                {
                    sh.Copy();
                    PowerPoint.Shape shapeCopy = addedSlide.Shapes.Paste()[1];
                    LegacyShapeUtil.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();
            PowerPoint.Shape previousSlidePicture = addedSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1];
            LegacyShapeUtil.CopyShapePosition(shapeGroup, ref previousSlidePicture);
            previousSlidePicture.Name = "PPTZoomOutShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff");
            shapeGroup.Delete();

            return(previousSlidePicture);
        }
Exemple #20
0
        /// <summary>
        /// Copies the shape into this slide, without the usual position offset when an existing shape is already there.
        /// </summary>
        public Shape CopyShapeToSlide(Shape shape)
        {
            try
            {
                shape.Copy();
                var newShape = _slide.Shapes.Paste()[1];

                newShape.Name = shape.Name;
                newShape.Left = shape.Left;
                newShape.Top  = shape.Top;
                ShapeUtil.MoveZToJustInFront(newShape, shape);

                DeleteShapeAnimations(newShape);
                TransferAnimation(shape, newShape);

                return(newShape);
            }
            catch (COMException)
            {
                // invalid shape for copy paste (e.g. a placeholder title box with no content)
                return(null);
            }
        }
        private static void UpdateBeamOnSlide(PowerPointSlide slide, Shape refBeamShape)
        {
            RemoveBeamAgendaFromSlide(slide);
            refBeamShape.Copy();
            var beamShape = slide.Shapes.Paste();
            var section = GetSlideSection(slide);

            beamShape.GroupItems.Cast<Shape>()
                                .Where(AgendaShape.WithPurpose(ShapePurpose.BeamShapeHighlightedText))
                                .ToList()
                                .ForEach(shape => shape.Delete());

            if (section.Index == 1) return;

            var beamFormats = BeamFormats.ExtractFormats(refBeamShape);
            var currentSectionTextBox = beamShape.GroupItems
                                                .Cast<Shape>()
                                                .Where(AgendaShape.MeetsConditions(shape => shape.ShapePurpose == ShapePurpose.BeamShapeText &&
                                                                                            shape.Section.Index == section.Index))
                                                .FirstOrDefault();
            var currentSectionText = currentSectionTextBox.TextFrame2.TextRange;

            Graphics.SyncTextRange(beamFormats.Highlighted, currentSectionText, pickupTextContent: false);
        }
Exemple #22
0
        private void button2_Click(object sender, EventArgs e)
        {
            PowerPoint.Selection sel = app.ActiveWindow.Selection;
            if (sel.Type != PowerPoint.PpSelectionType.ppSelectionShapes)
            {
                MessageBox.Show("请先选中图片");
            }
            else
            {
                string                apath = app.ActivePresentation.Path;
                PowerPoint.Slide      slide = app.ActiveWindow.View.Slide;
                PowerPoint.ShapeRange range = sel.ShapeRange;
                if (sel.HasChildShapeRange)
                {
                    range = sel.ChildShapeRange;
                }
                int   count = range.Count;
                float nn    = float.Parse(textBox1.Text.Trim()) / 100f;
                for (int p = 1; p <= count; p++)
                {
                    PowerPoint.Shape pic = range[p];
                    pic.Copy();
                    PowerPoint.Shape npic = slide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1];
                    pic.Export(apath + @"xshape.png", PowerPoint.PpShapeFormat.ppShapeFormatPNG);
                    Bitmap   bmp0 = new Bitmap(apath + @"xshape.png");
                    Graphics g    = Graphics.FromImage(bmp0);
                    g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    g.DrawImage(bmp0, 0, 0);
                    g.Dispose();

                    Bitmap bmp1 = null;
                    if (radioButton1.Checked)
                    {
                        bmp1 = new Bitmap(bmp0.Width, (int)(bmp0.Height * (Math.Abs(nn) + 1)));
                        for (int i = 0; i < bmp0.Width; i++)
                        {
                            for (int j = 0; j < bmp0.Height; j++)
                            {
                                Color  color = bmp0.GetPixel(i, j);
                                double yn    = 0;
                                if (nn >= 0)
                                {
                                    yn = (double)j + (double)Math.Abs(bmp0.Height * nn) * (double)i / (double)bmp0.Width;
                                }
                                else
                                {
                                    yn = (double)j + (double)Math.Abs(bmp0.Height * nn) * (double)(bmp0.Width - i) / (double)bmp0.Width;
                                }

                                bmp1.SetPixel(i, (int)yn, color);
                            }
                        }
                    }
                    else if (radioButton2.Checked)
                    {
                        bmp1 = new Bitmap((int)(bmp0.Width * (Math.Abs(nn) + 1)), bmp0.Height);

                        for (int i = 0; i < bmp0.Height; i++)
                        {
                            for (int j = 0; j < bmp0.Width; j++)
                            {
                                Color  color = bmp0.GetPixel(j, i);
                                double xn    = 0;
                                if (nn < 0)
                                {
                                    xn = (double)j + (double)Math.Abs(bmp0.Width * nn) * (double)i / (double)bmp0.Height;
                                }
                                else
                                {
                                    xn = (double)j + (double)Math.Abs(bmp0.Width * nn) * (double)(bmp0.Height - i) / (double)bmp0.Height;
                                }
                                bmp1.SetPixel((int)xn, i, color);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("先选择垂直或水平方向");
                    }
                    bmp1.Save(apath + @"xshape2.png");
                    PowerPoint.Shape pic2 = slide.Shapes.AddPicture(apath + @"xshape2.png", Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue, pic.Left, pic.Top + pic.Height / 2 - npic.Height / 2, npic.Width, npic.Height);
                    npic.Delete();
                    bmp0.Dispose();
                    bmp1.Dispose();
                    File.Delete(apath + @"xshape.png");
                    File.Delete(apath + @"xshape2.png");
                    pic.Delete();
                    pic2.Select();
                }
            }
        }
 /// <summary>
 /// Copies the shape into this slide, without the usual position offset when an existing shape is already there.
 /// </summary>
 public Shape CopyShapeToSlide(Shape shape)
 {
     try
     {
         shape.Copy();
         var newShape = _slide.Shapes.Paste()[1];
         newShape.Left = shape.Left;
         newShape.Top = shape.Top;
         return newShape;
     }
     catch (COMException)
     {
         // invalid shape for copy paste (e.g. a placeholder title box with no content)
         return null;
     }
 }
Exemple #24
0
        private void InsertItem(IFileItem item)
        {
            if (item == null)
            {
                return;
            }

            PPT.Application   app  = new PPT.Application();
            PPT.Presentations pres = app.Presentations;

            PPT.Presentation pptx   = pres.Open(item.File.FullPath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
            PPT.Slides       slides = pptx.Slides;
            PPT.Slide        slide  = slides[item.Index];

            if (item.Type == ItemType.Slide)
            {
                slide.Copy();
            }
            else
            {
                PPT.Shapes shapes = slide.Shapes;
                PPT.Shape  shape  = shapes[1];

                shape.Copy();

                shapes.ReleaseCOM();
                shapes = null;
                shape.ReleaseCOM();
                shape = null;
            }

            PPT.Presentation dstpptx = app.ActivePresentation;

            PPT.DocumentWindow wnd  = app.ActiveWindow;
            PPT.View           view = wnd.View;

            //TODO: Check if there is no selection (selection between slides)
            PPT.Slides dstSlides = dstpptx.Slides;
            PPT.Slide  dstSlide  = null;

            dstSlide = view.Slide as PPT.Slide;
            int ix = dstSlide.SlideIndex + 1;

            if (item.Type == ItemType.Slide)
            {
                dstSlide.Copy();

                var r = dstSlides.Paste(); //TODO: dstSlides.Paste(ix) Hangs here
                var s = r[1];

                s.MoveTo(ix);

                s.ReleaseCOM();
                s = null;

                r.ReleaseCOM();
                r = null;
            }
            else
            {
                view.Paste();
            }

            dstSlide.ReleaseCOM();
            dstSlide = null;

            wnd.ReleaseCOM();
            wnd = null;

            view.ReleaseCOM();
            view = null;

            dstpptx.ReleaseCOM();
            dstpptx = null;


            slide.ReleaseCOM();
            slide = null;

            slides.ReleaseCOM();
            slides = null;

            pptx.Close();
            pptx.ReleaseCOM();
            pptx = null;

            pres.ReleaseCOM();
            pres = null;

            app.ReleaseCOM();
            app = null;

            dstSlides.ReleaseCOM();
            dstSlides = null;
        }
Exemple #25
0
        /// <summary>
        /// A better version of SyncShape, but cannot do a partial sync like SyncShape can.
        /// SyncShape cannot operate on Groups and Charts. If those are detected, SyncWholeShape resorts to deleting
        /// candidateShape and replacing it with a copy of refShape instead of syncing.
        /// </summary>
        public static void SyncWholeShape(Shape refShape, ref Shape candidateShape, PowerPointSlide candidateSlide)
        {
            bool succeeded = true;
            try
            {
                SyncShape(refShape, candidateShape);
            }
            catch (UnauthorizedAccessException)
            {
                succeeded = false;
            }
            catch (ArgumentException)
            {
                succeeded = false;
            }
            catch (COMException)
            {
                succeeded = false;
            }
            if (succeeded) return;

            candidateShape.Delete();
            refShape.Copy();
            candidateShape = candidateSlide.Shapes.Paste()[1];
            candidateShape.Name = refShape.Name;
        }
Exemple #26
0
    static void FixSlideNumbers(Presentation presentation)
    {
        Shape FindFirstSlideNumberShape()
        {
            CustomLayout layout =
                presentation.SlideMaster.CustomLayouts.OfType <CustomLayout>()
                .Where(l => l.Name == "Title and Content").First();

            foreach (Shape shape in layout.Shapes)
            {
                if (shape.Type == MsoShapeType.msoPlaceholder)
                {
                    if (shape.PlaceholderFormat.Type == PpPlaceholderType.ppPlaceholderSlideNumber)
                    {
                        return(shape);
                    }
                }
            }
            return(null);
        }

        Console.Write("Fixing slide numbering...");

        var layoutsWithoutNumbering = new HashSet <string>()
        {
            "Presentation Title Slide",
            "Section Title Slide",
            "Questions Slide"
        };

        Shape slideNumberShape = FindFirstSlideNumberShape();

        slideNumberShape.Copy();

        // Delete the [slide number] box in each slide, then put it again if needed
        for (int slideNum = 1; slideNum <= presentation.Slides.Count; slideNum++)
        {
            Slide  slide      = presentation.Slides[slideNum];
            string layoutName = slide.CustomLayout.Name;

            foreach (Shape shape in slide.Shapes)
            {
                bool isSlideNumberTextBox = shape.Type == MsoShapeType.msoTextBox &&
                                            shape.Name.Contains("Slide Number");
                bool isSlideNumberPlaceholder = shape.Type == MsoShapeType.msoPlaceholder &&
                                                shape.PlaceholderFormat.Type == PpPlaceholderType.ppPlaceholderSlideNumber;
                if (isSlideNumberTextBox || isSlideNumberPlaceholder)
                {
                    // Found a "slide number" shape --> delete it
                    shape.Delete();
                }
            }

            if (!layoutsWithoutNumbering.Contains(layoutName))
            {
                // The slide should have [slide number] box --> insert it
                slide.Shapes.Paste();
            }

            Console.Write("."); // Display progress of the current operation
        }
        Console.WriteLine();
    }
Exemple #27
0
        public static void AddDrillDownAnimation(PowerPoint.Shape selectedShape, PowerPointSlide currentSlide,
                                                 out PowerPointDrillDownSlide addedSlide, bool includeAckSlide = true, bool deletePreviouslyAdded = true)
        {
            try
            {
                if (currentSlide == null || currentSlide.Index == PowerPointPresentation.Current.SlideCount)
                {
                    System.Windows.Forms.MessageBox.Show("No next slide is found. Please select the correct slide", "Unable to Add Animations");
                    addedSlide = null;
                    return;
                }

                //Pick up the border and shadow style, to be applied to zoomed shape
                selectedShape.PickUp();
                PrepareZoomShape(currentSlide, ref selectedShape);
                PowerPointSlide nextSlide = GetNextSlide(currentSlide, deletePreviouslyAdded);

                PowerPoint.Shape nextSlidePicture = null, shapeToZoom = null;

                currentSlide.HideIndicator();
                if (ZoomLabSettings.BackgroundZoomChecked)
                {
                    nextSlidePicture = GetNextSlidePictureWithBackground(currentSlide, nextSlide);
                    nextSlidePicture.Apply();
                    PrepareNextSlidePicture(currentSlide, selectedShape, ref nextSlidePicture);

                    addedSlide = (PowerPointDrillDownSlide)currentSlide.CreateDrillDownSlide();
                    addedSlide.DeleteAllShapes();

                    nextSlidePicture.Copy();
                    shapeToZoom = addedSlide.Shapes.Paste()[1];
                    addedSlide.DeleteShapeAnimations(shapeToZoom);

                    currentSlide.Copy();
                    var backgroundShape = addedSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1];
                    backgroundShape.Apply();
                    ShapeUtil.FitShapeToSlide(ref backgroundShape);
                    backgroundShape.ZOrder(Office.MsoZOrderCmd.msoSendBackward);
                    backgroundShape.Name = "PPTZoomInShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff");

                    addedSlide.PrepareForDrillDown();
                    addedSlide.AddDrillDownAnimationBackground(backgroundShape, shapeToZoom, nextSlidePicture);
                }
                else
                {
                    PowerPoint.Shape pictureOnNextSlide = null;
                    nextSlidePicture = GetNextSlidePictureWithoutBackground(currentSlide, nextSlide, out pictureOnNextSlide);
                    nextSlidePicture.Apply();
                    PrepareNextSlidePicture(currentSlide, selectedShape, ref nextSlidePicture);

                    addedSlide = (PowerPointDrillDownSlide)currentSlide.CreateDrillDownSlide();
                    addedSlide.DeleteAllShapes();

                    nextSlidePicture.Copy();
                    shapeToZoom = addedSlide.Shapes.Paste()[1];
                    addedSlide.DeleteShapeAnimations(shapeToZoom);

                    currentSlide.Copy();
                    var backgroundShape = addedSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1];
                    backgroundShape.Apply();
                    ShapeUtil.FitShapeToSlide(ref backgroundShape);
                    backgroundShape.ZOrder(Office.MsoZOrderCmd.msoSendBackward);
                    backgroundShape.Name = "PPTZoomInShape" + DateTime.Now.ToString("yyyyMMddHHmmssffff");

                    addedSlide.PrepareForDrillDown();
                    addedSlide.AddDrillDownAnimationNoBackground(backgroundShape, shapeToZoom, pictureOnNextSlide);
                    pictureOnNextSlide.Delete();
                }
                currentSlide.ShowIndicator();

                Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(addedSlide.Index);
                Globals.ThisAddIn.Application.CommandBars.ExecuteMso("AnimationPreview");
                if (includeAckSlide)
                {
                    PowerPointPresentation.Current.AddAckSlide();
                }
            }
            catch (Exception e)
            {
                Logger.LogException(e, "AddDrillDownAnimation");
                ErrorDialogBox.ShowDialog("Error when adding drill down animation", "An error occurred when adding drill down animation.", e);
                throw;
            }
        }
Exemple #28
0
        public static void AddStepBackAnimation(PowerPoint.Shape selectedShape, PowerPointSlide currentSlide,
                                                out PowerPointStepBackSlide addedSlide, bool includeAckSlide = true, bool deletePreviouslyAdded = true)
        {
            try
            {
                if (currentSlide == null || currentSlide.Index == 1)
                {
                    System.Windows.Forms.MessageBox.Show("No previous slide is found. Please select the correct slide", "Unable to Add Animations");
                    addedSlide = null;
                    return;
                }

                //Pick up the border and shadow style, to be applied to zoomed shape
                selectedShape.PickUp();
                PrepareZoomShape(currentSlide, ref selectedShape);
                PowerPointSlide previousSlide = GetPreviousSlide(currentSlide, deletePreviouslyAdded);

                PowerPoint.Shape previousSlidePicture = null, shapeToZoom = null;

                currentSlide.HideIndicator();
                if (ZoomLabSettings.BackgroundZoomChecked)
                {
                    previousSlidePicture = GetPreviousSlidePictureWithBackground(currentSlide, previousSlide);
                    previousSlidePicture.Apply();
                    PreparePreviousSlidePicture(selectedShape, ref previousSlidePicture);

                    addedSlide = (PowerPointStepBackSlide)previousSlide.CreateStepBackSlide();
                    addedSlide.DeleteAllShapes();

                    PowerPoint.Shape backgroundShape = null;
                    shapeToZoom = GetStepBackWithBackgroundShapeToZoom(currentSlide, addedSlide, previousSlidePicture, out backgroundShape);
                    shapeToZoom.Apply();

                    addedSlide.PrepareForStepBack();
                    addedSlide.AddStepBackAnimationBackground(shapeToZoom, backgroundShape, previousSlidePicture);
                }
                else
                {
                    addedSlide = (PowerPointStepBackSlide)previousSlide.CreateStepBackSlide();
                    addedSlide.DeleteAllShapes();

                    shapeToZoom = GetStepBackWithoutBackgroundShapeToZoom(addedSlide, previousSlide);
                    shapeToZoom.Apply();
                    shapeToZoom.Copy();
                    previousSlidePicture = currentSlide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPastePNG)[1];
                    previousSlidePicture.Apply();
                    PreparePreviousSlidePicture(selectedShape, ref previousSlidePicture);

                    addedSlide.PrepareForStepBack();
                    addedSlide.AddStepBackAnimationNonBackground(shapeToZoom, previousSlidePicture);
                }
                currentSlide.ShowIndicator();

                currentSlide.Transition.EntryEffect = PowerPoint.PpEntryEffect.ppEffectFadeSmoothly;
                currentSlide.Transition.Duration    = 0.25f;
                Globals.ThisAddIn.Application.ActiveWindow.View.GotoSlide(addedSlide.Index);
                Globals.ThisAddIn.Application.CommandBars.ExecuteMso("AnimationPreview");
                if (includeAckSlide)
                {
                    PowerPointPresentation.Current.AddAckSlide();
                }
            }
            catch (Exception e)
            {
                Logger.LogException(e, "AddStepBackAnimation");
                ErrorDialogBox.ShowDialog("Error when adding step back animation", "An error occurred when adding step back animation.", e);
                throw;
            }
        }
 public void SaveShape(Shape shape)
 {
     shape.Copy();
     this.SaveShapeFromClipBoard(shape);
 }