From baef3b364bfb993572913886c0d800c062c66958 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 8 May 2024 11:42:01 +0800 Subject: [PATCH] Bug fix --- v2rayN/v2rayN/Views/MsgView.xaml | 1 - .../v2rayN/Views/OptionSettingWindow.xaml.cs | 95 ++++++++++--------- 2 files changed, 51 insertions(+), 45 deletions(-) diff --git a/v2rayN/v2rayN/Views/MsgView.xaml b/v2rayN/v2rayN/Views/MsgView.xaml index 7ec25302..9e61d419 100644 --- a/v2rayN/v2rayN/Views/MsgView.xaml +++ b/v2rayN/v2rayN/Views/MsgView.xaml @@ -17,7 +17,6 @@ (); - foreach (var pattern in searchPatterns) - { - files.AddRange(Directory.GetFiles(Utils.GetFontsPath(), pattern)); - } - var culture = _config.uiItem.currentLanguage == Global.Languages[0] ? "zh-cn" : "en-us"; - var culture2 = "en-us"; - foreach (var ttf in files) - { - var families = Fonts.GetFontFamilies(Utils.GetFontsPath(ttf)); - foreach (FontFamily family in families) - { - var typefaces = family.GetTypefaces(); - foreach (Typeface typeface in typefaces) - { - typeface.TryGetGlyphTypeface(out GlyphTypeface glyph); - //var fontFace = glyph.Win32FaceNames[new CultureInfo("en-us")]; - //if (!fontFace.Equals("Regular") && !fontFace.Equals("Normal")) - //{ - // continue; - //} - var fontFamily = glyph.Win32FamilyNames[new CultureInfo(culture)]; - if (Utils.IsNullOrEmpty(fontFamily)) - { - fontFamily = glyph.Win32FamilyNames[new CultureInfo(culture2)]; - if (Utils.IsNullOrEmpty(fontFamily)) - { - continue; - } - } - cmbcurrentFontFamily.Items.Add(fontFamily); - break; - } - } - } - } - catch (Exception ex) - { - Logging.SaveLog("fill fonts error", ex); - } + lstFonts.ForEach(it => { cmbcurrentFontFamily.Items.Add(it); }); cmbcurrentFontFamily.Items.Add(string.Empty); this.WhenActivated(disposables => @@ -206,5 +164,54 @@ namespace v2rayN.Views this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); }); } + + private List GetFonts(string path) + { + var lstFonts = new List(); + try + { + string[] searchPatterns = { "*.ttf", "*.ttc" }; + var files = new List(); + foreach (var pattern in searchPatterns) + { + files.AddRange(Directory.GetFiles(path, pattern)); + } + var culture = _config.uiItem.currentLanguage == Global.Languages[0] ? "zh-cn" : "en-us"; + var culture2 = "en-us"; + foreach (var ttf in files) + { + var families = Fonts.GetFontFamilies(Utils.GetFontsPath(ttf)); + foreach (FontFamily family in families) + { + var typefaces = family.GetTypefaces(); + foreach (Typeface typeface in typefaces) + { + typeface.TryGetGlyphTypeface(out GlyphTypeface glyph); + //var fontFace = glyph.Win32FaceNames[new CultureInfo("en-us")]; + //if (!fontFace.Equals("Regular") && !fontFace.Equals("Normal")) + //{ + // continue; + //} + var fontFamily = glyph.Win32FamilyNames[new CultureInfo(culture)]; + if (Utils.IsNullOrEmpty(fontFamily)) + { + fontFamily = glyph.Win32FamilyNames[new CultureInfo(culture2)]; + if (Utils.IsNullOrEmpty(fontFamily)) + { + continue; + } + } + lstFonts.Add(fontFamily); + break; + } + } + } + } + catch (Exception ex) + { + Logging.SaveLog("fill fonts error", ex); + } + return lstFonts; + } } } \ No newline at end of file