public PowerPoint.Shape ApplyRectBannerEffect(BannerDirection direction, Position textPos, PowerPoint.Shape imageShape,
            string overlayColor, int transparency)
        {
            var tbInfo =
                new TextBoxes(Shapes.Range(), SlideWidth, SlideHeight)
                .GetTextBoxesInfo();
            if (tbInfo == null)
                return null;

            TextBoxes.AddMargin(tbInfo);

            PowerPoint.Shape overlayShape;
            direction = HandleAutoDirection(direction, textPos);
            switch (direction)
            {
                case BannerDirection.Horizontal:
                    overlayShape = ApplyOverlayEffect(overlayColor, transparency, 0, tbInfo.Top, SlideWidth,
                        tbInfo.Height);
                    break;
                // case BannerDirection.Vertical:
                default:
                    overlayShape = ApplyOverlayEffect(overlayColor, transparency, tbInfo.Left, 0, tbInfo.Width,
                        SlideHeight);
                    break;
            }
            ChangeName(overlayShape, EffectName.Banner);
            overlayShape.ZOrder(MsoZOrderCmd.msoSendToBack);
            if (imageShape != null)
            {
                imageShape.ZOrder(MsoZOrderCmd.msoSendToBack);
            }
            return overlayShape;
        }
 public void TestGetTextBoxInfoForEmptyTextBoxes()
 {
     var shapes = PpOperations.SelectShapesByPrefix("TextBox");
     var textBoxes = new TextBoxes(shapes, 
         Pres.PageSetup.SlideWidth, Pres.PageSetup.SlideHeight);
     var textBoxInfo = textBoxes.GetTextBoxesInfo();
     Assert.AreEqual(null, textBoxInfo);
 }
        public void TestStartBoxing()
        {
            PpOperations.SelectSlide(2);
            var shapes = PpOperations.SelectShapesByPrefix("TextBox");
            var textBoxes = new TextBoxes(shapes,
                Pres.PageSetup.SlideWidth, Pres.PageSetup.SlideHeight);

            textBoxes
                .SetAlignment(Alignment.Centre)
                .SetPosition(Position.Left)
                .StartBoxing();
            var textBoxInfo = textBoxes.GetTextBoxesInfo();
            Assert.IsTrue(SlideUtil.IsRoughlySame(241.439987f, textBoxInfo.Height));
            Assert.IsTrue(SlideUtil.IsRoughlySame(25f, textBoxInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(149.279953f, textBoxInfo.Top));
            Assert.IsTrue(SlideUtil.IsRoughlySame(710.945068f, textBoxInfo.Width));

            textBoxes
                .SetAlignment(Alignment.Centre)
                .SetPosition(Position.Centre)
                .StartBoxing();
            textBoxInfo = textBoxes.GetTextBoxesInfo();
            Assert.IsTrue(SlideUtil.IsRoughlySame(124.527481f, textBoxInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(149.279953f, textBoxInfo.Top));

            textBoxes
                .SetAlignment(Alignment.Centre)
                .SetPosition(Position.BottomLeft)
                .StartBoxing();
            textBoxInfo = textBoxes.GetTextBoxesInfo();
            Assert.IsTrue(SlideUtil.IsRoughlySame(25f, textBoxInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(273.559875f, textBoxInfo.Top));

            textBoxes
                .SetAlignment(Alignment.Centre)
                .SetPosition(Position.Bottom)
                .StartBoxing();
            textBoxInfo = textBoxes.GetTextBoxesInfo();
            Assert.IsTrue(SlideUtil.IsRoughlySame(124.527481f, textBoxInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(273.560028f, textBoxInfo.Top));

            textBoxes
                .SetAlignment(Alignment.Centre)
                .SetPosition(Position.Right)
                .StartBoxing();
            textBoxInfo = textBoxes.GetTextBoxesInfo();
            Assert.IsTrue(SlideUtil.IsRoughlySame(224.054962f, textBoxInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(149.279953f, textBoxInfo.Top));

            textBoxes
                .SetAlignment(Alignment.Auto)
                .SetPosition(Position.Original)
                .StartBoxing();
            textBoxInfo = textBoxes.GetTextBoxesInfo();
            Assert.IsTrue(SlideUtil.IsRoughlySame(68.2f, textBoxInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(52.17752f, textBoxInfo.Top));
        }
        public void TestStartBoxing()
        {
            PpOperations.SelectSlide(2);
            var shapes = PpOperations.SelectShapesByPrefix("TextBox");
            var textBoxes = new TextBoxes(shapes,
                Pres.PageSetup.SlideWidth, Pres.PageSetup.SlideHeight);

            textBoxes
                .SetAlignment(Alignment.Centre)
                .SetPosition(Position.Left)
                .StartBoxing();
            var textBoxInfo = textBoxes.GetTextBoxesInfo();
            Assert.IsTrue(SlideUtil.IsRoughlySame(57.5200043f, textBoxInfo.Height));
            Assert.IsTrue(SlideUtil.IsRoughlySame(25f, textBoxInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(241.240036f, textBoxInfo.Top));
            Assert.IsTrue(SlideUtil.IsRoughlySame(710.945068f, textBoxInfo.Width));

            textBoxes
                .SetAlignment(Alignment.Centre)
                .SetPosition(Position.Centre)
                .StartBoxing();
            textBoxInfo = textBoxes.GetTextBoxesInfo();
            Assert.IsTrue(SlideUtil.IsRoughlySame(124.527481f, textBoxInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(241.240036f, textBoxInfo.Top));

            textBoxes
                .SetAlignment(Alignment.Centre)
                .SetPosition(Position.BottomLeft)
                .StartBoxing();
            textBoxInfo = textBoxes.GetTextBoxesInfo();
            Assert.IsTrue(SlideUtil.IsRoughlySame(25f, textBoxInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(457.480042f, textBoxInfo.Top));

            textBoxes
                .SetAlignment(Alignment.Centre)
                .SetPosition(Position.Bottom)
                .StartBoxing();
            textBoxInfo = textBoxes.GetTextBoxesInfo();
            Assert.IsTrue(SlideUtil.IsRoughlySame(124.527481f, textBoxInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(457.480042f, textBoxInfo.Top));

            textBoxes
                .SetAlignment(Alignment.Centre)
                .SetPosition(Position.Right)
                .StartBoxing();
            textBoxInfo = textBoxes.GetTextBoxesInfo();
            Assert.IsTrue(SlideUtil.IsRoughlySame(224.054962f, textBoxInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(241.23996f, textBoxInfo.Top));
        }
        private PowerPoint.Shape ApplyCircleBannerEffect(string overlayColor, int transparency,
            bool isOutline = false, int margin = 0)
        {
            var tbInfo =
                new TextBoxes(Shapes.Range(), SlideWidth, SlideHeight)
                .GetTextBoxesInfo();
            if (tbInfo == null)
                return null;
            TextBoxes.AddMargin(tbInfo, margin);

            var overlayShape = ApplyCircleOverlayEffect(overlayColor, transparency, tbInfo.Left, tbInfo.Top, tbInfo.Width,
                tbInfo.Height, isOutline);
            ChangeName(overlayShape, EffectName.Banner);
            return overlayShape;
        }
        public void ApplyPseudoTextWhenNoTextShapes()
        {
            var isTextShapesEmpty = new TextBoxes(
                Shapes.Range(), SlideWidth, SlideHeight)
                .IsTextShapesEmpty();

            if (!isTextShapesEmpty) return;

            try
            {
                if (_slide.Layout == PowerPoint.PpSlideLayout.ppLayoutBlank)
                {
                    _slide.Layout = PowerPoint.PpSlideLayout.ppLayoutTitleOnly;
                }
                Shapes.AddTitle().TextFrame2.TextRange.Text = "Picture Slides Lab";
            }
            catch
            {
                // title already exist
                foreach (PowerPoint.Shape shape in Shapes)
                {
                    try
                    {
                        if (shape.Type != MsoShapeType.msoPlaceholder)
                        {
                            continue;
                        }

                        switch (shape.PlaceholderFormat.Type)
                        {
                            case PowerPoint.PpPlaceholderType.ppPlaceholderTitle:
                            case PowerPoint.PpPlaceholderType.ppPlaceholderCenterTitle:
                            case PowerPoint.PpPlaceholderType.ppPlaceholderVerticalTitle:
                                shape.TextFrame2.TextRange.Text = "Picture Slides Lab";
                                break;
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.LogException(e, "ApplyPseudoTextWhenNoTextShapes");
                    }
                }
            }
        }
        public void TestGetTextBoxInfo()
        {
            PpOperations.SelectSlide(2);
            var shapes = PpOperations.SelectShapesByPrefix("TextBox");
            var textBoxes = new TextBoxes(shapes,
                Pres.PageSetup.SlideWidth, Pres.PageSetup.SlideHeight);
            var textBoxInfo = textBoxes.GetTextBoxesInfo();

            Assert.IsTrue(SlideUtil.IsRoughlySame(348.4239f, textBoxInfo.Height));
            Assert.IsTrue(SlideUtil.IsRoughlySame(68.2f, textBoxInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(52.17752f, textBoxInfo.Top));
            Assert.IsTrue(SlideUtil.IsRoughlySame(741.0565f, textBoxInfo.Width));

            TextBoxes.AddMargin(textBoxInfo, 25);
            Assert.IsTrue(SlideUtil.IsRoughlySame(398.4239f, textBoxInfo.Height));
            Assert.IsTrue(SlideUtil.IsRoughlySame(43.1999969f, textBoxInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(27.17752f, textBoxInfo.Top));
            Assert.IsTrue(SlideUtil.IsRoughlySame(791.0565f, textBoxInfo.Width));
        }
        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;
        }
        public PowerPoint.Shape ApplyRectOutlineEffect(PowerPoint.Shape imageShape, string overlayColor, int transparency)
        {
            var tbInfo =
                new TextBoxes(Shapes.Range(), SlideWidth, SlideHeight)
                .GetTextBoxesInfo();
            if (tbInfo == null)
                return null;

            TextBoxes.AddMargin(tbInfo, 10);

            var overlayShape = ApplyOverlayEffect(overlayColor, transparency, tbInfo.Left, tbInfo.Top, tbInfo.Width,
                tbInfo.Height);
            overlayShape.Fill.Visible = MsoTriState.msoFalse;
            overlayShape.Line.Visible = MsoTriState.msoTrue;

            ChangeName(overlayShape, EffectName.Banner);
            overlayShape.ZOrder(MsoZOrderCmd.msoSendToBack);
            if (imageShape != null)
            {
                imageShape.ZOrder(MsoZOrderCmd.msoSendToBack);
            }
            return overlayShape;
        }
        public void ApplyPseudoTextWhenNoTextShapes()
        {
            var isTextShapesEmpty = new TextBoxes(
                Shapes.Range(), SlideWidth, SlideHeight)
                .IsTextShapesEmpty();

            if (!isTextShapesEmpty) return;

            try
            {
                Shapes.AddTitle().TextFrame2.TextRange.Text = "Picture Slides Lab";
            }
            catch
            {
                // title already exist
                foreach (PowerPoint.Shape shape in Shapes)
                {
                    try
                    {
                        switch (shape.PlaceholderFormat.Type)
                        {
                            case PowerPoint.PpPlaceholderType.ppPlaceholderTitle:
                            case PowerPoint.PpPlaceholderType.ppPlaceholderCenterTitle:
                            case PowerPoint.PpPlaceholderType.ppPlaceholderVerticalTitle:
                                shape.TextFrame2.TextRange.Text = "Picture Slides Lab";
                                break;
                        }
                    }
                    catch (COMException)
                    {
                        // non-placeholder shapes don't have PlaceholderFormat
                        // and will cause exception
                    }
                }
            }
        }
        public void TestTextPositionAndAlignment()
        {
            _designer.ApplyTextPositionAndAlignment(Position.Left, Alignment.Auto);
            var tbInfo = new TextBoxes(
                _contentSlide.Shapes.Range(),
                Pres.PageSetup.SlideWidth,
                Pres.PageSetup.SlideHeight)
                .GetTextBoxesInfo();
            Assert.IsTrue(SlideUtil.IsRoughlySame(25f, tbInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(159.559921f, tbInfo.Top));
            Assert.IsTrue(SlideUtil.IsRoughlySame(640.76f, tbInfo.Width));
            Assert.IsTrue(SlideUtil.IsRoughlySame(220.880081f, tbInfo.Height));

            _designer.ApplyTextWrapping();
            tbInfo = new TextBoxes(
                _contentSlide.Shapes.Range(),
                Pres.PageSetup.SlideWidth,
                Pres.PageSetup.SlideHeight)
                .GetTextBoxesInfo();
            Assert.IsTrue(SlideUtil.IsRoughlySame(25f, tbInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(101.239922f, tbInfo.Top));
            Assert.IsTrue(SlideUtil.IsRoughlySame(418.505035f, tbInfo.Width));
            Assert.IsTrue(SlideUtil.IsRoughlySame(279.200073f, tbInfo.Height));
        }
        public void TestStartBoxingWithTextWrapping()
        {
            PpOperations.SelectSlide(2);
            var shapes = PpOperations.SelectShapesByPrefix("TextBox");
            var textBoxes = new TextBoxes(shapes,
                Pres.PageSetup.SlideWidth, Pres.PageSetup.SlideHeight);

            textBoxes.StartTextWrapping();

            textBoxes
                .SetAlignment(Alignment.Centre)
                .SetPosition(Position.Left)
                .StartBoxing();

            var textBoxInfo = textBoxes.GetTextBoxesInfo();
            Assert.IsTrue(SlideUtil.IsRoughlySame(349.440033f, textBoxInfo.Height));
            Assert.IsTrue(SlideUtil.IsRoughlySame(25f, textBoxInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(95.27996f, textBoxInfo.Top));
            // aft text wrapping, width is smaller (originally should be 710)
            Assert.IsTrue(SlideUtil.IsRoughlySame(448.355042f, textBoxInfo.Width));
        }
        public void TestTextPositionAndAlignment()
        {
            _designer.ApplyTextPositionAndAlignment(Position.Left, Alignment.Auto);
            var tbInfo = new TextBoxes(
                _contentSlide.Shapes.Range(), 
                Pres.PageSetup.SlideWidth, 
                Pres.PageSetup.SlideHeight)
                .GetTextBoxesInfo();
            Assert.IsTrue(SlideUtil.IsRoughlySame(25f, tbInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(177.52f, tbInfo.Top));
            Assert.IsTrue(SlideUtil.IsRoughlySame(640.76f, tbInfo.Width));
            Assert.IsTrue(SlideUtil.IsRoughlySame(184.96f, tbInfo.Height));

            _designer.ApplyTextWrapping();
            tbInfo = new TextBoxes(
                _contentSlide.Shapes.Range(),
                Pres.PageSetup.SlideWidth,
                Pres.PageSetup.SlideHeight)
                .GetTextBoxesInfo();
            Assert.IsTrue(SlideUtil.IsRoughlySame(25f, tbInfo.Left));
            Assert.IsTrue(SlideUtil.IsRoughlySame(119.2f, tbInfo.Top));
            Assert.IsTrue(SlideUtil.IsRoughlySame(418.505035f, tbInfo.Width));
            Assert.IsTrue(SlideUtil.IsRoughlySame(243.279984f, tbInfo.Height));
        }