/// <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; } }
private bool ShouldSerializeImageSize() { return(!ImageSize.Equals(new Size(16, 16))); }