public PreviewInfo PreviewApplyStyle(ImageItem source, Slide contentSlide, 
            float slideWidth, float slideHeight, StyleOptions option)
        {
            SetStyleOptions(option);
            SlideWidth = slideWidth;
            SlideHeight = slideHeight;

            var previewInfo = new PreviewInfo();
            var handler = CreateEffectsHandlerForPreview(source, contentSlide);

            // use thumbnail to apply, in order to speed up
            var fullSizeImgPath = source.FullSizeImageFile;
            var originalThumbnail = source.ImageFile;
            source.FullSizeImageFile = null;
            source.ImageFile = source.CroppedThumbnailImageFile ?? source.ImageFile;

            ApplyStyle(handler, source, isActualSize: false);

            // recover the source back
            source.FullSizeImageFile = fullSizeImgPath;
            source.ImageFile = originalThumbnail;
            handler.GetNativeSlide().Export(previewInfo.PreviewApplyStyleImagePath, "JPG",
                    GetPreviewWidth(), PreviewHeight);

            handler.Delete();
            return previewInfo;
        }
        public void ApplyStyle(ImageItem source, Slide contentSlide,
            float slideWidth, float slideHeight, StyleOptions option = null)
        {
            if (Globals.ThisAddIn != null)
            {
                Globals.ThisAddIn.Application.StartNewUndoEntry();
            }
            if (option != null)
            {
                SetStyleOptions(option);
            }

            // try to use cropped/adjusted image to apply
            var fullsizeImage = source.FullSizeImageFile;
            source.FullSizeImageFile = source.CroppedImageFile ?? source.FullSizeImageFile;
            source.OriginalImageFile = fullsizeImage;
            
            var effectsHandler = new EffectsDesigner(contentSlide, 
                slideWidth, slideHeight, source);

            ApplyStyle(effectsHandler, source, isActualSize: true);

            source.FullSizeImageFile = fullsizeImage;
            source.OriginalImageFile = null;
        }
 public void TestApply()
 {
     variant.Set("OptionName", "test option name");
     var option = new StyleOptions();
     variant.Apply(option);
     Assert.AreEqual("test option name", option.OptionName);
 }
 public StylesDesigner(Application app = null)
 {
     Path = TempPath.TempFolder;
     Name = "PictureSlidesLabPreview";
     Options = new StyleOptions();
     Application = app;
     Open(withWindow: false, focus: false);
 }
 public void Apply(StyleOptions opt)
 {
     foreach (var pair in _variants)
     {
         var type = opt.GetType();
         var prop = type.GetProperty(pair.Key);
         prop.SetValue(opt, pair.Value, null);
     }
 }
Example #6
0
 public void Apply(StyleOptions opt)
 {
     foreach (var pair in _variants)
     {
         var type = opt.GetType();
         var prop = type.GetProperty(pair.Key);
         prop.SetValue(opt, pair.Value, null);
     }
 }
        public void TestCopy()
        {
            variant.Set("TextBoxPosition", 999);
            variant.Set("OptionName", "test option name");
            variant = variant.Copy(new StyleOptions());

            var option = new StyleOptions();
            option.TextBoxPosition = 999;
            option.OptionName = "test option name";

            variant.Apply(option);
            Assert.AreEqual(5, option.TextBoxPosition);
            Assert.AreEqual("Reloaded", option.OptionName);
        }
        public void TestIsNoEffect()
        {
            variant.Set("TextBoxPosition", 999);
            variant.Set("OptionName", "test option name");

            var option = new StyleOptions();
            option.TextBoxPosition = 999;
            option.OptionName = "test option name";

            Assert.IsTrue(variant.IsNoEffect(option));

            option.TextBoxPosition = 4;

            Assert.IsFalse(variant.IsNoEffect(option));
        }
