Пример #1
0
        private List <Color> GetColors(XmlNodeList stops)
        {
            List <Color> colors = new List <Color>(stops.Count);

            for (int i = 0; i < stops.Count; i++)
            {
                SvgStopElement stop     = (SvgStopElement)stops.Item(i);
                string         prop     = stop.GetPropertyValue("stop-color");
                GdiSvgColor    svgColor = new GdiSvgColor(stop, "stop-color");

                colors.Add(svgColor.Color);
            }

            return(colors);
        }
Пример #2
0
        protected List <GdiGradientStop> GetGradientStops(XmlNodeList stops)
        {
            int itemCount = stops.Count;

            if (itemCount == 0)
            {
                return(new List <GdiGradientStop>());
            }
            var gradientStops = new List <GdiGradientStop>(itemCount);

            double lastOffset = 0;

            for (int i = 0; i < itemCount; i++)
            {
                SvgStopElement stop = (SvgStopElement)stops.Item(i);
                if (stop == null)
                {
                    continue;
                }
                string prop  = stop.GetAttribute("stop-color");
                string style = stop.GetAttribute("style");
                Color  color = Color.Transparent; // no auto-inherited...
                if (!string.IsNullOrWhiteSpace(prop) || !string.IsNullOrWhiteSpace(style))
                {
                    GdiSvgColor svgColor = new GdiSvgColor(stop, "stop-color");
                    color = svgColor.Color;
                }
                else
                {
                    color = Color.Black; // the default color...
                    double alpha = 255;
                    string opacity;

                    opacity = stop.GetAttribute("stop-opacity"); // no auto-inherit
                    if (opacity == "inherit")                    // if explicitly defined...
                    {
                        opacity = stop.GetPropertyValue("stop-opacity");
                    }
                    if (!string.IsNullOrWhiteSpace(opacity))
                    {
                        alpha *= SvgNumber.ParseNumber(opacity);
                    }

                    alpha = Math.Min(alpha, 255);
                    alpha = Math.Max(alpha, 0);

                    color = Color.FromArgb((byte)Convert.ToInt32(alpha), color.R, color.G, color.B);
                }

                double offset = (stop.Offset == null) ? 0 : stop.Offset.AnimVal;

                offset /= 100;
                offset  = Math.Max(lastOffset, offset);

                gradientStops.Add(new GdiGradientStop(color, (float)offset));
                lastOffset = offset;
            }

            if (itemCount == 0)
            {
                gradientStops.Add(new GdiGradientStop(Color.Black, 0));
                gradientStops.Add(new GdiGradientStop(Color.Black, 1));
            }

            return(gradientStops);
        }
Пример #3
0
        private List<Color> GetColors(XmlNodeList stops)
        {
            List<Color> colors = new List<Color>(stops.Count);
            for (int i = 0; i < stops.Count; i++)
            {
                SvgStopElement stop = (SvgStopElement)stops.Item(i);
                string prop = stop.GetPropertyValue("stop-color");
                GdiSvgColor svgColor = new GdiSvgColor(stop, "stop-color");

                colors.Add(svgColor.Color);
            }

            return colors;
        }