Example #1
0
        Color ParseStopColor(SvgStopElement stop)
        {
            var color   = new SvgColor((string)stop.Style.Get("stop-color"));
            var opacity = float.Parse((string)stop.Style.Get("stop-opacity"), CultureInfo.InvariantCulture);

            return(Color.FromArgb((int)(255 * opacity), color.Color));
        }
Example #2
0
        private GradientStopCollection GetGradientStops(XmlNodeList stops)
        {
            int itemCount = stops.Count;
            GradientStopCollection gradientStops = new GradientStopCollection(itemCount);

            double lastOffset = 0;

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

                double offset = stop.Offset.AnimVal;

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

                gradientStops.Add(new GradientStop(svgColor.Color, offset));
                lastOffset = offset;
            }

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

            return(gradientStops);
        }
Example #3
0
        public static GradientStopCollection ToGradientStops(System.Xml.XmlNodeList stops)
        {
            int itemCount = stops.Count;
            GradientStopCollection gradientStops = new GradientStopCollection(itemCount);

            double lastOffset = 0;

            for (int i = 0; i < itemCount; i++)
            {
                SvgStopElement stop  = (SvgStopElement)stops.Item(i);
                string         prop  = stop.GetAttribute("stop-color");
                string         style = stop.GetAttribute("style");
                Color          color = Colors.Transparent; // no auto-inherited...
                if (!string.IsNullOrWhiteSpace(prop) || !string.IsNullOrWhiteSpace(style))
                {
                    SvgColor svgColor = new SvgColor(stop.GetComputedStyle(string.Empty).GetPropertyValue("stop-color"));
                    if (svgColor.ColorType == SvgColorType.CurrentColor)
                    {
                        string sCurColor = stop.GetComputedStyle(string.Empty).GetPropertyValue(CssConstants.PropColor);
                        svgColor = new SvgColor(sCurColor);
                    }
                    TryConvertColor(svgColor.RgbColor, out color);
                }
                else
                {
                    color = Colors.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.AnimVal;

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

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

            return(gradientStops);
        }
        private GradientStopCollection GetGradientStops(XmlNodeList stops)
        {
            int itemCount = stops.Count;
            GradientStopCollection gradientStops = new GradientStopCollection(itemCount);

            double lastOffset = 0;

            for (int i = 0; i < itemCount; i++)
            {
                SvgStopElement stop  = (SvgStopElement)stops.Item(i);
                string         prop  = stop.GetAttribute("stop-color");
                string         style = stop.GetAttribute("style");
                Color          color = Colors.Transparent; // no auto-inherited...
                if (!String.IsNullOrEmpty(prop) || !String.IsNullOrEmpty(style))
                {
                    WpfSvgColor svgColor = new WpfSvgColor(stop, "stop-color");
                    color = svgColor.Color;
                }
                else
                {
                    color = Colors.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 (opacity != null && opacity.Length > 0)
                    {
                        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.AnimVal;

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

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

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

            return(gradientStops);
        }
Example #5
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);
        }
Example #6
0
        private List <float> GetPositions(XmlNodeList stops)
        {
            List <float> positions = new List <float>(stops.Count);
            float        lastPos   = 0;

            for (int i = 0; i < stops.Count; i++)
            {
                SvgStopElement stop = (SvgStopElement)stops.Item(i);
                float          pos  = (float)stop.Offset.AnimVal;

                pos /= 100;
                pos  = Math.Max(lastPos, pos);

                positions.Add(pos);
                lastPos = pos;
            }

            return(positions);
        }
Example #7
0
 public virtual void VisitStopElement(SvgStopElement element)
 => DefaultVisit(element);
Example #8
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);
        }