+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
/**\r
* Namespace: System.Web.UI.WebControls\r
* Struct: FontUnit\r
*/\r
\r
using System;\r
+using System.Collections;\r
+using System.ComponentModel;\r
using System.Globalization;\r
using System.Web;\r
using System.Web.UI;\r
\r
namespace System.Web.UI.WebControls\r
{\r
+ [TypeConverter(typeof(FontUnitConverter))]\r
public struct FontUnit\r
{\r
public static readonly FontUnit Empty = new FontUnit();\r
public static readonly FontUnit XSmall = new FontUnit(FontSize.XSmall);\r
public static readonly FontUnit XXLarge = new FontUnit(FontSize.XXLarge);\r
public static readonly FontUnit XXSmall = new FontUnit(FontSize.XXSmall);\r
- \r
+\r
private FontSize type;\r
private Unit val;\r
- \r
+\r
+ private static Hashtable sizeTable;\r
+\r
+ static FontUnit ()\r
+ {\r
+ sizeTable = new Hashtable (CaseInsensitiveHashCodeProvider.Default,\r
+ CaseInsensitiveComparer.Default);\r
+ sizeTable.Add ("smaller", 2);\r
+ sizeTable.Add ("larger", 3);\r
+ sizeTable.Add ("xx-small", 4);\r
+ sizeTable.Add ("xxsmall", 4);\r
+ sizeTable.Add ("x-small", 5);\r
+ sizeTable.Add ("xsmall", 5);\r
+ sizeTable.Add ("small", 6);\r
+ sizeTable.Add ("medium", 7);\r
+ sizeTable.Add ("large", 8);\r
+ sizeTable.Add ("xlarge", 9);\r
+ sizeTable.Add ("x-large", 9);\r
+ sizeTable.Add ("xxlarge", 10);\r
+ sizeTable.Add ("xx-large", 10);\r
+ }\r
+\r
public FontUnit(FontSize type)\r
{\r
if(!Enum.IsDefined(typeof(FontSize), type))\r
val = Unit.Empty;\r
}\r
}\r
- \r
+\r
public FontUnit(int value)\r
{\r
type = FontSize.AsUnit;\r
val = Unit.Point(value);\r
}\r
- \r
+\r
public FontUnit(string value): this(value, CultureInfo.CurrentCulture)\r
{\r
}\r
- \r
+\r
public FontUnit(Unit value)\r
{\r
- if(val.IsEmpty)\r
+ if(value.IsEmpty)\r
{\r
type = FontSize.NotSet;\r
val = Unit.Empty;\r
val = value;\r
}\r
}\r
- \r
+\r
public FontUnit(string value, CultureInfo culture)\r
{\r
type = FontSize.NotSet;\r
if(value != null && value != String.Empty)\r
{\r
string low = value.ToLower(culture);\r
- int index = GetTypeFromString(low);\r
- if( index != -1)\r
- {\r
- type = (FontSize)fs;\r
- return;\r
- } else\r
+ int size = GetTypeFromString(low);\r
+ if (size != -1)\r
{\r
+ type = (FontSize)size;\r
+ } else {\r
val = new Unit(value, culture, UnitType.Point);\r
type = FontSize.AsUnit;\r
}\r
}\r
}\r
- \r
- private int GetTypeFromString(string strVal)\r
- {\r
- string[] values = {\r
- "smaller",\r
- "larger",\r
- "xx-small",\r
- "x-small",\r
- "small",\r
- "medium",\r
- "large",\r
- "xlarge",\r
- "xxlarge"\r
- }\r
- int i = 0;\r
- foreach(string valType in values)\r
- {\r
- if(strVal == valType)\r
- {\r
- return (i + 2);\r
- }\r
- i++;\r
- }\r
- return -1;\r
+\r
+ private static int GetTypeFromString(string strVal)\r
+ {\r
+ if (!(sizeTable.ContainsKey (strVal)))\r
+ return -1;\r
+ return (int) sizeTable [strVal];\r
}\r
- \r
- public static FontUnit Parse(string s): Parse(s, CultureInfo.CurrentCulture)\r
+\r
+ public static FontUnit Parse(string s)\r
{\r
+ return Parse(s, CultureInfo.CurrentCulture);\r
}\r
- \r
+\r
public static FontUnit Parse(string s, CultureInfo culture)\r
{\r
return new FontUnit(s, culture);\r
}\r
- \r
+\r
public static FontUnit Point(int n)\r
{\r
return new FontUnit(n);\r
}\r
- \r
+\r
public static bool operator ==(FontUnit left, FontUnit right)\r
{\r
return (left.type == right.type && left.val == right.val);\r
}\r
- \r
+\r
public static bool operator !=(FontUnit left, FontUnit right)\r
{\r
return !(left == right);\r
}\r
- \r
+\r
public static implicit operator FontUnit(int n)\r
{\r
return FontUnit.Point(n);\r
}\r
- \r
+\r
public override bool Equals(object obj)\r
{\r
if(obj!= null && obj is FontUnit)\r
}\r
return false;\r
}\r
- \r
+\r
public override int GetHashCode()\r
{\r
return ( (type.GetHashCode() << 2) | val.GetHashCode() );\r
}\r
- \r
- public override string ToString(): ToString(CultureInfo.CurrentCulture)\r
+\r
+ public override string ToString()\r
{\r
+ return ToString(CultureInfo.CurrentCulture);\r
}\r
- \r
- public override string ToString(CultureInfo culture)\r
+\r
+ public string ToString(CultureInfo culture)\r
{\r
if(IsEmpty)\r
{\r
default: return PropertyConverter.EnumToString(typeof(FontSize), type);\r
}\r
}\r
- \r
+\r
public bool IsEmpty\r
{\r
get\r
return (type == FontSize.NotSet);\r
}\r
}\r
- \r
+\r
public FontSize Type\r
{\r
get\r
return type;\r
}\r
}\r
- \r
+\r
public Unit Unit\r
{\r
get\r