protected GradientBrush GetGradientBrush(string fill, GradientBrush child) { XElement defE; if (defs.TryGetValue (fill, out defE)) { GradientBrush brush = null; switch (defE.Name.LocalName) { case "linearGradient": brush = CreateLinearGradientBrush (defE); break; case "radialGradient": brush = CreateRadialGradientBrush (defE); break; default: throw new NotSupportedException ("Fill " + defE.Name); } if (child != null) { if (child is RadialGradientBrush && brush is RadialGradientBrush) { ((RadialGradientBrush)brush).Center = ((RadialGradientBrush)child).Center; ((RadialGradientBrush)brush).Focus = ((RadialGradientBrush)child).Focus; ((RadialGradientBrush)brush).Radius = ((RadialGradientBrush)child).Radius; } else if (child is LinearGradientBrush && brush is LinearGradientBrush) { ((LinearGradientBrush)brush).Start = ((LinearGradientBrush)child).Start; ((LinearGradientBrush)brush).End = ((LinearGradientBrush)child).End; } brush.AddStops(child.Stops); } XNamespace xlink = "http://www.w3.org/1999/xlink"; var parent = defE.Attribute(xlink + "href"); if (parent != null && !string.IsNullOrEmpty(parent.Value)) { brush = GetGradientBrush(parent.Value.Substring(1), brush); } return brush; } else { throw new Exception ("Invalid fill url reference: " + fill); } }
void WriteStops (GradientBrush gb) { w.Indent (); foreach (var s in gb.Stops) { w.Write ("<stop stop-color=\"{0}\" offset=\"{1}%\"", s.Color.HtmlString, s.Offset*100); if (s.Color.A != 255) { w.Write (" stop-opacity=\"{0}\"", s.Color.Alpha); } w.WriteLine (" />", s.Color.HtmlString, s.Offset*100); } w.Outdent (); }