FontInfo.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: FontInfo
  4. *
  5. * Author: Gaurav Vaish
  6. * Maintainer: [email protected]
  7. * Contact: <[email protected]>, <[email protected]>
  8. * Implementation: yes
  9. * Status: 100%
  10. *
  11. * (C) Gaurav Vaish (2001)
  12. */
  13. using System;
  14. using System.Text;
  15. using System.Reflection;
  16. using System.Web;
  17. using System.Web.UI;
  18. using System.Drawing;
  19. using System.ComponentModel;
  20. namespace System.Web.UI.WebControls
  21. {
  22. [TypeConverter(typeof(ExpandableObjectConverter))]
  23. public sealed class FontInfo
  24. {
  25. private Style infoOwner;
  26. internal FontInfo(Style owner)
  27. {
  28. infoOwner = owner;
  29. }
  30. /// <summary>
  31. /// Default constructor
  32. /// <remarks>
  33. /// The default constructor is made private to prevent any instances being made.
  34. /// </remarks>
  35. /// </summary>
  36. private FontInfo()
  37. {
  38. }
  39. public bool Bold
  40. {
  41. get
  42. {
  43. if(infoOwner.IsSet(Style.FONT_BOLD))
  44. return (bool)(infoOwner.ViewState["FontInfoBold"]);
  45. return false;
  46. }
  47. set
  48. {
  49. infoOwner.ViewState["FontInfoBold"] = value;
  50. infoOwner.Set(Style.FONT_BOLD);
  51. }
  52. }
  53. public bool Italic
  54. {
  55. get
  56. {
  57. if(infoOwner.IsSet(Style.FONT_ITALIC))
  58. return (bool)(infoOwner.ViewState["FontInfoItalic"]);
  59. return false;
  60. }
  61. set
  62. {
  63. infoOwner.ViewState["FontInfoItalic"] = value;
  64. infoOwner.Set(Style.FONT_ITALIC);
  65. }
  66. }
  67. public bool Overline
  68. {
  69. get
  70. {
  71. if(infoOwner.IsSet(Style.FONT_OLINE))
  72. return (bool)(infoOwner.ViewState["FontInfoOverline"]);
  73. return false;
  74. }
  75. set
  76. {
  77. infoOwner.ViewState["FontInfoOverline"] = value;
  78. infoOwner.Set(Style.FONT_OLINE);
  79. }
  80. }
  81. public bool Strikeout
  82. {
  83. get
  84. {
  85. if(infoOwner.IsSet(Style.FONT_STRIKE))
  86. return (bool)(infoOwner.ViewState["FontInfoStrikeout"]);
  87. return false;
  88. }
  89. set
  90. {
  91. infoOwner.ViewState["FontInfoStrikeout"] = value;
  92. infoOwner.Set(Style.FONT_STRIKE);
  93. }
  94. }
  95. public bool Underline
  96. {
  97. get
  98. {
  99. if(infoOwner.IsSet(Style.FONT_ULINE))
  100. return (bool)(infoOwner.ViewState["FontInfoUnderline"]);
  101. return false;
  102. }
  103. set
  104. {
  105. infoOwner.ViewState["FontInfoUnderline"] = value;
  106. infoOwner.Set(Style.FONT_ULINE);
  107. }
  108. }
  109. //TODO: How do I check if the value is negative. FontUnit is struct not enum
  110. public FontUnit Size
  111. {
  112. get
  113. {
  114. if(infoOwner.IsSet(Style.FONT_SIZE))
  115. return (FontUnit)(infoOwner.ViewState["FontInfoSize"]);
  116. return FontUnit.Empty;
  117. }
  118. set
  119. {
  120. infoOwner.ViewState["FontInfoSize"] = value;
  121. infoOwner.Set(Style.FONT_SIZE);
  122. }
  123. }
  124. public string Name
  125. {
  126. get
  127. {
  128. if(Names!=null)
  129. return Names[0];
  130. return String.Empty;
  131. }
  132. set
  133. {
  134. if(value == null)
  135. throw new ArgumentException();
  136. string[] strArray = null;
  137. if(value.Length > 0)
  138. {
  139. strArray = new string[1];
  140. strArray[0] = value;
  141. }
  142. Names = strArray;
  143. }
  144. }
  145. public string[] Names
  146. {
  147. get
  148. {
  149. if(infoOwner.IsSet(Style.FONT_NAMES))
  150. return (string[])(infoOwner.ViewState["FontInfoNames"]);
  151. return (new string[0]);
  152. }
  153. set
  154. {
  155. if(value!=null)
  156. {
  157. infoOwner.ViewState["FontInfoNames"] = value;
  158. infoOwner.Set(Style.FONT_NAMES);
  159. }
  160. }
  161. }
  162. internal void Reset()
  163. {
  164. if(infoOwner.IsSet(Style.FONT_NAMES))
  165. infoOwner.ViewState.Remove("FontInfoNames");
  166. if(infoOwner.IsSet(Style.FONT_BOLD))
  167. infoOwner.ViewState.Remove("FontInfoBold");
  168. if(infoOwner.IsSet(Style.FONT_ITALIC))
  169. infoOwner.ViewState.Remove("FontInfoItalic");
  170. if(infoOwner.IsSet(Style.FONT_STRIKE))
  171. infoOwner.ViewState.Remove("FontInfoStrikeout");
  172. if(infoOwner.IsSet(Style.FONT_OLINE))
  173. infoOwner.ViewState.Remove("FontInfoOverline");
  174. if(infoOwner.IsSet(Style.FONT_ULINE))
  175. infoOwner.ViewState.Remove("FontInfoUnderline");
  176. if(infoOwner.IsSet(Style.FONT_SIZE) && infoOwner.Font.Size != FontUnit.Empty)
  177. infoOwner.ViewState.Remove("FontInfoSize");
  178. }
  179. internal Style Owner
  180. {
  181. get
  182. {
  183. return infoOwner;
  184. }
  185. }
  186. public void CopyFrom(FontInfo source)
  187. {
  188. if(source!=null)
  189. {
  190. if(source.Owner.IsSet(Style.FONT_NAMES))
  191. Names = source.Names;
  192. if(source.Owner.IsSet(Style.FONT_BOLD))
  193. Bold = source.Bold;
  194. if(source.Owner.IsSet(Style.FONT_ITALIC))
  195. Italic = source.Italic;
  196. if(source.Owner.IsSet(Style.FONT_STRIKE))
  197. Strikeout = source.Strikeout;
  198. if(source.Owner.IsSet(Style.FONT_OLINE))
  199. Overline = source.Overline;
  200. if(source.Owner.IsSet(Style.FONT_ULINE))
  201. Underline = source.Underline;
  202. if(source.Owner.IsSet(Style.FONT_SIZE) && source.Size != FontUnit.Empty)
  203. Size = source.Size;
  204. }
  205. }
  206. public void MergeWith(FontInfo with)
  207. {
  208. if(with!=null)
  209. {
  210. if(with.Owner.IsSet(Style.FONT_NAMES) && !infoOwner.IsSet(Style.FONT_NAMES))
  211. Names = with.Names;
  212. if(with.Owner.IsSet(Style.FONT_BOLD) && !infoOwner.IsSet(Style.FONT_BOLD))
  213. Bold = with.Bold;
  214. if(with.Owner.IsSet(Style.FONT_ITALIC) && !infoOwner.IsSet(Style.FONT_ITALIC))
  215. Italic = with.Italic;
  216. if(with.Owner.IsSet(Style.FONT_STRIKE) && !infoOwner.IsSet(Style.FONT_STRIKE))
  217. Strikeout = with.Strikeout;
  218. if(with.Owner.IsSet(Style.FONT_OLINE) && !infoOwner.IsSet(Style.FONT_OLINE))
  219. Overline = with.Overline;
  220. if(with.Owner.IsSet(Style.FONT_ULINE) && !infoOwner.IsSet(Style.FONT_ULINE))
  221. Underline = with.Underline;
  222. if(with.Owner.IsSet(Style.FONT_SIZE) && with.Size != FontUnit.Empty && !infoOwner.IsSet(Style.FONT_SIZE))
  223. Size = with.Size;
  224. }
  225. }
  226. public bool ShouldSerializeNames()
  227. {
  228. return (Names.Length > 0);
  229. }
  230. public override string ToString()
  231. {
  232. return ( (Name.Length > 0) ? (Name.ToString() + ", " + Size.ToString()) : Size.ToString() );
  233. }
  234. }
  235. }