Ejemplo n.º 1
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);
        }
        Boolean CheckIdentifier(CSSPrimitiveValue ident)
        {
            _resets.Clear();

            if (!ident.Is(Keywords.None))
            {
                _resets.Add(ident.GetString(), 0);
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a single value from the given source.
        /// </summary>
        /// <param name="source">The token iterator.</param>
        /// <returns>The value or NULL.</returns>
        CSSValue CreateValue(IEnumerator<CssToken> source)
        {
            CSSValue value = null;

            switch (source.Current.Type)
            {
                case CssTokenType.String:// 'i am a string'
                    value = new CSSPrimitiveValue(UnitType.String, ((CssStringToken)source.Current).Data);
                    break;

                case CssTokenType.Url:// url('this is a valid URL')
                    value = new CSSPrimitiveValue(UnitType.Uri, ((CssStringToken)source.Current).Data);
                    break;

                case CssTokenType.Ident: // ident
                    value = new CSSPrimitiveValue(UnitType.Ident, ((CssKeywordToken)source.Current).Data);
                    break;

                case CssTokenType.Percentage: // 5%
                    value = new CSSPrimitiveValue(UnitType.Percentage, ((CssUnitToken)source.Current).Data);
                    break;

                case CssTokenType.Dimension: // 3px
                    value = new CSSPrimitiveValue(((CssUnitToken)source.Current).Unit, ((CssUnitToken)source.Current).Data);
                    break;

                case CssTokenType.Number: // 173
                    value = new CSSPrimitiveValue(UnitType.Number, ((CssNumberToken)source.Current).Data);
                    break;

                case CssTokenType.Hash: // #string
                    HtmlColor color;

                    if(HtmlColor.TryFromHex(((CssKeywordToken)source.Current).Data, out color))
                        value = new CSSPrimitiveValue(color);

                    break;

                case CssTokenType.Delim: // e.g. #0F3, #012345, ...
                    if (((CssDelimToken)source.Current).Data == '#')
                    {
                        String hash = String.Empty;

                        while (source.MoveNext())
                        {
                            var stop = false;

                            switch (source.Current.Type)
                            {
                                case CssTokenType.Number:
                                case CssTokenType.Dimension:
                                case CssTokenType.Ident:
                                    var rest = source.Current.ToValue();

                                    if (hash.Length + rest.Length <= 6)
                                        hash += rest;
                                    else
                                        stop = true;

                                    break;

                                default:
                                    stop = true;
                                    break;
                            }

                            if (stop || hash.Length == 6)
                                break;
                        }

                        if (HtmlColor.TryFromHex(hash, out color))
                            value = new CSSPrimitiveValue(color);
                    }
                    break;

                case CssTokenType.Function: // rgba(255, 255, 20, 0.5)
                    value = CreateFunction(source);
                    break;
            }

            return value;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Changes the value of X Y and Z to the given value.
 /// </summary>
 /// <param name="value">The value to set for all values.</param>
 public void ChangeAllTo(CSSPrimitiveValue value)
 {
     X = value;
     Y = value;
     Z = value;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Sets the values of all sides to the given value.
 /// </summary>
 /// <param name="value">The value to apply.</param>
 public void SetAllSides(CSSPrimitiveValue value)
 {
     Top = value;
     Right = value;
     Bottom = value;
     Left = value;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Sets the value for the given side.
 /// </summary>
 /// <param name="side">The side to change.</param>
 /// <param name="value">The value to apply.</param>
 public void SetSide(CssSide side, CSSPrimitiveValue value)
 {
     switch (side)
     {
         case CssSide.Top:
             Top = value;
             break;
         case CssSide.Right:
             Right = value;
             break;
         case CssSide.Bottom:
             Bottom = value;
             break;
         case CssSide.Left:
             Left = value;
             break;
     }
 }