using System; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml; using System.Web.UI.WebControls; using System.ComponentModel; namespace Svg { /// /// An SVG element to render circles to the document. /// [SvgElement("circle")] public class SvgCircle : SvgVisualElement { private GraphicsPath _path; private SvgUnit _radius; private SvgUnit _centerX; private SvgUnit _centerY; /// /// Gets the center point of the circle. /// /// The center. public SvgPoint Center { get { return new SvgPoint(this.CenterX, this.CenterY); } } [SvgAttribute("cx")] public virtual SvgUnit CenterX { get { return this._centerX; } set { if(_centerX != value) { this._centerX = value; this.IsPathDirty = true; OnAttributeChanged(new AttributeEventArgs{ Attribute = "cx", Value = value }); } } } [SvgAttribute("cy")] public virtual SvgUnit CenterY { get { return this._centerY; } set { if(_centerY != value) { this._centerY = value; this.IsPathDirty = true; OnAttributeChanged(new AttributeEventArgs{ Attribute = "cy", Value = value }); } } } [SvgAttribute("r")] public virtual SvgUnit Radius { get { return this._radius; } set { if(_radius != value) { this._radius = value; this.IsPathDirty = true; OnAttributeChanged(new AttributeEventArgs{ Attribute = "r", Value = value }); } } } /// /// Gets the bounds of the circle. /// /// The rectangular bounds of the circle. public override RectangleF Bounds { get { return this.Path(null).GetBounds(); } } /// /// Gets a value indicating whether the circle requires anti-aliasing when being rendered. /// /// /// true if the circle requires anti-aliasing; otherwise, false. /// protected override bool RequiresSmoothRendering { get { return true; } } /// /// Gets the representing this element. /// public override GraphicsPath Path(ISvgRenderer renderer) { if (this._path == null || this.IsPathDirty) { _path = new GraphicsPath(); _path.StartFigure(); var center = this.Center.ToDeviceValue(renderer, this); var radius = this.Radius.ToDeviceValue(renderer, UnitRenderingType.Other, this); _path.AddEllipse(center.X - radius, center.Y - radius, 2 * radius, 2 * radius); _path.CloseFigure(); this.IsPathDirty = false; } return _path; } /// /// Renders the circle to the specified object. /// /// The graphics object. protected override void Render(ISvgRenderer renderer) { // Don't draw if there is no radius set if (this.Radius.Value > 0.0f) { base.Render(renderer); } } /// /// Initializes a new instance of the class. /// public SvgCircle() { CenterX = new SvgUnit(0.0f); CenterY = new SvgUnit(0.0f); } public override SvgElement DeepCopy() { return DeepCopy(); } public override SvgElement DeepCopy() { var newObj = base.DeepCopy() as SvgCircle; newObj.CenterX = this.CenterX; newObj.CenterY = this.CenterY; newObj.Radius = this.Radius; return newObj; } } }