Example #9
0
        /// <summary>
        /// return true, when applying variant to this style options has no effect (still same)
        /// </summary>
        /// <param name="opt"></param>
        public bool IsNoEffect(StyleOptions opt)
        {
            foreach (var pair in _variants)
            {
                if (pair.Key.Equals("OptionName") || pair.Value is bool)
                {
                    continue;
                }

                var type     = opt.GetType();
                var prop     = type.GetProperty(pair.Key);
                var optValue = prop.GetValue(opt, null);
                if (!pair.Value.Equals(optValue))
                {
                    return(false);
                }
            }
            return(true);
        }
 /// <summary>
 /// Copy corresponding variant info from the given style
 /// </summary>
 public StyleVariants Copy(StyleOptions opt, string givenOptionName = null)
 {
     var newVariants = new Dictionary<string, object>();
     foreach (var pair in _variants)
     {
         if (pair.Key.Equals("OptionName"))
         {
             newVariants["OptionName"] = givenOptionName ?? "Reloaded";
         }
         else
         {
             var type = opt.GetType();
             var prop = type.GetProperty(pair.Key);
             var optValue = prop.GetValue(opt, null);
             newVariants[pair.Key] = optValue;
         }
     }
     return new StyleVariants(newVariants);
 }
        /// <summary>
        /// return true, when applying variant to this style options has no effect (still same)
        /// </summary>
        /// <param name="opt"></param>
        public bool IsNoEffect(StyleOptions opt)
        {
            foreach (var pair in _variants)
            {
                if (pair.Key.Equals("OptionName") || pair.Value is bool)
                {
                    continue;
                }

                var type = opt.GetType();
                var prop = type.GetProperty(pair.Key);
                var optValue = prop.GetValue(opt, null);
                if (!pair.Value.Equals(optValue))
                {
                    return false;
                }
            }
            return true;
        }
Example #12
0
        /// <summary>
        /// Copy corresponding variant info from the given style
        /// </summary>
        public StyleVariants Copy(StyleOptions opt, string givenOptionName = null)
        {
            var newVariants = new Dictionary <string, object>();

            foreach (var pair in _variants)
            {
                if (pair.Key.Equals("OptionName"))
                {
                    newVariants["OptionName"] = givenOptionName ?? "Reloaded";
                }
                else
                {
                    var type     = opt.GetType();
                    var prop     = type.GetProperty(pair.Key);
                    var optValue = prop.GetValue(opt, null);
                    newVariants[pair.Key] = optValue;
                }
            }
            return(new StyleVariants(newVariants));
        }
 public void Init()
 {
     option = new StyleOptions();
 }
        public List<PowerPoint.Shape> EmbedStyleOptionsInformation(string originalImageFile, string croppedImageFile, 
            string imageContext, Rect rect, StyleOptions opt)
        {
            if (originalImageFile == null) return new List<PowerPoint.Shape>();

            var originalImage = AddPicture(originalImageFile, EffectName.Original_DO_NOT_REMOVE);
            originalImage.Visible = MsoTriState.msoFalse;

            var croppedImage = AddPicture(croppedImageFile, EffectName.Cropped_DO_NOT_REMOVE);
            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.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)
                {
                    PowerPointLabsGlobals.LogException(e, "EmbedStyleOptionsInformation");
                }
            }
            return result;
        }
 public void SetStyleOptions(StyleOptions opt)
 {
     Options = opt;
 }
        private StyleOptions ConstructStyleFromShapeInfo(Shape shape)
        {
            var opt = new StyleOptions();
            var props = opt.GetType().GetProperties();
            foreach (var propertyInfo in props)
            {
                var valueInStr = shape.Tags[Service.Effect.Tag.ReloadPrefix + propertyInfo.Name];
                if (string.IsNullOrEmpty(valueInStr))
                {
                    continue;
                }

                if (propertyInfo.PropertyType == typeof(string))
                {
                    propertyInfo.SetValue(opt, valueInStr, null);
                }
                else if (propertyInfo.PropertyType == typeof(int))
                {
                    var valueInInt = int.Parse(valueInStr);
                    propertyInfo.SetValue(opt, valueInInt, null);
                }
                else if (propertyInfo.PropertyType == typeof(bool))
                {
                    var valueInBool = bool.Parse(valueInStr);
                    propertyInfo.SetValue(opt, valueInBool, null);
                }
            }
            return opt;
        }
 private Dictionary<string, List<StyleVariants>> ConstructVariantsFromStyle(StyleOptions opt)
 {
     var variants = StyleVariantsFactory.GetVariants(opt.StyleName);
     // replace each category/aspect's variant
     // with the new variant from the given style options
     foreach (var pair in variants)
     {
         var firstVariant = pair.Value[0];
         var newFirstVariant = firstVariant.Copy(opt);
         for (var i = 0; i < pair.Value.Count; i++)
         {
             // try to swap out the 'no-effect' style options
             if (pair.Value[i].IsNoEffect(opt))
             {
                 pair.Value[i] = firstVariant;
                 break;
             }
         }
         pair.Value[0] = newFirstVariant;
     }
     return variants;
 }