Exemplo n.º 1
0
        public void ParseColorStopWithoutValue()
        {
            var stop = ColorStop.Parse("#00a, #fff, #000");

            Assert.Equal(Rgba32.Parse("#00a"), stop.Color);
            Assert.Null(stop.Position);
        }
Exemplo n.º 2
0
        public void ParseColorStop()
        {
            var stop = ColorStop.Parse("#00a 90%");

            Assert.Equal(Rgba32.Parse("#00a"), stop.Color);
            Assert.Equal(0.9, stop.Position);
        }
Exemplo n.º 3
0
        public static CssValue Rgba(CssValue[] args)
        {
            if (args.Length == 4)
            {
                return(new CssFunction("rgba", new CssValueList(args)));
            }

            var color = Rgba32.Parse(args[0].ToString());

            return(CssColor.FromRgba(color.R, color.G, color.B, float.Parse(args[1].ToString())));
        }
Exemplo n.º 4
0
        public void ParseColorStopList()
        {
            var text = "#00a 90%, #000 91%, #fff 92%".AsSpan();

            int read;

            var stop1 = ColorStop.Read(text, out read);

            Assert.Equal(8, read);

            var stop2 = ColorStop.Read(text.Slice(read + 2), out read);

            Assert.Equal(8, read);

            Assert.Equal(Rgba32.Parse("#00a"), (Rgba32)stop1.Color);
            Assert.Equal(0.9, stop1.Position);

            Assert.Equal(Rgba32.Parse("#000"), (Rgba32)stop2.Color);
        }
Exemplo n.º 5
0
        public static Rgba32 ReadColor(this ReadOnlySpan <char> text, out int read)
        {
            read = 0;

            char current;

            bool isFunction = false;

            while (read < text.Length)
            {
                current = text[read];

                // if we detect a function, read until )
                // otherwise, read until end or space

                if (isFunction)
                {
                    if (current == ')')
                    {
                        read++;
                        break;
                    }
                }
                else if (current == '(')
                {
                    isFunction = true;
                }
                else if (current == ' ' || current == ',')
                {
                    break;
                }

                read++;
            }

            return(Rgba32.Parse(text.Slice(0, read)));
        }
Exemplo n.º 6
0
 private static Rgba32 GetColor(CssValue value) => Rgba32.Parse(value.ToString());