2 // System.Web.UI.WebControls.FontInfo.cs
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
9 // (c) 2002 Ximian, Inc. (http://www.ximian.com)
10 // (C) Gaurav Vaish (2002)
11 // (C) 2003 Andreas Nahr
16 using System.Reflection;
\r
18 using System.Web.UI;
\r
19 using System.Drawing;
\r
20 using System.ComponentModel;
\r
22 namespace System.Web.UI.WebControls
\r
24 [TypeConverter(typeof(ExpandableObjectConverter))]
\r
25 public sealed class FontInfo
\r
27 private Style infoOwner;
\r
29 internal FontInfo(Style owner)
\r
35 /// Default constructor
\r
37 /// The default constructor is made private to prevent any instances being made.
\r
44 [DefaultValue (false), Bindable (true), WebCategory ("Font")]
45 [NotifyParentProperty (true)]
46 [WebSysDescription ("The 'bold' style of the font.")]
\r
51 if(infoOwner.IsSet(Style.FONT_BOLD))
\r
52 return (bool)(infoOwner.ViewState["FontInfoBold"]);
\r
57 infoOwner.ViewState["FontInfoBold"] = value;
\r
58 infoOwner.Set(Style.FONT_BOLD);
\r
62 [DefaultValue (false), Bindable (true), WebCategory ("Font")]
63 [NotifyParentProperty (true)]
64 [WebSysDescription ("The 'italic' style of the font.")]
\r
69 if(infoOwner.IsSet(Style.FONT_ITALIC))
\r
70 return (bool)(infoOwner.ViewState["FontInfoItalic"]);
\r
75 infoOwner.ViewState["FontInfoItalic"] = value;
\r
76 infoOwner.Set(Style.FONT_ITALIC);
\r
80 [DefaultValue (false), Bindable (true), WebCategory ("Font")]
81 [NotifyParentProperty (true)]
82 [WebSysDescription ("The 'overline' style of the font.")]
\r
83 public bool Overline
\r
87 if(infoOwner.IsSet(Style.FONT_OLINE))
\r
88 return (bool)(infoOwner.ViewState["FontInfoOverline"]);
\r
93 infoOwner.ViewState["FontInfoOverline"] = value;
\r
94 infoOwner.Set(Style.FONT_OLINE);
\r
98 [DefaultValue (false), Bindable (true), WebCategory ("Font")]
99 [NotifyParentProperty (true)]
100 [WebSysDescription ("The 'strikeout' style of the font.")]
\r
101 public bool Strikeout
\r
105 if(infoOwner.IsSet(Style.FONT_STRIKE))
\r
106 return (bool)(infoOwner.ViewState["FontInfoStrikeout"]);
\r
111 infoOwner.ViewState["FontInfoStrikeout"] = value;
\r
112 infoOwner.Set(Style.FONT_STRIKE);
\r
116 [DefaultValue (false), Bindable (true), WebCategory ("Font")]
117 [NotifyParentProperty (true)]
118 [WebSysDescription ("The 'underline' style of the font.")]
\r
119 public bool Underline
\r
123 if(infoOwner.IsSet(Style.FONT_ULINE))
\r
124 return (bool)(infoOwner.ViewState["FontInfoUnderline"]);
\r
129 infoOwner.ViewState["FontInfoUnderline"] = value;
\r
130 infoOwner.Set(Style.FONT_ULINE);
\r
134 [DefaultValue (null), Bindable (true), WebCategory ("Font")]
135 [NotifyParentProperty (true)]
136 [WebSysDescription ("The size of the font.")]
\r
137 public FontUnit Size
\r
141 if(infoOwner.IsSet(Style.FONT_SIZE))
\r
142 return (FontUnit)(infoOwner.ViewState["FontInfoSize"]);
\r
143 return FontUnit.Empty;
\r
147 if ((value.Type == FontSize.AsUnit) && (value.Unit.Value < 0))
\r
148 throw new ArgumentOutOfRangeException("value");
\r
149 infoOwner.ViewState["FontInfoSize"] = value;
\r
150 infoOwner.Set(Style.FONT_SIZE);
\r
154 [DefaultValue (""), Bindable (true), WebCategory ("Font")]
155 [NotifyParentProperty (true), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
156 [Editor ("System.Drawing.Design.FontNameEditor, " + Consts.AssemblySystem_Drawing_Design, typeof (System.Drawing.Design.UITypeEditor))]
157 [TypeConverter (typeof (FontConverter.FontNameConverter))]
158 [WebSysDescription ("The name of the font that this control should be rendered with.")]
\r
163 if(Names!=null && Names.Length > 0)
165 return String.Empty;
\r
170 throw new ArgumentException();
\r
171 string[] strArray = null;
\r
172 if(value.Length > 0)
\r
174 strArray = new string[1];
\r
175 strArray[0] = value;
\r
181 [WebCategory ("Font")]
182 [NotifyParentProperty (true)]
183 [Editor ("System.Windows.Forms.Design.StringArrayEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
184 [TypeConverter (typeof (FontNamesConverter))]
185 [WebSysDescription ("Multiple fonts that can be used to render the control.")]
\r
186 public string[] Names
\r
190 if(infoOwner.IsSet(Style.FONT_NAMES))
\r
191 return (string[])(infoOwner.ViewState["FontInfoNames"]);
\r
192 return (new string[0]);
\r
198 infoOwner.ViewState["FontInfoNames"] = value;
\r
199 infoOwner.Set(Style.FONT_NAMES);
\r
204 internal void Reset()
\r
206 if(infoOwner.IsSet(Style.FONT_NAMES))
\r
207 infoOwner.ViewState.Remove("FontInfoNames");
\r
208 if(infoOwner.IsSet(Style.FONT_BOLD))
\r
209 infoOwner.ViewState.Remove("FontInfoBold");
\r
210 if(infoOwner.IsSet(Style.FONT_ITALIC))
\r
211 infoOwner.ViewState.Remove("FontInfoItalic");
\r
212 if(infoOwner.IsSet(Style.FONT_STRIKE))
\r
213 infoOwner.ViewState.Remove("FontInfoStrikeout");
\r
214 if(infoOwner.IsSet(Style.FONT_OLINE))
\r
215 infoOwner.ViewState.Remove("FontInfoOverline");
\r
216 if(infoOwner.IsSet(Style.FONT_ULINE))
\r
217 infoOwner.ViewState.Remove("FontInfoUnderline");
\r
218 if(infoOwner.IsSet(Style.FONT_SIZE) && infoOwner.Font.Size != FontUnit.Empty)
\r
219 infoOwner.ViewState.Remove("FontInfoSize");
\r
222 internal Style Owner
\r
230 public void CopyFrom(FontInfo source)
\r
234 if(source.Owner.IsSet(Style.FONT_NAMES))
\r
235 Names = source.Names;
\r
236 if(source.Owner.IsSet(Style.FONT_BOLD)&& source.Bold)
\r
237 Bold = source.Bold;
\r
238 if(source.Owner.IsSet(Style.FONT_ITALIC)&& source.Italic)
\r
239 Italic = source.Italic;
\r
240 if(source.Owner.IsSet(Style.FONT_STRIKE)&& source.Strikeout)
\r
241 Strikeout = source.Strikeout;
\r
242 if(source.Owner.IsSet(Style.FONT_OLINE)&& source.Overline)
\r
243 Overline = source.Overline;
\r
244 if(source.Owner.IsSet(Style.FONT_ULINE)&& source.Underline)
\r
245 Underline = source.Underline;
\r
246 if(source.Owner.IsSet(Style.FONT_SIZE) && source.Size != FontUnit.Empty)
\r
247 Size = source.Size;
\r
251 public void MergeWith(FontInfo with)
\r
255 if(with.Owner.IsSet(Style.FONT_NAMES) && !infoOwner.IsSet(Style.FONT_NAMES))
\r
256 Names = with.Names;
\r
257 if(with.Owner.IsSet(Style.FONT_BOLD) && !infoOwner.IsSet(Style.FONT_BOLD))
\r
259 if(with.Owner.IsSet(Style.FONT_ITALIC) && !infoOwner.IsSet(Style.FONT_ITALIC))
\r
260 Italic = with.Italic;
\r
261 if(with.Owner.IsSet(Style.FONT_STRIKE) && !infoOwner.IsSet(Style.FONT_STRIKE))
\r
262 Strikeout = with.Strikeout;
\r
263 if(with.Owner.IsSet(Style.FONT_OLINE) && !infoOwner.IsSet(Style.FONT_OLINE))
\r
264 Overline = with.Overline;
\r
265 if(with.Owner.IsSet(Style.FONT_ULINE) && !infoOwner.IsSet(Style.FONT_ULINE))
\r
266 Underline = with.Underline;
\r
267 if(with.Owner.IsSet(Style.FONT_SIZE) && with.Size != FontUnit.Empty && !infoOwner.IsSet(Style.FONT_SIZE))
\r
272 public bool ShouldSerializeNames()
\r
274 return (Names.Length > 0);
\r
277 public override string ToString()
\r
279 return ( (Name.Length > 0) ? (Name.ToString() + ", " + Size.ToString()) : Size.ToString() );
\r