Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / MIT / System / Web / UI / MobileControls / Design / Converters / FontNameConverter.cs / 1305376 / FontNameConverter.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.Design.MobileControls.Converters { using Microsoft.Win32; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Diagnostics; using System.Globalization; [ System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode) ] [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")] internal sealed class FontNameConverter : TypeConverter { private StandardValuesCollection values; ////// Creates a new font name converter. /// public FontNameConverter() { // Sink an event to let us know when the installed // set of fonts changes. // SystemEvents.InstalledFontsChanged += new EventHandler(this.OnInstalledFontsChanged); } ////// Determines if this converter can convert an object in the given source /// type to the native type of the converter. /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) { return true; } return base.CanConvertFrom(context, sourceType); } ////// Converts the given object to the converter's native type. /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { return MatchFontName((string)value, context); } return base.ConvertFrom(context, culture, value); } ////// We need to know when we're finalized. /// ~FontNameConverter() { SystemEvents.InstalledFontsChanged -= new EventHandler(this.OnInstalledFontsChanged); } ////// Retrieves a collection containing a set of standard values /// for the data type this validator is designed for. This /// will return null if the data type does not support a /// standard set of values. /// public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { if (values == null) { FontFamily[] fonts = FontFamily.Families; Hashtable hash = new Hashtable(); for (int i = 0; i < fonts.Length; i++) { string name = fonts[i].Name; hash[name.ToLower(CultureInfo.InvariantCulture)] = name; } object[] array = new object[hash.Values.Count]; hash.Values.CopyTo(array, 0); Array.Sort(array); values = new StandardValuesCollection(array); } return values; } ////// Determines if the list of standard values returned from /// GetStandardValues is an exclusive list. If the list /// is exclusive, then no other values are valid, such as /// in an enum data type. If the list is not exclusive, /// then there are other valid values besides the list of /// standard values GetStandardValues provides. /// public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return false; } ////// Determines if this object supports a standard set of values /// that can be picked from a list. /// public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } private string MatchFontName(string name, ITypeDescriptorContext context) { Debug.Assert(name != null, "Expected an actual font name to match in FontNameConverter::MatchFontName."); // AUI 2300 if (name.Trim().Length == 0) { return String.Empty; } // Try a partial match // string bestMatch = null; IEnumerator e = GetStandardValues(context).GetEnumerator(); while (e.MoveNext()) { string fontName = e.Current.ToString(); if (String.Equals(fontName, name, StringComparison.OrdinalIgnoreCase)) { // For an exact match, return immediately // return fontName; } else if (fontName.StartsWith(name, StringComparison.OrdinalIgnoreCase)) { if (bestMatch == null || fontName.Length <= bestMatch.Length) { bestMatch = fontName; } } } if (bestMatch == null) { // no match... fall back on whatever was provided bestMatch = name; } return bestMatch; } ////// Called by system events when someone adds or removes a font. Here /// we invalidate our font name collection. /// private void OnInstalledFontsChanged(object sender, EventArgs e) { values = null; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.Design.MobileControls.Converters { using Microsoft.Win32; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Diagnostics; using System.Globalization; [ System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode) ] [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")] internal sealed class FontNameConverter : TypeConverter { private StandardValuesCollection values; ////// Creates a new font name converter. /// public FontNameConverter() { // Sink an event to let us know when the installed // set of fonts changes. // SystemEvents.InstalledFontsChanged += new EventHandler(this.OnInstalledFontsChanged); } ////// Determines if this converter can convert an object in the given source /// type to the native type of the converter. /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) { return true; } return base.CanConvertFrom(context, sourceType); } ////// Converts the given object to the converter's native type. /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { return MatchFontName((string)value, context); } return base.ConvertFrom(context, culture, value); } ////// We need to know when we're finalized. /// ~FontNameConverter() { SystemEvents.InstalledFontsChanged -= new EventHandler(this.OnInstalledFontsChanged); } ////// Retrieves a collection containing a set of standard values /// for the data type this validator is designed for. This /// will return null if the data type does not support a /// standard set of values. /// public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { if (values == null) { FontFamily[] fonts = FontFamily.Families; Hashtable hash = new Hashtable(); for (int i = 0; i < fonts.Length; i++) { string name = fonts[i].Name; hash[name.ToLower(CultureInfo.InvariantCulture)] = name; } object[] array = new object[hash.Values.Count]; hash.Values.CopyTo(array, 0); Array.Sort(array); values = new StandardValuesCollection(array); } return values; } ////// Determines if the list of standard values returned from /// GetStandardValues is an exclusive list. If the list /// is exclusive, then no other values are valid, such as /// in an enum data type. If the list is not exclusive, /// then there are other valid values besides the list of /// standard values GetStandardValues provides. /// public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return false; } ////// Determines if this object supports a standard set of values /// that can be picked from a list. /// public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } private string MatchFontName(string name, ITypeDescriptorContext context) { Debug.Assert(name != null, "Expected an actual font name to match in FontNameConverter::MatchFontName."); // AUI 2300 if (name.Trim().Length == 0) { return String.Empty; } // Try a partial match // string bestMatch = null; IEnumerator e = GetStandardValues(context).GetEnumerator(); while (e.MoveNext()) { string fontName = e.Current.ToString(); if (String.Equals(fontName, name, StringComparison.OrdinalIgnoreCase)) { // For an exact match, return immediately // return fontName; } else if (fontName.StartsWith(name, StringComparison.OrdinalIgnoreCase)) { if (bestMatch == null || fontName.Length <= bestMatch.Length) { bestMatch = fontName; } } } if (bestMatch == null) { // no match... fall back on whatever was provided bestMatch = name; } return bestMatch; } ////// Called by system events when someone adds or removes a font. Here /// we invalidate our font name collection. /// private void OnInstalledFontsChanged(object sender, EventArgs e) { values = null; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PatternMatcher.cs
- SQLInt64Storage.cs
- ProgressiveCrcCalculatingStream.cs
- DynamicValueConverter.cs
- MLangCodePageEncoding.cs
- FlatButtonAppearance.cs
- AliasExpr.cs
- EventProxy.cs
- ObjectAssociationEndMapping.cs
- EditorPart.cs
- TextReader.cs
- TakeQueryOptionExpression.cs
- SortedDictionary.cs
- BidOverLoads.cs
- ValidationErrorCollection.cs
- ReaderContextStackData.cs
- DataGridViewTextBoxColumn.cs
- GiveFeedbackEventArgs.cs
- CodeComment.cs
- OdbcConnectionHandle.cs
- UInt32.cs
- DataGridSortCommandEventArgs.cs
- BackgroundFormatInfo.cs
- CacheHelper.cs
- PropertyMetadata.cs
- RunWorkerCompletedEventArgs.cs
- HttpWebResponse.cs
- FieldMetadata.cs
- BinaryEditor.cs
- FontDifferentiator.cs
- Literal.cs
- WebPartMovingEventArgs.cs
- MissingSatelliteAssemblyException.cs
- NamedPipeProcessProtocolHandler.cs
- KeyValueConfigurationCollection.cs
- ICollection.cs
- KnownIds.cs
- IIS7UserPrincipal.cs
- ImageClickEventArgs.cs
- ReadWriteSpinLock.cs
- ComponentEditorPage.cs
- EmbeddedMailObjectsCollection.cs
- ExpressionEditorAttribute.cs
- EventManager.cs
- UrlAuthorizationModule.cs
- AuthenticationException.cs
- ReflectTypeDescriptionProvider.cs
- CompiledQuery.cs
- DataGridViewSelectedCellsAccessibleObject.cs
- Conditional.cs
- EntityDataSourceValidationException.cs
- ConnectionConsumerAttribute.cs
- PowerModeChangedEventArgs.cs
- QilTernary.cs
- ExpressionPrefixAttribute.cs
- KeyEvent.cs
- __Filters.cs
- LinqDataSourceDeleteEventArgs.cs
- XamlBrushSerializer.cs
- AppLevelCompilationSectionCache.cs
- SwitchAttribute.cs
- SelectiveScrollingGrid.cs
- URLString.cs
- DirectoryRootQuery.cs
- ExpressionBindings.cs
- BamlResourceContent.cs
- _emptywebproxy.cs
- DropShadowEffect.cs
- FontSizeConverter.cs
- CodeChecksumPragma.cs
- _NegoStream.cs
- PageCodeDomTreeGenerator.cs
- TransportReplyChannelAcceptor.cs
- XmlQualifiedNameTest.cs
- SQLRoleProvider.cs
- SR.cs
- EnumMemberAttribute.cs
- XsltInput.cs
- ExtenderHelpers.cs
- TerminateDesigner.cs
- LocatorBase.cs
- AssociatedControlConverter.cs
- OuterGlowBitmapEffect.cs
- FunctionQuery.cs
- URLMembershipCondition.cs
- TextFormattingConverter.cs
- NavigationEventArgs.cs
- ExecutionScope.cs
- MouseEventArgs.cs
- ClientScriptManagerWrapper.cs
- ObjectDataSourceFilteringEventArgs.cs
- NullReferenceException.cs
- SimpleHandlerFactory.cs
- TagMapInfo.cs
- TriggerAction.cs
- State.cs
- PageClientProxyGenerator.cs
- SymLanguageVendor.cs
- BufferModesCollection.cs
- SettingsPropertyCollection.cs