using System; using System.Drawing; using System.ComponentModel; namespace Volian.Svg.Library { [TypeConverter(typeof(ViewBoxTypeConverter))] public class SvgViewBox { #region ctor public SvgViewBox() { ;} public SvgViewBox(float x, float y, float width, float height) => _MyRectangleF = new RectangleF(x, y, width, height); public SvgViewBox(string val) { string[] parms = ((string)val).Split(' '); _MyRectangleF = new RectangleF(Convert.ToSingle(parms[0]), Convert.ToSingle(parms[1]), Convert.ToSingle(parms[2]), Convert.ToSingle(parms[3])); } #endregion #region Public Properties private RectangleF _MyRectangleF = new RectangleF(); public float X { get { return _MyRectangleF.X; } set { _MyRectangleF.X = value; } } public float Y { get { return _MyRectangleF.Y; } set { _MyRectangleF.Y = value; } } public float Width { get { return _MyRectangleF.Width; } set { _MyRectangleF.Width = value; } } public float Height { get { return _MyRectangleF.Height; } set { _MyRectangleF.Height = value; } } #endregion #region ToString public override string ToString() => string.Format("{0} {1} {2} {3}", X, Y, Width, Height); #endregion } public class ViewBoxTypeConverter : ExpandableObjectConverter { public override bool CanConvertTo(ITypeDescriptorContext context, Type t) => t == typeof(string); public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) => destType == typeof(string) && value is SvgViewBox ? value.ToString() : base.ConvertTo(context, culture, value, destType); public override bool CanConvertFrom(ITypeDescriptorContext context, Type t) => t == typeof(string); public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object val) { string[] parms = ((string)val).Split(' '); SvgViewBox viewBox = new SvgViewBox(Convert.ToSingle(parms[0]), Convert.ToSingle(parms[1]), Convert.ToSingle(parms[2]), Convert.ToSingle(parms[3])); return viewBox; } } }