Ejemplo n.º 1
0
        static CSSImageValue Image(List <CSSValue> arguments)
        {
            if (arguments.Count == 0)
            {
                return(null);
            }

            var imageList = new List <Location>();

            foreach (var argument in arguments)
            {
                var uri = argument.ToUri();

                if (uri == null)
                {
                    if (argument is CSSStringValue)
                    {
                        uri = new Location(((CSSStringValue)argument).Value);
                    }
                    else
                    {
                        return(null);
                    }
                }

                imageList.Add(uri);
            }

            return(CSSImageValue.FromUrls(imageList));
        }
Ejemplo n.º 2
0
        static CSSImageValue GeneralLinearGradient(List <CSSValue> arguments, Boolean repeating)
        {
            if (arguments.Count > 1)
            {
                var direction = Angle.Zero;
                var angle     = arguments[0].ToAngle();
                var offset    = 0;

                if (angle.HasValue)
                {
                    direction = angle.Value;
                    offset++;
                }

                var stops = new CSSImageValue.GradientStop[arguments.Count - offset];

                if (stops.Length > 1)
                {
                    var perStop = 100f / (arguments.Count - offset - 1);

                    for (int i = offset, k = 0; i < arguments.Count; i++, k++)
                    {
                        CSSPrimitiveValue <Color> color = null;
                        var location = CSSCalcValue.FromPercent(new Percent(perStop * k));

                        if (arguments[i] is CSSValueList)
                        {
                            var list = (CSSValueList)arguments[i];

                            if (list.Length != 2)
                            {
                                return(null);
                            }

                            color    = list[0].AsColor();
                            location = list[1].AsCalc();
                        }
                        else
                        {
                            color = arguments[i].AsColor();
                        }

                        if (color == null || location == null)
                        {
                            return(null);
                        }

                        stops[k] = new CSSImageValue.GradientStop(color.Value, location);
                    }

                    return(CSSImageValue.FromLinearGradient(direction, repeating, stops));
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public static CSSImageValue AsImage(this CSSValue value)
        {
            if (value is CSSImageValue)
            {
                return((CSSImageValue)value);
            }
            else if (value is CSSPrimitiveValue <Location> )
            {
                return(CSSImageValue.FromUrl(((CSSPrimitiveValue <Location>)value).Value));
            }
            else if (value.Is("none"))
            {
                return(CSSImageValue.None);
            }

            return(null);
        }