public BoxShadow(String value,
                         IStyleVariableAccessor variableAccessor)
        {
            List <String> tokens;

            var rgbIndex = value.IndexOf("rgb", StringComparison.OrdinalIgnoreCase);

            if (rgbIndex < 0)
            {
                tokens = new List <String>(value.Split());
            }
            else
            {
                var preRgb = value.Substring(0, rgbIndex - 1);
                tokens = new List <String>(preRgb.Split());

                var withRgb = value.Substring(rgbIndex);
                tokens.Add(withRgb);
            }

            switch (tokens.Count)
            {
            case 5:
                SpreadRadius = new QuantityDeclaration(tokens[3],
                                                       variableAccessor, DeclarationProperty.BoxShadow);
                goto case 4;

            case 4:
                BlurRadius = new QuantityDeclaration(tokens[2],
                                                     variableAccessor, DeclarationProperty.BoxShadow);
                break;
            }

            OffsetY = new QuantityDeclaration(tokens[1],
                                              variableAccessor, DeclarationProperty.BoxShadow);

            OffsetX = new QuantityDeclaration(tokens[0],
                                              variableAccessor, DeclarationProperty.BoxShadow);

            Color = new ColorDeclaration(tokens[tokens.Count - 1], DeclarationProperty.BoxShadow,
                                         variableAccessor);
        }
Esempio n. 2
0
        public OutlineDeclaration(String value,
                                  IStyleVariableAccessor variableAccessor)
            : base(variableAccessor, DeclarationProperty.Outline)
        {
            var tokens = value.Split();

            for (var c = 0; c < tokens.Length; c++)
            {
                var token = tokens[c];

                if (Style == null)
                {
                    var styleIs = GetEnumValue(token, OutlineStyle.Invalid);
                    if (styleIs != OutlineStyle.Invalid)
                    {
                        Style = new OutlineStyleDeclaration(token, variableAccessor);
                        continue;
                    }
                }

                if (Width == null)
                {
                    if (QuantityDeclaration.IsValidQuantity(token))
                    {
                        Width = new OutlineWidthDeclaration(token, variableAccessor);
                        continue;
                    }
                }

                Color = new OutlineColorDeclaration(value, variableAccessor);
            }

            if (Style == null)
            {
                throw new InvalidOperationException();
            }
        }