mirror of https://github.com/2dust/v2rayN
Bug fix
parent
4b9ddb803f
commit
baef3b364b
|
@ -17,7 +17,6 @@
|
|||
<TextBlock
|
||||
Margin="8,0"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource MaterialDesign.Brush.Primary.Light}"
|
||||
Style="{StaticResource ToolbarTextBlock}"
|
||||
Text="{x:Static resx:ResUI.MsgInformationTitle}" />
|
||||
<ComboBox
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace v2rayN.Views
|
|||
|
||||
this.Owner = Application.Current.MainWindow;
|
||||
_config = LazyConfig.Instance.GetConfig();
|
||||
var lstFonts = GetFonts(Utils.GetFontsPath());
|
||||
|
||||
ViewModel = new OptionSettingViewModel(this);
|
||||
|
||||
|
@ -89,50 +90,7 @@ namespace v2rayN.Views
|
|||
cmbSubConvertUrl.Items.Add(it);
|
||||
});
|
||||
|
||||
//fill fonts
|
||||
try
|
||||
{
|
||||
string[] searchPatterns = { "*.ttf", "*.ttc" };
|
||||
var files = new List<string>();
|
||||
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<string> GetFonts(string path)
|
||||
{
|
||||
var lstFonts = new List<string>();
|
||||
try
|
||||
{
|
||||
string[] searchPatterns = { "*.ttf", "*.ttc" };
|
||||
var files = new List<string>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue