Esempio n. 1
0
 private void customSizeDefaultsCommand_Execute(object sender, EventArgs e)
 {
     using (new WaitCursor())
         using (EditImageSizesDialog dialog = new EditImageSizesDialog())
         {
             ImageSizeName imageSizeName = ImagePropertiesInfo.InlineImageSizeName;
             if (dialog.ShowDialog(_editorContext.MainFrameWindow) == DialogResult.OK)
             {
                 // If the current ImageSizeName's settings changed, we should resize the image.
                 ImagePropertiesInfo.InlineImageSizeName = imageSizeName;
                 ApplyImageDecorations(ImagePropertyType.InlineSize, ImageDecoratorInvocationSource.Command);
             }
         }
 }
 public static Size GetSizeConstraints(ImageSizeName sizeName)
 {
     switch (sizeName)
     {
         case ImageSizeName.Large:
             return ImageEditingSettings.DefaultImageSizeLarge;
         case ImageSizeName.Medium:
             return ImageEditingSettings.DefaultImageSizeMedium;
         case ImageSizeName.Small:
             return ImageEditingSettings.DefaultImageSizeSmall;
         case ImageSizeName.Full:
             return new Size(Int32.MaxValue, Int32.MaxValue);
         default:
             Debug.Fail("Unsupported image size: " + sizeName);
             return ImageEditingSettings.DefaultImageSizeMedium;
     }
 }
Esempio n. 3
0
        public static Size GetDefaultImageSize(IProperties settings)
        {
            ImageSizeName boundsSize = GetDefaultBoundsSizeName(settings);
            Size          defaultBoundsSize;

            if (boundsSize != ImageSizeName.Custom)
            {
                defaultBoundsSize = ImageSizeHelper.GetSizeConstraints(boundsSize);
            }
            else
            {
                int defaultWidth  = settings.GetInt(DEFAULT_WIDTH, 240);
                int defaultHeight = settings.GetInt(DEFAULT_HEIGHT, 240);
                defaultBoundsSize = new Size(defaultWidth, defaultHeight);
            }
            return(defaultBoundsSize);
        }
Esempio n. 4
0
        public static Size GetSizeConstraints(ImageSizeName sizeName)
        {
            switch (sizeName)
            {
            case ImageSizeName.Large:
                return(ImageEditingSettings.DefaultImageSizeLarge);

            case ImageSizeName.Medium:
                return(ImageEditingSettings.DefaultImageSizeMedium);

            case ImageSizeName.Small:
                return(ImageEditingSettings.DefaultImageSizeSmall);

            case ImageSizeName.Full:
                return(new Size(Int32.MaxValue, Int32.MaxValue));

            default:
                Debug.Fail("Unsupported image size: " + sizeName);
                return(ImageEditingSettings.DefaultImageSizeMedium);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Scales the given imageSourceSize to the imageSizeName constraints.
        /// </summary>
        public static Size ScaleImageSizeName(ImageSizeName imageSizeName, Size imageSourceSize, RotateFlipType currentRotation)
        {
            Debug.Assert(imageSizeName != ImageSizeName.Custom, "No scaling policy associated with ImageSizeName.Custom");

            Size scaledImageSize = imageSourceSize;

            if (imageSizeName != ImageSizeName.Full)
            {
                Size sizeConstraints = ImageSizeHelper.GetSizeConstraints(imageSizeName);

                if (ImageUtils.IsRotated90(currentRotation))
                {
                    scaledImageSize = ImageUtils.GetScaledImageSize(sizeConstraints.Height, sizeConstraints.Width, imageSourceSize);
                    scaledImageSize = new Size(scaledImageSize.Height, scaledImageSize.Width);
                }
                else
                {
                    scaledImageSize = ImageUtils.GetScaledImageSize(sizeConstraints.Width, sizeConstraints.Height, imageSourceSize);
                }
            }

            return(scaledImageSize);
        }
        /// <summary>
        /// Sets the new size of the image (not including the border)
        /// </summary>
        /// <param name="size"></param>
        /// <param name="sizeName"></param>
        public void SetImageSize(Size size, ImageSizeName? sizeName)
        {
            IHTMLImgElement imgElement = (IHTMLImgElement)ImgElement;

            ImageBorderMargin borderMargin = BorderMargin;
            // The next line is a little bit tortured, but
            // I'm trying to introduce the concept of "calculated image size"
            // for more complex border calculations without breaking any
            // existing logic.
            Size sizeWithBorder = ImageSize.Equals(size)
                ? ImageSizeWithBorder : borderMargin.CalculateImageSize(size);

            if (imgElement.width != sizeWithBorder.Width || imgElement.height != sizeWithBorder.Height)
            {
                imgElement.width = sizeWithBorder.Width;
                imgElement.height = sizeWithBorder.Height;
            }

            //remember the size offsets which are added by CSS margins/padding
            Settings.SetInt(IMAGE_WIDTH_OFFSET, imgElement.width - sizeWithBorder.Width);
            Settings.SetInt(IMAGE_HEIGHT_OFFSET, imgElement.height - sizeWithBorder.Height);

            if (sizeName != null)
                ImageSizeName = sizeName.Value;

            //Initialize the saved aspect ratio if it has no value
            //OR update it if the ratio has been changed
            Size targetSize = TargetAspectRatioSize;
            if (targetSize.Width == -1 ||
               (size.Width != Math.Round((targetSize.Width * (float)size.Height) / targetSize.Height) &&
                size.Height != Math.Round((targetSize.Height * (float)size.Width) / targetSize.Width)))
            {
                TargetAspectRatioSize = size;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Scales the given imageSourceSize to the imageSizeName constraints.
        /// </summary>
        public static Size ScaleImageSizeName(ImageSizeName imageSizeName, Size imageSourceSize, RotateFlipType currentRotation)
        {
            Debug.Assert(imageSizeName != ImageSizeName.Custom, "No scaling policy associated with ImageSizeName.Custom");

            Size scaledImageSize = imageSourceSize;

            if (imageSizeName != ImageSizeName.Full)
            {
                Size sizeConstraints = ImageSizeHelper.GetSizeConstraints(imageSizeName);

                if (ImageUtils.IsRotated90(currentRotation))
                {
                    scaledImageSize = ImageUtils.GetScaledImageSize(sizeConstraints.Height, sizeConstraints.Width, imageSourceSize);
                    scaledImageSize = new Size(scaledImageSize.Height, scaledImageSize.Width);
                }
                else
                {
                    scaledImageSize = ImageUtils.GetScaledImageSize(sizeConstraints.Width, sizeConstraints.Height, imageSourceSize);
                }
            }

            return scaledImageSize;
        }
Esempio n. 8
0
        private bool ImageSizeNameMatches(ImageSizeName sizeName, Size orginalSize, Size currentSize)
        {
            Size constrainedSize = ImageSizeHelper.GetSizeConstraints(sizeName);

            return(currentSize == ImageUtils.GetScaledImageSize(constrainedSize.Width, constrainedSize.Height, orginalSize));
        }
 private bool ImageSizeNameMatches(ImageSizeName sizeName, Size orginalSize, Size currentSize)
 {
     Size constrainedSize = ImageSizeHelper.GetSizeConstraints(sizeName);
     return currentSize == ImageUtils.GetScaledImageSize(constrainedSize.Width, constrainedSize.Height, orginalSize);
 }