Ejemplo n.º 1
0
 public static string GetName(this swm.LanguageSpecificStringDictionary nameDictionary, string ietfLanguageTag)
 {
     return(CustomControls.FontDialog.NameDictionaryExtensions.GetName(nameDictionary, ietfLanguageTag));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// ConvertTo - Converts the specified object to an instance of the specified type.
        /// </summary>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (null == value)
            {
                throw new ArgumentNullException("value");
            }

            FontFamily fontFamily = value as FontFamily;

            if (fontFamily == null)
            {
                throw new ArgumentException(SR.Get(SRID.General_Expected_Type, "FontFamily"), "value");
            }

            if (null == destinationType)
            {
                throw new ArgumentNullException("destinationType");
            }

            if (destinationType == typeof(string))
            {
                if (fontFamily.Source != null)
                {
                    // Usual case: it's a named font family.
                    return(fontFamily.Source);
                }
                else
                {
                    // If client calls typeConverter.CanConvertTo(typeof(string)) then we'll return
                    // true always, even though we don't have access to the FontFamily instance; so
                    // we need to be able to return some kind of family name even if Source==null.
                    string name = null;

                    CultureInfo parentCulture = null;
                    if (culture != null)
                    {
                        if (culture.Equals(CultureInfo.InvariantCulture))
                        {
                            culture = null;
                        }
                        else
                        {
                            parentCulture = culture.Parent;
                            if (parentCulture != null &&
                                (parentCulture.Equals(CultureInfo.InvariantCulture) || parentCulture == culture))
                            {
                                parentCulture = null;
                            }
                        }
                    }

                    // Try looking up the name in the FamilyNames dictionary.
                    LanguageSpecificStringDictionary names = fontFamily.FamilyNames;

                    if (culture != null && names.TryGetValue(XmlLanguage.GetLanguage(culture.IetfLanguageTag), out name))
                    {
                        // LanguageSpecificStringDictionary does not allow null string to be added.
                        Debug.Assert(name != null);
                    }
                    else if (parentCulture != null && names.TryGetValue(XmlLanguage.GetLanguage(parentCulture.IetfLanguageTag), out name))
                    {
                        // LanguageSpecificStringDictionary does not allow null string to be added.
                        Debug.Assert(name != null);
                    }
                    else if (names.TryGetValue(XmlLanguage.Empty, out name))
                    {
                        // LanguageSpecificStringDictionary does not allow null string to be added.
                        Debug.Assert(name != null);
                    }
                    else
                    {
                        // Try the first target font compatible with the culture.
                        foreach (FontFamilyMap familyMap in fontFamily.FamilyMaps)
                        {
                            if (FontFamilyMap.MatchCulture(familyMap.Language, culture))
                            {
                                name = familyMap.Target;
                                break;
                            }
                        }

                        // Use global ui as a last resort.
                        if (name == null)
                        {
                            name = FontFamily.GlobalUI;
                        }
                    }

                    return(name);
                }
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Ejemplo n.º 3
0
 public static string GetDisplayName(this swm.LanguageSpecificStringDictionary nameDictionary)
 {
     return(CustomControls.FontDialog.NameDictionaryExtensions.GetDisplayName(nameDictionary));
 }