using System; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Drawing.Drawing2D; namespace Svg { public sealed class SvgRadialGradientServer : SvgGradientServer { [SvgAttribute("cx")] public SvgUnit CenterX { get { return this.Attributes.GetAttribute("cx"); } set { this.Attributes["cx"] = value; } } [SvgAttribute("cy")] public SvgUnit CenterY { get { return this.Attributes.GetAttribute("cy"); } set { this.Attributes["cy"] = value; } } [SvgAttribute("r")] public SvgUnit Radius { get { return this.Attributes.GetAttribute("r"); } set { this.Attributes["r"] = value; } } [SvgAttribute("fx")] public SvgUnit FocalX { get { return this.Attributes.GetAttribute("fx"); } set { this.Attributes["fx"] = value; } } [SvgAttribute("fy")] public SvgUnit FocalY { get { return this.Attributes.GetAttribute("fy"); } set { this.Attributes["fy"] = value; } } /// /// Initializes a new instance of the class. /// public SvgRadialGradientServer() { } /// /// Gets the name of the element. /// protected override string ElementName { get { return "radialGradient"; } } public override Brush GetBrush(SvgGraphicsElement renderingElement, float opacity) { GraphicsPath path = new GraphicsPath(); float left = this.CenterX.ToDeviceValue(renderingElement); float top = this.CenterY.ToDeviceValue(renderingElement, true); float radius = this.Radius.ToDeviceValue(renderingElement); RectangleF boundingBox = (this.GradientUnits == SvgGradientUnit.ObjectBoundingBox) ? renderingElement.Bounds : renderingElement.OwnerDocument.GetDimensions(); path.AddEllipse(left-radius, top-radius, radius*2, radius*2); PathGradientBrush brush = new PathGradientBrush(path); ColorBlend blend = base.GetColourBlend(renderingElement, opacity); brush.InterpolationColors = blend; brush.CenterPoint = new PointF(this.FocalX.ToDeviceValue(renderingElement), this.FocalY.ToDeviceValue(renderingElement, true)); return brush; } } }