Ejemplo n.º 1
0
        public void Decorate(ImageDecoratorContext context)
        {
            HtmlImageTargetDecoratorSettings settings = new HtmlImageTargetDecoratorSettings(context.Settings, context.ImgElement);

            if (context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert ||
                context.InvocationSource == ImageDecoratorInvocationSource.Reset)
            {
                //set the default link target type.
                //settings.LinkTarget = settings.DefaultLinkTarget;

                //the default size is a scaled version of the image based on the default inline size constraints.
                Size defaultSizeBounds = settings.DefaultTargetBoundsSize;

                settings.BaseSize = context.Image.Size;

                //calculate the base image size to scale from.  If the image is rotated 90 degrees, then switch the height/width
                Size baseImageSize = context.Image.Size;
                if (ImageUtils.IsRotated90(context.ImageRotation))
                {
                    baseImageSize = new Size(baseImageSize.Height, baseImageSize.Width);
                }

                //calculate and set the scaled default size using the defaultSizeBounds
                //Note: if the image dimensions are smaller than the default, don't scale that dimension (bug 419446)
                Size defaultSize = ImageUtils.GetScaledImageSize(Math.Min(baseImageSize.Width, defaultSizeBounds.Width), Math.Min(baseImageSize.Height, defaultSizeBounds.Height), baseImageSize);
                settings.ImageSize     = defaultSize;
                settings.ImageSizeName = settings.DefaultTargetBoundsSizeName;
            }
            else if (settings.BaseSizeChanged(context.Image) && context.ImageEmbedType == ImageEmbedType.Linked)
            {
                Size newBaseSize = context.Image.Size;
                settings.ImageSize = HtmlImageResizeDecorator.AdjustImageSizeForNewBaseSize(false, settings, newBaseSize, context.ImageRotation, context);
                settings.BaseSize  = newBaseSize;
            }

            if (context.InvocationSource == ImageDecoratorInvocationSource.Reset)
            {
                //set the initial link options
                settings.LinkOptions = settings.DefaultLinkOptions;
            }

            //this decorator only applies to linked images.
            if (context.ImageEmbedType == ImageEmbedType.Linked)
            {
                Size imageSize = settings.ImageSize;

                //resize the image and update the image used by the context.
                Bitmap bitmap = HtmlImageResizeDecorator.ResizeImage(context.Image, imageSize, context.ImageRotation);

                context.Image = bitmap;
                if (settings.ImageSize != bitmap.Size)
                {
                    settings.ImageSize = bitmap.Size;
                }
            }
        }
        public void Decorate(ImageDecoratorContext context)
        {
            HtmlImageTargetDecoratorSettings settings = new HtmlImageTargetDecoratorSettings(context.Settings, context.ImgElement);
            if (context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert ||
               context.InvocationSource == ImageDecoratorInvocationSource.Reset)
            {
                //set the default link target type.
                //settings.LinkTarget = settings.DefaultLinkTarget;

                //the default size is a scaled version of the image based on the default inline size constraints.
                Size defaultSizeBounds = settings.DefaultTargetBoundsSize;

                settings.BaseSize = context.Image.Size;

                //calculate the base image size to scale from.  If the image is rotated 90 degrees, then switch the height/width
                Size baseImageSize = context.Image.Size;
                if (ImageUtils.IsRotated90(context.ImageRotation))
                    baseImageSize = new Size(baseImageSize.Height, baseImageSize.Width);

                //calculate and set the scaled default size using the defaultSizeBounds
                //Note: if the image dimensions are smaller than the default, don't scale that dimension (bug 419446)
                Size defaultSize = ImageUtils.GetScaledImageSize(Math.Min(baseImageSize.Width, defaultSizeBounds.Width), Math.Min(baseImageSize.Height, defaultSizeBounds.Height), baseImageSize);
                settings.ImageSize = defaultSize;
                settings.ImageSizeName = settings.DefaultTargetBoundsSizeName;
            }
            else if (settings.BaseSizeChanged(context.Image) && context.ImageEmbedType == ImageEmbedType.Linked)
            {
                Size newBaseSize = context.Image.Size;
                settings.ImageSize = HtmlImageResizeDecorator.AdjustImageSizeForNewBaseSize(false, settings, newBaseSize, context.ImageRotation, context);
                settings.BaseSize = newBaseSize;
            }

            if (context.InvocationSource == ImageDecoratorInvocationSource.Reset)
            {
                //set the initial link options
                settings.LinkOptions = settings.DefaultLinkOptions;
            }

            //this decorator only applies to linked images.
            if (context.ImageEmbedType == ImageEmbedType.Linked)
            {
                Size imageSize = settings.ImageSize;

                //resize the image and update the image used by the context.
                Bitmap bitmap = HtmlImageResizeDecorator.ResizeImage(context.Image, imageSize, context.ImageRotation);

                context.Image = bitmap;
                if (settings.ImageSize != bitmap.Size)
                    settings.ImageSize = bitmap.Size;
            }
        }
