Esempio n. 1
0
        private static void ScaleHeight(float newHeight, BackgroundImage image, float?[] imageWidthAndHeight)
        {
            float difference = image.GetImageHeight() == 0f ? 1f : newHeight / image.GetImageHeight();

            imageWidthAndHeight[0] = image.GetImageWidth() * difference;
            imageWidthAndHeight[1] = newHeight;
        }
        private static void ApplyBackgroundSize(IList <IList <String> > backgroundProperties, float em, float rem, int
                                                imageIndex, BackgroundImage image)
        {
            if (backgroundProperties == null || backgroundProperties.IsEmpty())
            {
                return;
            }
            if (image.GetForm() != null && (image.GetImageHeight() == 0f || image.GetImageWidth() == 0f))
            {
                return;
            }
            IList <String> backgroundSizeValues = backgroundProperties[GetBackgroundSidePropertyIndex(backgroundProperties
                                                                                                      .Count, imageIndex)];

            if (backgroundSizeValues.Count == 2 && CommonCssConstants.AUTO.Equals(backgroundSizeValues[1]))
            {
                backgroundSizeValues.JRemoveAt(1);
            }
            if (backgroundSizeValues.Count == 1)
            {
                String widthValue = backgroundSizeValues[0];
                ApplyBackgroundWidth(widthValue, image, em, rem);
            }
            if (backgroundSizeValues.Count == 2)
            {
                ApplyBackgroundWidthHeight(backgroundSizeValues, image, em, rem);
            }
        }
Esempio n. 3
0
        private static void SetDefaultSizeIfNull(float?[] widthAndHeight, float areaWidth, float areaHeight, BackgroundImage
                                                 image, bool isGradient)
        {
            if (isGradient)
            {
                widthAndHeight[0] = widthAndHeight[0] == null ? areaWidth : widthAndHeight[0];
                widthAndHeight[1] = widthAndHeight[1] == null ? areaHeight : widthAndHeight[1];
            }
            else
            {
                widthAndHeight[0] = widthAndHeight[0] == null?image.GetImageWidth() : widthAndHeight[0];

                widthAndHeight[1] = widthAndHeight[1] == null?image.GetImageHeight() : widthAndHeight[1];
            }
        }
Esempio n. 4
0
        private static BackgroundSize CalculateBackgroundSizeForArea(BackgroundImage image, float areaWidth, float
                                                                     areaHeight)
        {
            double widthDifference  = areaWidth / image.GetImageWidth();
            double heightDifference = areaHeight / image.GetImageHeight();

            if (image.GetBackgroundSize().IsCover())
            {
                return(CreateSizeWithMaxValueSide(widthDifference > heightDifference));
            }
            else
            {
                if (image.GetBackgroundSize().IsContain())
                {
                    return(CreateSizeWithMaxValueSide(widthDifference < heightDifference));
                }
                else
                {
                    return(new BackgroundSize());
                }
            }
        }