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.Collections;
\r
16 using System.ComponentModel;
\r
17 using System.Globalization;
\r
19 using System.Web.UI;
\r
21 namespace System.Web.UI.WebControls
\r
23 [TypeConverter(typeof(FontUnitConverter))]
\r
24 public struct FontUnit
\r
26 public static readonly FontUnit Empty = new FontUnit();
\r
27 public static readonly FontUnit Large = new FontUnit(FontSize.Large);
\r
28 public static readonly FontUnit Larger = new FontUnit(FontSize.Larger);
\r
29 public static readonly FontUnit Medium = new FontUnit(FontSize.Medium);
\r
30 public static readonly FontUnit Small = new FontUnit(FontSize.Small);
\r
31 public static readonly FontUnit Smaller = new FontUnit(FontSize.Smaller);
\r
32 public static readonly FontUnit XLarge = new FontUnit(FontSize.XLarge);
\r
33 public static readonly FontUnit XSmall = new FontUnit(FontSize.XSmall);
\r
34 public static readonly FontUnit XXLarge = new FontUnit(FontSize.XXLarge);
\r
35 public static readonly FontUnit XXSmall = new FontUnit(FontSize.XXSmall);
\r
37 private FontSize type;
\r
40 private static Hashtable sizeTable;
\r
44 sizeTable = new Hashtable (CaseInsensitiveHashCodeProvider.Default,
\r
45 CaseInsensitiveComparer.Default);
\r
46 sizeTable.Add ("smaller", 2);
\r
47 sizeTable.Add ("larger", 3);
\r
48 sizeTable.Add ("xx-small", 4);
\r
49 sizeTable.Add ("xxsmall", 4);
\r
50 sizeTable.Add ("x-small", 5);
\r
51 sizeTable.Add ("xsmall", 5);
\r
52 sizeTable.Add ("small", 6);
\r
53 sizeTable.Add ("medium", 7);
\r
54 sizeTable.Add ("large", 8);
\r
55 sizeTable.Add ("xlarge", 9);
\r
56 sizeTable.Add ("x-large", 9);
\r
57 sizeTable.Add ("xxlarge", 10);
\r
58 sizeTable.Add ("xx-large", 10);
\r
61 public FontUnit(FontSize type)
\r
63 if(!Enum.IsDefined(typeof(FontSize), type))
\r
64 throw new ArgumentException();
\r
66 if(this.type == FontSize.AsUnit)
\r
68 val = Unit.Point(10);
\r
75 public FontUnit(int value)
\r
77 type = FontSize.AsUnit;
\r
78 val = Unit.Point(value);
\r
81 public FontUnit(string value): this(value, CultureInfo.CurrentCulture)
\r
85 public FontUnit(Unit value)
\r
89 type = FontSize.NotSet;
\r
93 type = FontSize.AsUnit;
\r
98 public FontUnit(string value, CultureInfo culture)
\r
100 type = FontSize.NotSet;
\r
102 if(value != null && value != String.Empty)
\r
104 string low = value.ToLower(culture);
\r
105 int size = GetTypeFromString(low);
\r
108 type = (FontSize)size;
\r
110 val = new Unit(value, culture, UnitType.Point);
\r
111 type = FontSize.AsUnit;
\r
116 private static int GetTypeFromString(string strVal)
\r
118 if (!(sizeTable.ContainsKey (strVal)))
\r
120 return (int) sizeTable [strVal];
\r
123 public static FontUnit Parse(string s)
\r
125 return Parse(s, CultureInfo.CurrentCulture);
\r
128 public static FontUnit Parse(string s, CultureInfo culture)
\r
130 return new FontUnit(s, culture);
\r
133 public static FontUnit Point(int n)
\r
135 return new FontUnit(n);
\r
138 public static bool operator ==(FontUnit left, FontUnit right)
\r
140 return (left.type == right.type && left.val == right.val);
\r
143 public static bool operator !=(FontUnit left, FontUnit right)
\r
145 return !(left == right);
\r
148 public static implicit operator FontUnit(int n)
\r
150 return FontUnit.Point(n);
\r
153 public override bool Equals(object obj)
\r
155 if(obj!= null && obj is FontUnit)
\r
157 FontUnit that = (FontUnit)obj;
\r
158 return (this.type == that.type && this.val == that.val);
\r
163 public override int GetHashCode()
\r
165 return ( (type.GetHashCode() << 2) | val.GetHashCode() );
\r
168 public override string ToString()
\r
170 return ToString(CultureInfo.CurrentCulture);
\r
173 public string ToString(CultureInfo culture)
\r
177 return String.Empty;
\r
179 //string strRepr = String.Empty;
\r
182 case FontSize.AsUnit: return val.ToString(culture);
\r
183 case FontSize.XXSmall: return "XX-Small";
\r
184 case FontSize.XSmall: return "X-Small";
\r
185 case FontSize.XLarge: return "X-Large";
\r
186 case FontSize.XXLarge: return "XX-Large";
\r
187 default: return PropertyConverter.EnumToString(typeof(FontSize), type);
\r
191 public bool IsEmpty
\r
195 return (type == FontSize.NotSet);
\r
199 public FontSize Type
\r