Ejemplo n.º 3
0
        protected override void LoadEditor()
        {
            base.LoadEditor();
            HtmlImageTargetSettings = new HtmlImageTargetDecoratorSettings(EditorContext.Settings, EditorContext.ImgElement);
            LoadLinkTargetsCombo();

            string imgUrl = (string)EditorContext.ImgElement.getAttribute("src", 2);

            LinkToSourceImageEnabled = UrlHelper.IsFileUrl(imgUrl) && GlobalEditorOptions.SupportsFeature(ContentEditorFeature.SupportsImageClickThroughs);

            if (ImageEditingContext.EditorOptions.DhtmlImageViewer != null)
            {
                imageViewer = DhtmlImageViewers.GetImageViewer(ImageEditingContext.EditorOptions.DhtmlImageViewer);
            }
        }
Ejemplo n.º 4
0
        void IImageDecoratorDefaultSettingsCustomizer.CustomizeDefaultSettingsBeforeSave(ImageDecoratorEditorContext context, IProperties defaultSettings)
        {
            HtmlImageTargetDecoratorSettings defaultTargetSettings = new HtmlImageTargetDecoratorSettings(defaultSettings, context.ImgElement);
            HtmlImageTargetDecoratorSettings targetSettings        = new HtmlImageTargetDecoratorSettings(context.Settings, context.ImgElement);

            //save a reasonable value for the default link target.
            //If the link target is a URL, default to NONE since the user clearly doesn't want to preserve
            //the URL currently associated with the image for all future images
            if (defaultTargetSettings.LinkTarget != LinkTargetType.URL)
            {
                defaultTargetSettings.DefaultLinkTarget = defaultTargetSettings.LinkTarget;
            }
            else
            {
                defaultTargetSettings.DefaultLinkTarget = LinkTargetType.NONE;
            }

            defaultTargetSettings.DefaultLinkOptions          = targetSettings.LinkOptions;
            defaultTargetSettings.DefaultTargetBoundsSizeName = targetSettings.ImageSizeName;
            defaultTargetSettings.DefaultTargetBoundsSize     = targetSettings.ImageSize;
        }
        void IImageDecoratorDefaultSettingsCustomizer.CustomizeDefaultSettingsBeforeSave(ImageDecoratorEditorContext context, IProperties defaultSettings)
        {
            HtmlImageTargetDecoratorSettings defaultTargetSettings = new HtmlImageTargetDecoratorSettings(defaultSettings, context.ImgElement);
            HtmlImageTargetDecoratorSettings targetSettings = new HtmlImageTargetDecoratorSettings(context.Settings, context.ImgElement);

            //save a reasonable value for the default link target.
            //If the link target is a URL, default to NONE since the user clearly doesn't want to preserve
            //the URL currently associated with the image for all future images
            if (defaultTargetSettings.LinkTarget != LinkTargetType.URL)
                defaultTargetSettings.DefaultLinkTarget = defaultTargetSettings.LinkTarget;
            else
                defaultTargetSettings.DefaultLinkTarget = LinkTargetType.NONE;

            defaultTargetSettings.DefaultLinkOptions = targetSettings.LinkOptions;
            defaultTargetSettings.DefaultTargetBoundsSizeName = targetSettings.ImageSizeName;
            defaultTargetSettings.DefaultTargetBoundsSize = targetSettings.ImageSize;
        }
        protected override void LoadEditor()
        {
            base.LoadEditor();
            HtmlImageTargetSettings = new HtmlImageTargetDecoratorSettings(EditorContext.Settings, EditorContext.ImgElement);
            LoadLinkTargetsCombo();

            string imgUrl = (string)EditorContext.ImgElement.getAttribute("src", 2);
            LinkToSourceImageEnabled = UrlHelper.IsFileUrl(imgUrl) && GlobalEditorOptions.SupportsFeature(ContentEditorFeature.SupportsImageClickThroughs);

            if (ImageEditingContext.EditorOptions.DhtmlImageViewer != null)
            {
                imageViewer = DhtmlImageViewers.GetImageViewer(ImageEditingContext.EditorOptions.DhtmlImageViewer);
            }
        }