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
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 using System
.Reflection
;
41 using System
.ComponentModel
;
43 namespace System
.Web
.UI
.WebControls
45 [TypeConverter(typeof(ExpandableObjectConverter
))]
46 public sealed class FontInfo
48 private Style infoOwner
;
50 internal FontInfo(Style owner
)
56 /// Default constructor
58 /// The default constructor is made private to prevent any instances being made.
65 [DefaultValue (false), Bindable (true), WebCategory ("Font")]
66 [NotifyParentProperty (true)]
67 [WebSysDescription ("The 'bold' style of the font.")]
72 if(infoOwner
.IsSet(Style
.FONT_BOLD
))
73 return (bool)(infoOwner
.ViewState
["FontInfoBold"]);
78 infoOwner
.ViewState
["FontInfoBold"] = value;
79 infoOwner
.Set(Style
.FONT_BOLD
);
83 [DefaultValue (false), Bindable (true), WebCategory ("Font")]
84 [NotifyParentProperty (true)]
85 [WebSysDescription ("The 'italic' style of the font.")]
90 if(infoOwner
.IsSet(Style
.FONT_ITALIC
))
91 return (bool)(infoOwner
.ViewState
["FontInfoItalic"]);
96 infoOwner
.ViewState
["FontInfoItalic"] = value;
97 infoOwner
.Set(Style
.FONT_ITALIC
);
101 [DefaultValue (false), Bindable (true), WebCategory ("Font")]
102 [NotifyParentProperty (true)]
103 [WebSysDescription ("The 'overline' style of the font.")]
108 if(infoOwner
.IsSet(Style
.FONT_OLINE
))
109 return (bool)(infoOwner
.ViewState
["FontInfoOverline"]);
114 infoOwner
.ViewState
["FontInfoOverline"] = value;
115 infoOwner
.Set(Style
.FONT_OLINE
);
119 [DefaultValue (false), Bindable (true), WebCategory ("Font")]
120 [NotifyParentProperty (true)]
121 [WebSysDescription ("The 'strikeout' style of the font.")]
122 public bool Strikeout
126 if(infoOwner
.IsSet(Style
.FONT_STRIKE
))
127 return (bool)(infoOwner
.ViewState
["FontInfoStrikeout"]);
132 infoOwner
.ViewState
["FontInfoStrikeout"] = value;
133 infoOwner
.Set(Style
.FONT_STRIKE
);
137 [DefaultValue (false), Bindable (true), WebCategory ("Font")]
138 [NotifyParentProperty (true)]
139 [WebSysDescription ("The 'underline' style of the font.")]
140 public bool Underline
144 if(infoOwner
.IsSet(Style
.FONT_ULINE
))
145 return (bool)(infoOwner
.ViewState
["FontInfoUnderline"]);
150 infoOwner
.ViewState
["FontInfoUnderline"] = value;
151 infoOwner
.Set(Style
.FONT_ULINE
);
155 [DefaultValue (null), Bindable (true), WebCategory ("Font")]
156 [NotifyParentProperty (true)]
157 [WebSysDescription ("The size of the font.")]
162 if(infoOwner
.IsSet(Style
.FONT_SIZE
))
163 return (FontUnit
)(infoOwner
.ViewState
["FontInfoSize"]);
164 return FontUnit
.Empty
;
168 if ((value.Type
== FontSize
.AsUnit
) && (value.Unit
.Value
< 0))
169 throw new ArgumentOutOfRangeException("value");
170 infoOwner
.ViewState
["FontInfoSize"] = value;
171 infoOwner
.Set(Style
.FONT_SIZE
);
175 [DefaultValue (""), Bindable (true), WebCategory ("Font")]
176 [NotifyParentProperty (true), DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
177 [Editor ("System.Drawing.Design.FontNameEditor, " + Consts
.AssemblySystem_Drawing_Design
, typeof (System
.Drawing
.Design
.UITypeEditor
))]
178 [TypeConverter (typeof (FontConverter
.FontNameConverter
))]
179 [WebSysDescription ("The name of the font that this control should be rendered with.")]
184 if(Names
!=null && Names
.Length
> 0)
191 throw new ArgumentException();
192 string[] strArray
= null;
195 strArray
= new string[1];
202 [WebCategory ("Font")]
203 [NotifyParentProperty (true)]
204 [Editor ("System.Windows.Forms.Design.StringArrayEditor, " + Consts
.AssemblySystem_Design
, typeof (System
.Drawing
.Design
.UITypeEditor
))]
205 [TypeConverter (typeof (FontNamesConverter
))]
206 [WebSysDescription ("Multiple fonts that can be used to render the control.")]
207 public string[] Names
211 if(infoOwner
.IsSet(Style
.FONT_NAMES
))
212 return (string[])(infoOwner
.ViewState
["FontInfoNames"]);
213 return (new string[0]);
219 infoOwner
.ViewState
["FontInfoNames"] = value;
220 infoOwner
.Set(Style
.FONT_NAMES
);
225 internal void Reset()
227 if(infoOwner
.IsSet(Style
.FONT_NAMES
))
228 infoOwner
.ViewState
.Remove("FontInfoNames");
229 if(infoOwner
.IsSet(Style
.FONT_BOLD
))
230 infoOwner
.ViewState
.Remove("FontInfoBold");
231 if(infoOwner
.IsSet(Style
.FONT_ITALIC
))
232 infoOwner
.ViewState
.Remove("FontInfoItalic");
233 if(infoOwner
.IsSet(Style
.FONT_STRIKE
))
234 infoOwner
.ViewState
.Remove("FontInfoStrikeout");
235 if(infoOwner
.IsSet(Style
.FONT_OLINE
))
236 infoOwner
.ViewState
.Remove("FontInfoOverline");
237 if(infoOwner
.IsSet(Style
.FONT_ULINE
))
238 infoOwner
.ViewState
.Remove("FontInfoUnderline");
239 if(infoOwner
.IsSet(Style
.FONT_SIZE
) && infoOwner
.Font
.Size
!= FontUnit
.Empty
)
240 infoOwner
.ViewState
.Remove("FontInfoSize");
251 public void CopyFrom(FontInfo source
)
255 if(source
.Owner
.IsSet(Style
.FONT_NAMES
))
256 Names
= source
.Names
;
257 if(source
.Owner
.IsSet(Style
.FONT_BOLD
)&& source
.Bold
)
259 if(source
.Owner
.IsSet(Style
.FONT_ITALIC
)&& source
.Italic
)
260 Italic
= source
.Italic
;
261 if(source
.Owner
.IsSet(Style
.FONT_STRIKE
)&& source
.Strikeout
)
262 Strikeout
= source
.Strikeout
;
263 if(source
.Owner
.IsSet(Style
.FONT_OLINE
)&& source
.Overline
)
264 Overline
= source
.Overline
;
265 if(source
.Owner
.IsSet(Style
.FONT_ULINE
)&& source
.Underline
)
266 Underline
= source
.Underline
;
267 if(source
.Owner
.IsSet(Style
.FONT_SIZE
) && source
.Size
!= FontUnit
.Empty
)
272 public void MergeWith(FontInfo with
)
276 if(with
.Owner
.IsSet(Style
.FONT_NAMES
) && !infoOwner
.IsSet(Style
.FONT_NAMES
))
278 if(with
.Owner
.IsSet(Style
.FONT_BOLD
) && !infoOwner
.IsSet(Style
.FONT_BOLD
))
280 if(with
.Owner
.IsSet(Style
.FONT_ITALIC
) && !infoOwner
.IsSet(Style
.FONT_ITALIC
))
281 Italic
= with
.Italic
;
282 if(with
.Owner
.IsSet(Style
.FONT_STRIKE
) && !infoOwner
.IsSet(Style
.FONT_STRIKE
))
283 Strikeout
= with
.Strikeout
;
284 if(with
.Owner
.IsSet(Style
.FONT_OLINE
) && !infoOwner
.IsSet(Style
.FONT_OLINE
))
285 Overline
= with
.Overline
;
286 if(with
.Owner
.IsSet(Style
.FONT_ULINE
) && !infoOwner
.IsSet(Style
.FONT_ULINE
))
287 Underline
= with
.Underline
;
288 if(with
.Owner
.IsSet(Style
.FONT_SIZE
) && with
.Size
!= FontUnit
.Empty
&& !infoOwner
.IsSet(Style
.FONT_SIZE
))
293 public bool ShouldSerializeNames()
295 return (Names
.Length
> 0);
298 public override string ToString()
300 return ( (Name
.Length
> 0) ? (Name
.ToString() + ", " + Size
.ToString()) : Size
.ToString() );