public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { FontFamily fontFamily = (FontFamily)value; XmlLanguage language = XmlLanguage.GetLanguage(culture.IetfLanguageTag); string name; if (!fontFamily.FamilyNames.TryGetValue(language, out name)) { name = FontUtil.GetName(fontFamily); } return((object)name); }
public static FontFace GetFontFaceInfo(string font, MediaCenterTheme theme) { FontFace fontFace = new FontFace(); List <FontFamily> list = new List <FontFamily>(); if (theme != null) { list.AddRange(theme.Fonts); } InstallMediaCenterFonts(); list.AddRange(Fonts.SystemFontFamilies); foreach (FontFamily fontFamily in list) { string name = FontUtil.GetName(fontFamily); if (font.StartsWith(name)) { fontFace.FontFamily = name; FontWeightConverter fontWeightConverter = new FontWeightConverter(); string str = font.Substring(name.Length).Trim(); char[] chArray = new char[1] { ' ' }; foreach (string text in str.Split(chArray)) { if (!string.IsNullOrEmpty(text)) { try { fontFace.FontWeight = (FontWeight)fontWeightConverter.ConvertFromString(text); } catch (FormatException) { } } } break; } } if (fontFace.FontFamily == null) { return((FontFace)null); } else { return(fontFace); } }
private static FontFamily FindFont(string font, IEnumerable <FontFamily> fonts) { return(Enumerable.FirstOrDefault <FontFamily>(Enumerable.Where <FontFamily>(fonts, (Func <FontFamily, bool>)(o => FontUtil.GetName(o) == font)))); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string fontFamilyName = (string)value; XmlLanguage lang = XmlLanguage.GetLanguage(culture.IetfLanguageTag); return((object)(Enumerable.FirstOrDefault <FontFamily>(this.FontFamilies, (Func <FontFamily, bool>)(o => { if (o.FamilyNames.ContainsKey(lang)) { return o.FamilyNames[lang] == fontFamilyName; } else { return false; } })) ?? Enumerable.FirstOrDefault <FontFamily>(this.FontFamilies, (Func <FontFamily, bool>)(o => FontUtil.GetName(o) == fontFamilyName)))); }
protected virtual void Apply(MediaCenterLibraryCache readCache, MediaCenterLibraryCache writeCache, ProgressEnabledOperation operation) { try { if (this.Fonts.Count > 0) { operation.OnProgress("Installing fonts...", 0); foreach (string file in Enumerable.Distinct <string>(Enumerable.Select <FontFamily, string>(Enumerable.Where <FontFamily>((IEnumerable <FontFamily>) this.Fonts, (Func <FontFamily, bool>)(f => !Enumerable.Any <FontFamily>((IEnumerable <FontFamily>)System.Windows.Media.Fonts.SystemFontFamilies, (Func <FontFamily, bool>)(o => FontUtil.GetName(f) == FontUtil.GetName(o))))), (Func <FontFamily, string>)(o => FontUtil.GetFile(o))))) { FontUtil.InstallFont(file); } } List <IThemeItem> list = Enumerable.ToList <IThemeItem>(Enumerable.Concat <IThemeItem>((IEnumerable <IThemeItem>) new List <IThemeItem>() { (IThemeItem)this.FontsItem, (IThemeItem)this.ColorsItem }, (IEnumerable <IThemeItem>) this.ThemeItems)); for (int currentIndex = 0; currentIndex < list.Count; ++currentIndex) { IThemeItem themeItem = list[currentIndex]; operation.OnProgress(string.Format("Applying {0}...", (object)themeItem.Name), currentIndex); try { themeItem.Apply(readCache, writeCache); } catch (ThemeApplicationException ex) { Trace.TraceWarning(((object)ex).ToString()); } } } catch (Exception ex) { Trace.TraceError(((object)ex).ToString()); operation.OnAbandoned(ex); throw; } operation.OnCompleted(); }