/// <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;

            #pragma warning disable 618
            if (Globals.ThisAddIn.IsApplicationVersion2013())
            {
                // sync glow, 2013 gives the wrong Glow.Fill color after copying the shape
                SyncFormats(shape, copiedShape, _glowFormats);
                // sync shape fill, 2013 gives the wrong fill color after copying the shape
                SyncFormats(shape, copiedShape, _fillFormats);

                // backup artistic effects for 2013
                // ForceSave() will make artistic effect permanent on the shapes for 2013 and no longer retrievable
                List <MsoPictureEffectType> extractedEffects = ArtisticEffectFormat.GetArtisticEffects(copiedShape);
                _backupArtisticEffects.Add(shapeKey, extractedEffects);
            }
            #pragma warning restore 618

            ForceSave();
            return(shapeKey);
        }
        public void ApplyFrostedGlassTextBoxEffect(string overlayColor, int transparency, Shape blurImage)
        {
            foreach (Shape shape in Shapes)
            {
                if ((shape.Type != MsoShapeType.msoPlaceholder
                        && shape.Type != MsoShapeType.msoTextBox)
                        || shape.TextFrame.HasText == MsoTriState.msoFalse
                        || StringUtil.IsNotEmpty(shape.Tags[Tag.AddedTextbox])
                        || StringUtil.IsNotEmpty(shape.Tags[Tag.ImageReference]))
                {
                    continue;
                }

                // multiple paragraphs.. 
                foreach (TextRange2 textRange in shape.TextFrame2.TextRange.Paragraphs)
                {
                    if (StringUtil.IsNotEmpty(textRange.TrimText().Text))
                    {
                        var paragraph = textRange.TrimText();
                        var left = paragraph.BoundLeft - 10;
                        var top = paragraph.BoundTop - 10;
                        var width = paragraph.BoundWidth + 20;
                        var height = paragraph.BoundHeight + 20;

                        blurImage.Copy();
                        var blurTextBox = Shapes.Paste()[1];
                        blurTextBox.Left = blurImage.Left;
                        blurTextBox.Top = blurImage.Top;
                        CropPicture(blurTextBox, left, top, width, height);
                        ChangeName(blurTextBox, EffectName.TextBox);

                        var overlayShape = ApplyOverlayEffect(overlayColor, transparency,
                            left, top, width, height);
                        ChangeName(overlayShape, EffectName.TextBox);

                        Graphics.MoveZToJustBehind(blurTextBox, shape);
                        Graphics.MoveZToJustBehind(overlayShape, shape);
                        shape.Tags.Add(Tag.AddedTextbox, overlayShape.Name);
                    }
                }
            }
            foreach (Shape shape in Shapes)
            {
                shape.Tags.Add(Tag.AddedTextbox, "");
            }
        }
Beispiel #3
0
        public static Shape FillInShapeWithImage(PowerPointSlide currentSlide, string imageFile, Shape shape,
                                                 double magnifyRatio = 1.0, bool isInPlace = false)
        {
            CreateFillInBackgroundForShape(imageFile, shape, magnifyRatio);
            shape.Fill.UserPicture(FillInBackgroundPicture);

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

            if (isInPlace)
            {
                return(shape);
            }

            shape.Copy();
            Shape shapeToReturn = currentSlide.Shapes.Paste()[1];

            shape.Delete();
            return(shapeToReturn);
        }
        public Shape ApplyFrostedGlassBannerEffect(BannerDirection direction, Position textPos, Shape blurImage,
            string overlayColor, int transparency)
        {
            var tbInfo =
                new TextBoxes(Shapes.Range(), SlideWidth, SlideHeight)
                .GetTextBoxesInfo();
            if (tbInfo == null)
                return null;

            TextBoxes.AddMargin(tbInfo);

            Shape overlayShape;
            blurImage.Copy();
            Shape blurBanner = Shapes.Paste()[1];
            blurBanner.Left = blurImage.Left;
            blurBanner.Top = blurImage.Top;
            direction = HandleAutoDirection(direction, textPos);
            switch (direction)
            {
                case BannerDirection.Horizontal:
                    overlayShape = ApplyOverlayEffect(overlayColor, transparency, 0, tbInfo.Top, SlideWidth,
                        tbInfo.Height);
                    CropPicture(blurBanner, 0, tbInfo.Top, SlideWidth, tbInfo.Height);
                    break;
                // case BannerDirection.Vertical:
                default:
                    overlayShape = ApplyOverlayEffect(overlayColor, transparency, tbInfo.Left, 0, tbInfo.Width,
                        SlideHeight);
                    CropPicture(blurBanner, tbInfo.Left, 0, tbInfo.Width, SlideHeight);
                    break;
            }
            ChangeName(overlayShape, EffectName.Banner);
            ChangeName(blurBanner, EffectName.Banner);
            overlayShape.ZOrder(MsoZOrderCmd.msoSendToBack);
            Graphics.MoveZToJustBehind(blurBanner, overlayShape);

            var range = Shapes.Range(new[] {blurBanner.Name, overlayShape.Name});
            var resultShape = range.Group();
            ChangeName(resultShape, EffectName.Banner);
            return resultShape;
        }