using System; using System.Collections.Generic; using System.Text; using System.Drawing; namespace Svg { public sealed class SvgColourServer : SvgPaintServer { /// /// An unspecified . /// public static readonly SvgPaintServer NotSet = new SvgColourServer(System.Drawing.Color.Black); /// /// A that should inherit from its parent. /// public static readonly SvgPaintServer Inherit = new SvgColourServer(System.Drawing.Color.Black); public SvgColourServer() : this(System.Drawing.Color.Black) { } public SvgColourServer(Color colour) { this._colour = colour; } private Color _colour; public Color Colour { get { return this._colour; } set { this._colour = value; } } public override Brush GetBrush(SvgVisualElement styleOwner, ISvgRenderer renderer, float opacity) { //is none? if (this == SvgPaintServer.None) return new SolidBrush(System.Drawing.Color.Transparent); int alpha = (int)((opacity * (this.Colour.A/255.0f) ) * 255); Color colour = System.Drawing.Color.FromArgb(alpha, this.Colour); return new SolidBrush(colour); } public override string ToString() { if(this == SvgPaintServer.None) return "none"; else if(this == SvgColourServer.NotSet) return ""; Color c = this.Colour; // Return the name if it exists if (c.IsKnownColor) { return c.Name; } // Return the hex value return String.Format("#{0}", c.ToArgb().ToString("x").Substring(2)); } public override SvgElement DeepCopy() { return DeepCopy(); } public override SvgElement DeepCopy() { var newObj = base.DeepCopy() as SvgColourServer; newObj.Colour = this.Colour; return newObj; } public override bool Equals(object obj) { var objColor = obj as SvgColourServer; if (objColor == null) return false; return this.GetHashCode() == objColor.GetHashCode(); } public override int GetHashCode() { return _colour.GetHashCode(); } } }