3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * Namespace: System.Web.UI.WebControls
\r
26 * Author: Gaurav Vaish
\r
27 * Maintainer: gvaish@iitk.ac.in
\r
28 * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>
\r
29 * Implementation: yes
\r
32 * (C) Gaurav Vaish (2001)
\r
36 using System.Collections;
\r
37 using System.ComponentModel;
\r
38 using System.Globalization;
\r
40 using System.Web.UI;
\r
42 namespace System.Web.UI.WebControls
\r
44 [TypeConverter(typeof(FontUnitConverter))]
\r
45 public struct FontUnit
\r
47 public static readonly FontUnit Empty = new FontUnit();
\r
48 public static readonly FontUnit Large = new FontUnit(FontSize.Large);
\r
49 public static readonly FontUnit Larger = new FontUnit(FontSize.Larger);
\r
50 public static readonly FontUnit Medium = new FontUnit(FontSize.Medium);
\r
51 public static readonly FontUnit Small = new FontUnit(FontSize.Small);
\r
52 public static readonly FontUnit Smaller = new FontUnit(FontSize.Smaller);
\r
53 public static readonly FontUnit XLarge = new FontUnit(FontSize.XLarge);
\r
54 public static readonly FontUnit XSmall = new FontUnit(FontSize.XSmall);
\r
55 public static readonly FontUnit XXLarge = new FontUnit(FontSize.XXLarge);
\r
56 public static readonly FontUnit XXSmall = new FontUnit(FontSize.XXSmall);
\r
58 private FontSize type;
\r
61 private static Hashtable sizeTable;
\r
65 sizeTable = new Hashtable (CaseInsensitiveHashCodeProvider.Default,
\r
66 CaseInsensitiveComparer.Default);
\r
67 sizeTable.Add ("smaller", 2);
\r
68 sizeTable.Add ("larger", 3);
\r
69 sizeTable.Add ("xx-small", 4);
\r
70 sizeTable.Add ("xxsmall", 4);
\r
71 sizeTable.Add ("x-small", 5);
\r
72 sizeTable.Add ("xsmall", 5);
\r
73 sizeTable.Add ("small", 6);
\r
74 sizeTable.Add ("medium", 7);
\r
75 sizeTable.Add ("large", 8);
\r
76 sizeTable.Add ("xlarge", 9);
\r
77 sizeTable.Add ("x-large", 9);
\r
78 sizeTable.Add ("xxlarge", 10);
\r
79 sizeTable.Add ("xx-large", 10);
\r
82 public FontUnit(FontSize type)
\r
84 if(!Enum.IsDefined(typeof(FontSize), type))
\r
85 throw new ArgumentException();
\r
87 if(this.type == FontSize.AsUnit)
\r
89 val = Unit.Point(10);
\r
96 public FontUnit(int value)
\r
98 type = FontSize.AsUnit;
\r
99 val = Unit.Point(value);
\r
102 public FontUnit(string value): this(value, CultureInfo.CurrentCulture)
\r
106 public FontUnit(Unit value)
\r
110 type = FontSize.NotSet;
\r
114 type = FontSize.AsUnit;
\r
119 public FontUnit(string value, CultureInfo culture)
\r
121 type = FontSize.NotSet;
\r
123 if(value != null && value != String.Empty)
\r
125 string low = value.ToLower(culture);
\r
126 int size = GetTypeFromString(low);
\r
129 type = (FontSize)size;
\r
131 val = new Unit(value, culture, UnitType.Point);
\r
132 type = FontSize.AsUnit;
\r
137 private static int GetTypeFromString(string strVal)
\r
139 if (!(sizeTable.ContainsKey (strVal)))
\r
141 return (int) sizeTable [strVal];
\r
144 public static FontUnit Parse(string s)
\r
146 return Parse(s, CultureInfo.CurrentCulture);
\r
149 public static FontUnit Parse(string s, CultureInfo culture)
\r
151 return new FontUnit(s, culture);
\r
154 public static FontUnit Point(int n)
\r
156 return new FontUnit(n);
\r
159 public static bool operator ==(FontUnit left, FontUnit right)
\r
161 return (left.type == right.type && left.val == right.val);
\r
164 public static bool operator !=(FontUnit left, FontUnit right)
\r
166 return !(left == right);
\r
169 public static implicit operator FontUnit(int n)
\r
171 return FontUnit.Point(n);
\r
174 public override bool Equals(object obj)
\r
176 if(obj!= null && obj is FontUnit)
\r
178 FontUnit that = (FontUnit)obj;
\r
179 return (this.type == that.type && this.val == that.val);
\r
184 public override int GetHashCode()
\r
186 return ( (type.GetHashCode() << 2) | val.GetHashCode() );
\r
189 public override string ToString()
\r
191 return ToString(CultureInfo.CurrentCulture);
\r
194 public string ToString(CultureInfo culture)
\r
198 return String.Empty;
\r
200 //string strRepr = String.Empty;
\r
203 case FontSize.AsUnit: return val.ToString(culture);
\r
204 case FontSize.XXSmall: return "XX-Small";
\r
205 case FontSize.XSmall: return "X-Small";
\r
206 case FontSize.XLarge: return "X-Large";
\r
207 case FontSize.XXLarge: return "XX-Large";
\r
208 default: return PropertyConverter.EnumToString(typeof(FontSize), type);
\r
212 public bool IsEmpty
\r
216 return (type == FontSize.NotSet);
\r
220 public FontSize Type
\r