Esempio n. 1
0
        //no instance required
        /// <summary>Calculates width and height values for image with a given area params.</summary>
        /// <param name="image">
        /// the
        /// <see cref="iText.Layout.Properties.BackgroundImage"/>
        /// width and height of which you want to calculate
        /// </param>
        /// <param name="areaWidth">width of the area of this images</param>
        /// <param name="areaHeight">height of the area of this images</param>
        /// <returns>array of two Float values. NOTE that first value defines width, second defines height.</returns>
        /// <seealso cref="iText.Layout.Properties.BackgroundSize"/>
        public static float[] CalculateBackgroundImageSize(BackgroundImage image, float areaWidth, float areaHeight
                                                           )
        {
            bool           isGradient = image.GetLinearGradientBuilder() != null;
            BackgroundSize size;

            if (!isGradient && image.GetBackgroundSize().IsSpecificSize())
            {
                size = CalculateBackgroundSizeForArea(image, areaWidth, areaHeight);
            }
            else
            {
                size = image.GetBackgroundSize();
            }
            UnitValue width  = size.GetBackgroundWidthSize();
            UnitValue height = size.GetBackgroundHeightSize();

            float?[] widthAndHeight = new float?[2];
            if (width != null && width.GetValue() >= 0)
            {
                bool needScale = !isGradient && height == null;
                CalculateBackgroundWidth(width, areaWidth, needScale, image, widthAndHeight);
            }
            if (height != null && height.GetValue() >= 0)
            {
                bool needScale = !isGradient && width == null;
                CalculateBackgroundHeight(height, areaHeight, needScale, image, widthAndHeight);
            }
            SetDefaultSizeIfNull(widthAndHeight, areaWidth, areaHeight, image, isGradient);
            return(new float[] { (float)widthAndHeight[0], (float)widthAndHeight[1] });
        }