public void ParseColorStopWithoutValue() { var stop = ColorStop.Parse("#00a, #fff, #000"); Assert.Equal(Rgba32.Parse("#00a"), stop.Color); Assert.Null(stop.Position); }
public void ParseColorStop() { var stop = ColorStop.Parse("#00a 90%"); Assert.Equal(Rgba32.Parse("#00a"), stop.Color); Assert.Equal(0.9, stop.Position); }
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()))); }
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); }
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))); }
private static Rgba32 GetColor(CssValue value) => Rgba32.Parse(value.ToString());