예제 #1
0
        protected override void ExecuteAction(string ribbonId)
        {
            this.StartNewUndoEntry();
            var selectedShape = this.GetCurrentSelection().ShapeRange[1];
            var pres          = this.GetCurrentPresentation();

            FitToSlide.FitToHeight(selectedShape, pres.SlideWidth, pres.SlideHeight);
        }
예제 #2
0
        public PowerPoint.Shape ApplySpecialEffectEffect(IMatrixFilter effectFilter, bool isActualSize)
        {
            Source.SpecialEffectImageFile = SpecialEffectImage(effectFilter, Source.FullSizeImageFile ?? Source.ImageFile, isActualSize);
            var specialEffectImageShape = AddPicture(Source.SpecialEffectImageFile, EffectName.SpecialEffect);
            var slideWidth  = SlideWidth;
            var slideHeight = SlideHeight;

            FitToSlide.AutoFit(specialEffectImageShape, slideWidth, slideHeight);
            CropPicture(specialEffectImageShape);
            return(specialEffectImageShape);
        }
        public PowerPoint.Shape ApplyBackgroundEffect()
        {
            PowerPoint.Shape imageShape = AddPicture(Source.FullSizeImageFile ?? Source.ImageFile, EffectName.BackGround);
            imageShape.ZOrder(MsoZOrderCmd.msoSendToBack);
            float slideWidth  = SlideWidth;
            float slideHeight = SlideHeight;

            FitToSlide.AutoFit(imageShape, slideWidth, slideHeight);

            CropPicture(imageShape);
            return(imageShape);
        }
        /// <summary>
        /// embed style information into the image shapes,
        /// and then return a list of shape in which
        /// index-0 is the original image
        /// index-1 is the cropped image
        /// </summary>
        /// <param name="originalImageFile"></param>
        /// <param name="croppedImageFile"></param>
        /// <param name="imageContext"></param>
        /// <param name="imageSource"></param>
        /// <param name="rect"></param>
        /// <param name="opt"></param>
        /// <returns></returns>
        public List <PowerPoint.Shape> EmbedStyleOptionsInformation(string originalImageFile, string croppedImageFile,
                                                                    string imageContext, string imageSource, Rect rect, StyleOption opt)
        {
            if (originalImageFile == null)
            {
                return(new List <PowerPoint.Shape>());
            }

            var originalImage = AddPicture(originalImageFile, EffectName.Original_DO_NOT_REMOVE);
            var slideWidth    = SlideWidth;
            var slideHeight   = SlideHeight;

            FitToSlide.AutoFit(originalImage, slideWidth, slideHeight);
            originalImage.Visible = MsoTriState.msoFalse;

            var croppedImage = AddPicture(croppedImageFile, EffectName.Cropped_DO_NOT_REMOVE);

            FitToSlide.AutoFit(croppedImage, slideWidth, slideHeight);
            croppedImage.Visible = MsoTriState.msoFalse;

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

            result.Add(originalImage);
            result.Add(croppedImage);

            // store source image info
            AddTag(originalImage, Tag.ReloadOriginImg, originalImageFile);
            AddTag(originalImage, Tag.ReloadCroppedImg, croppedImageFile);
            AddTag(originalImage, Tag.ReloadImgContext, imageContext);
            AddTag(originalImage, Tag.ReloadImgSource, imageSource);
            AddTag(originalImage, Tag.ReloadRectX, rect.X.ToString(CultureInfo.InvariantCulture));
            AddTag(originalImage, Tag.ReloadRectY, rect.Y.ToString(CultureInfo.InvariantCulture));
            AddTag(originalImage, Tag.ReloadRectWidth, rect.Width.ToString(CultureInfo.InvariantCulture));
            AddTag(originalImage, Tag.ReloadRectHeight, rect.Height.ToString(CultureInfo.InvariantCulture));

            // store style info
            var type  = opt.GetType();
            var props = type.GetProperties();

            foreach (var propertyInfo in props)
            {
                try
                {
                    AddTag(originalImage, Tag.ReloadPrefix + propertyInfo.Name,
                           propertyInfo.GetValue(opt, null).ToString());
                }
                catch (Exception e)
                {
                    Logger.LogException(e, "EmbedStyleOptionsInformation");
                }
            }
            return(result);
        }
        public PowerPoint.Shape ApplyBlurEffect(string imageFileToBlur = null, int degree = 85)
        {
            Source.BlurImageFile = BlurImage(imageFileToBlur
                                             ?? Source.FullSizeImageFile
                                             ?? Source.ImageFile, degree);
            PowerPoint.Shape blurImageShape = AddPicture(Source.BlurImageFile, EffectName.Blur);
            float            slideWidth     = SlideWidth;
            float            slideHeight    = SlideHeight;

            FitToSlide.AutoFit(blurImageShape, slideWidth, slideHeight);
            CropPicture(blurImageShape);
            return(blurImageShape);
        }
        private void SetToAbsoluteWidthAspectRatio()
        {
            // Store the original position of the shape
            var originalTop  = _shape.Top;
            var originalLeft = _shape.Left;

            _shape.LockAspectRatio = MsoTriState.msoFalse;
            FitToSlide.FitToWidth(_shape, _absoluteWidth, _absoluteHeight);
            _shape.LockAspectRatio = MsoTriState.msoTrue;

            _shape.Top  = originalTop;
            _shape.Left = originalLeft;

            UpdateAbsoluteWidth();
            UpdateAbsoluteHeight();
        }
        /// <summary>
        /// Fit the selected shapes with aspect ratio according to the set dimension type.
        /// </summary>
        /// <param name="selectedShapes"></param>
        /// <param name="dimension"></param>
        /// <param name="slideWidth"></param>
        /// <param name="slideHeight"></param>
        private void FitAspectRatioShapes(PowerPoint.ShapeRange selectedShapes, Dimension dimension, float slideWidth, float slideHeight)
        {
            try
            {
                for (int i = 1; i <= selectedShapes.Count; i++)
                {
                    PowerPoint.Shape      shape       = selectedShapes[i];
                    System.Drawing.PointF anchorPoint = GetVisualAnchorPoint(new PPShape(shape, false));

                    if (dimension == Dimension.Height)
                    {
                        FitToSlide.FitToHeight(shape, slideWidth, slideHeight);

                        PPShape ppShape = new PPShape(shape, false);
                        AlignVisualShape(ppShape, anchorPoint);
                        ppShape.VisualTop = 0;
                    }
                    else if (dimension == Dimension.Width)
                    {
                        FitToSlide.FitToWidth(shape, slideWidth, slideHeight);

                        PPShape ppShape = new PPShape(shape, false);
                        AlignVisualShape(ppShape, anchorPoint);
                        ppShape.VisualLeft = 0;
                    }
                    else if (dimension == Dimension.HeightAndWidth)
                    {
                        FitToSlide.AutoFit(shape, slideWidth, slideHeight);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.LogException(e, "FitAspectRatioShapes");
            }
        }