change fonts folder

pull/3187/head
2dust 2023-02-04 12:50:38 +08:00
parent a704a30242
commit 238086942e
8 changed files with 41 additions and 25 deletions

View File

@ -15,8 +15,8 @@ namespace v2rayN.Converters
var fontFamily = LazyConfig.Instance.GetConfig().uiItem.currentFontFamily;
if (!string.IsNullOrEmpty(fontFamily))
{
var fontPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\Fonts\");
MyFont = new FontFamily(new Uri($"file:///{fontPath}"), $"./#{fontFamily}");
var fontPath = Utils.GetFontsPath();
MyFont = new FontFamily(new Uri(@$"file:///{fontPath}\"), $"./#{fontFamily}");
}
}
catch

View File

@ -2402,7 +2402,7 @@ namespace v2rayN.Resx {
}
/// <summary>
/// 查找类似 Copy the font TTF file to the directory Resources\Fonts, restart the settings 的本地化字符串。
/// 查找类似 Copy the font TTF file to the directory guiFonts, restart the settings 的本地化字符串。
/// </summary>
public static string TbSettingsCurrentFontFamilyTip {
get {

View File

@ -1097,7 +1097,7 @@
<value>FontFamily(Require restart)</value>
</data>
<data name="TbSettingsCurrentFontFamilyTip" xml:space="preserve">
<value>Copy the font TTF file to the directory Resources\Fonts, restart the settings</value>
<value>Copy the font TTF file to the directory guiFonts, restart the settings</value>
</data>
<data name="TbSettingsSocksPortTip" xml:space="preserve">
<value>http port=socks port+1</value>

View File

@ -1097,7 +1097,7 @@
<value>当前字体(需重启)</value>
</data>
<data name="TbSettingsCurrentFontFamilyTip" xml:space="preserve">
<value>拷贝字体TTF文件到目录Resources\Fonts重启设置</value>
<value>拷贝字体TTF文件到目录guiFonts重启设置</value>
</data>
<data name="TbSettingsSocksPortTip" xml:space="preserve">
<value>http端口=socks端口+1</value>

View File

@ -1135,6 +1135,22 @@ namespace v2rayN
return Path.Combine(_tempPath, filename);
}
}
public static string GetFontsPath(string filename = "")
{
string _tempPath = Path.Combine(StartupPath(), "guiFonts");
if (!Directory.Exists(_tempPath))
{
Directory.CreateDirectory(_tempPath);
}
if (string.IsNullOrEmpty(filename))
{
return _tempPath;
}
else
{
return Path.Combine(_tempPath, filename);
}
}
#endregion

View File

@ -66,23 +66,32 @@ namespace v2rayN.Views
//fill fonts
try
{
var dir = new DirectoryInfo(Utils.GetPath(@"Resources\Fonts"));
var dir = new DirectoryInfo(Utils.GetFontsPath());
var files = dir.GetFiles("*.ttf");
var culture = _config.uiItem.currentLanguage.Equals(Global.Languages[0]) ? "zh-cn" : "en-us";
foreach (var it in files)
{
var glyphTypeface = new GlyphTypeface(new Uri(Utils.GetPath(@$"Resources\Fonts\{it.Name}")));
var fontFace = glyphTypeface.Win32FaceNames[new CultureInfo("en-us")];
if (!fontFace.Equals("Regular") && !fontFace.Equals("Normal"))
var families = Fonts.GetFontFamilies(Utils.GetFontsPath(it.Name));
foreach (FontFamily family in families)
{
continue;
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))
{
continue;
}
cmbcurrentFontFamily.Items.Add(fontFamily);
break;
}
}
var fontFamily = glyphTypeface.Win32FamilyNames[new CultureInfo(culture)];
if (Utils.IsNullOrEmpty(fontFamily))
{
continue;
}
cmbcurrentFontFamily.Items.Add(fontFamily);
}
}
catch (Exception ex)

View File

@ -101,13 +101,4 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="Resources\Fonts\SourceHanSansCN-Regular.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Fonts\微软雅黑.ttf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>