Skip to content

Commit baef3b3

Browse files
committed
Bug fix
1 parent 4b9ddb8 commit baef3b3

File tree

2 files changed

+51
-45
lines changed

2 files changed

+51
-45
lines changed

v2rayN/v2rayN/Views/MsgView.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
<TextBlock
1818
Margin="8,0"
1919
VerticalAlignment="Center"
20-
Foreground="{DynamicResource MaterialDesign.Brush.Primary.Light}"
2120
Style="{StaticResource ToolbarTextBlock}"
2221
Text="{x:Static resx:ResUI.MsgInformationTitle}" />
2322
<ComboBox

v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public OptionSettingWindow()
3030

3131
this.Owner = Application.Current.MainWindow;
3232
_config = LazyConfig.Instance.GetConfig();
33+
var lstFonts = GetFonts(Utils.GetFontsPath());
3334

3435
ViewModel = new OptionSettingViewModel(this);
3536

@@ -89,50 +90,7 @@ public OptionSettingWindow()
8990
cmbSubConvertUrl.Items.Add(it);
9091
});
9192

92-
//fill fonts
93-
try
94-
{
95-
string[] searchPatterns = { "*.ttf", "*.ttc" };
96-
var files = new List<string>();
97-
foreach (var pattern in searchPatterns)
98-
{
99-
files.AddRange(Directory.GetFiles(Utils.GetFontsPath(), pattern));
100-
}
101-
var culture = _config.uiItem.currentLanguage == Global.Languages[0] ? "zh-cn" : "en-us";
102-
var culture2 = "en-us";
103-
foreach (var ttf in files)
104-
{
105-
var families = Fonts.GetFontFamilies(Utils.GetFontsPath(ttf));
106-
foreach (FontFamily family in families)
107-
{
108-
var typefaces = family.GetTypefaces();
109-
foreach (Typeface typeface in typefaces)
110-
{
111-
typeface.TryGetGlyphTypeface(out GlyphTypeface glyph);
112-
//var fontFace = glyph.Win32FaceNames[new CultureInfo("en-us")];
113-
//if (!fontFace.Equals("Regular") && !fontFace.Equals("Normal"))
114-
//{
115-
// continue;
116-
//}
117-
var fontFamily = glyph.Win32FamilyNames[new CultureInfo(culture)];
118-
if (Utils.IsNullOrEmpty(fontFamily))
119-
{
120-
fontFamily = glyph.Win32FamilyNames[new CultureInfo(culture2)];
121-
if (Utils.IsNullOrEmpty(fontFamily))
122-
{
123-
continue;
124-
}
125-
}
126-
cmbcurrentFontFamily.Items.Add(fontFamily);
127-
break;
128-
}
129-
}
130-
}
131-
}
132-
catch (Exception ex)
133-
{
134-
Logging.SaveLog("fill fonts error", ex);
135-
}
93+
lstFonts.ForEach(it => { cmbcurrentFontFamily.Items.Add(it); });
13694
cmbcurrentFontFamily.Items.Add(string.Empty);
13795

13896
this.WhenActivated(disposables =>
@@ -206,5 +164,54 @@ public OptionSettingWindow()
206164
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
207165
});
208166
}
167+
168+
private List<string> GetFonts(string path)
169+
{
170+
var lstFonts = new List<string>();
171+
try
172+
{
173+
string[] searchPatterns = { "*.ttf", "*.ttc" };
174+
var files = new List<string>();
175+
foreach (var pattern in searchPatterns)
176+
{
177+
files.AddRange(Directory.GetFiles(path, pattern));
178+
}
179+
var culture = _config.uiItem.currentLanguage == Global.Languages[0] ? "zh-cn" : "en-us";
180+
var culture2 = "en-us";
181+
foreach (var ttf in files)
182+
{
183+
var families = Fonts.GetFontFamilies(Utils.GetFontsPath(ttf));
184+
foreach (FontFamily family in families)
185+
{
186+
var typefaces = family.GetTypefaces();
187+
foreach (Typeface typeface in typefaces)
188+
{
189+
typeface.TryGetGlyphTypeface(out GlyphTypeface glyph);
190+
//var fontFace = glyph.Win32FaceNames[new CultureInfo("en-us")];
191+
//if (!fontFace.Equals("Regular") && !fontFace.Equals("Normal"))
192+
//{
193+
// continue;
194+
//}
195+
var fontFamily = glyph.Win32FamilyNames[new CultureInfo(culture)];
196+
if (Utils.IsNullOrEmpty(fontFamily))
197+
{
198+
fontFamily = glyph.Win32FamilyNames[new CultureInfo(culture2)];
199+
if (Utils.IsNullOrEmpty(fontFamily))
200+
{
201+
continue;
202+
}
203+
}
204+
lstFonts.Add(fontFamily);
205+
break;
206+
}
207+
}
208+
}
209+
}
210+
catch (Exception ex)
211+
{
212+
Logging.SaveLog("fill fonts error", ex);
213+
}
214+
return lstFonts;
215+
}
209216
}
210217
}

0 commit comments

Comments
 (0)