2 * Namespace: System.Web.UI.WebControls
\r
5 * Author: Gaurav Vaish
\r
6 * Maintainer: gvaish@iitk.ac.in
\r
7 * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>
\r
8 * Implementation: yes
\r
11 * (C) Gaurav Vaish (2001)
\r
15 using System.Globalization;
\r
17 using System.Web.UI;
\r
19 namespace System.Web.UI.WebControls
\r
21 public struct FontUnit
\r
23 public static readonly FontUnit Empty = new FontUnit();
\r
24 public static readonly FontUnit Large = new FontUnit(FontSize.Large);
\r
25 public static readonly FontUnit Larger = new FontUnit(FontSize.Larger);
\r
26 public static readonly FontUnit Medium = new FontUnit(FontSize.Medium);
\r
27 public static readonly FontUnit Small = new FontUnit(FontSize.Small);
\r
28 public static readonly FontUnit Smaller = new FontUnit(FontSize.Smaller);
\r
29 public static readonly FontUnit XLarge = new FontUnit(FontSize.XLarge);
\r
30 public static readonly FontUnit XSmall = new FontUnit(FontSize.XSmall);
\r
31 public static readonly FontUnit XXLarge = new FontUnit(FontSize.XXLarge);
\r
32 public static readonly FontUnit XXSmall = new FontUnit(FontSize.XXSmall);
\r
34 private FontSize type;
\r
37 public FontUnit(FontSize type)
\r
39 if(!Enum.IsDefined(typeof(FontSize), type))
\r
40 throw new ArgumentException();
\r
42 if(this.type == FontSize.AsUnit)
\r
44 val = Unit.Point(10);
\r
51 public FontUnit(int value)
\r
53 type = FontSize.AsUnit;
\r
54 val = Unit.Point(value);
\r
57 public FontUnit(string value): this(value, CultureInfo.CurrentCulture)
\r
61 public FontUnit(Unit value)
\r
65 type = FontSize.NotSet;
\r
69 type = FontSize.AsUnit;
\r
74 public FontUnit(string value, CultureInfo culture)
\r
76 type = FontSize.NotSet;
\r
78 if(value != null && value != String.Empty)
\r
80 string low = value.ToLower(culture);
\r
81 int index = GetTypeFromString(low);
\r
84 type = (FontSize)fs;
\r
88 val = new Unit(value, culture, UnitType.Point);
\r
89 type = FontSize.AsUnit;
\r
94 private int GetTypeFromString(string strVal)
\r
108 foreach(string valType in values)
\r
110 if(strVal == valType)
\r
119 public static FontUnit Parse(string s): Parse(s, CultureInfo.CurrentCulture)
\r
123 public static FontUnit Parse(string s, CultureInfo culture)
\r
125 return new FontUnit(s, culture);
\r
128 public static FontUnit Point(int n)
\r
130 return new FontUnit(n);
\r
133 public static bool operator ==(FontUnit left, FontUnit right)
\r
135 return (left.type == right.type && left.val == right.val);
\r
138 public static bool operator !=(FontUnit left, FontUnit right)
\r
140 return !(left == right);
\r
143 public static implicit operator FontUnit(int n)
\r
145 return FontUnit.Point(n);
\r
148 public override bool Equals(object obj)
\r
150 if(obj!= null && obj is FontUnit)
\r
152 FontUnit that = (FontUnit)obj;
\r
153 return (this.type == that.type && this.val == that.val);
\r
158 public override int GetHashCode()
\r
160 return ( (type.GetHashCode() << 2) | val.GetHashCode() );
\r
163 public override string ToString(): ToString(CultureInfo.CurrentCulture)
\r
167 public override string ToString(CultureInfo culture)
\r
171 return String.Empty;
\r
173 //string strRepr = String.Empty;
\r
176 case FontSize.AsUnit: return val.ToString(culture);
\r
177 case FontSize.XXSmall: return "XX-Small";
\r
178 case FontSize.XSmall: return "X-Small";
\r
179 case FontSize.XLarge: return "X-Large";
\r
180 case FontSize.XXLarge: return "XX-Large";
\r
181 default: return PropertyConverter.EnumToString(typeof(FontSize), type);
\r
185 public bool IsEmpty
\r
189 return (type == FontSize.NotSet);
\r
193 public FontSize Type
\r