From 373d89874c886962e7a14dafb939e13b7bb28d17 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Thu, 2 Feb 2023 13:51:58 +0800 Subject: [PATCH] Add custom font settings --- .../v2rayN/Converters/MaterialDesignFonts.cs | 19 +- v2rayN/v2rayN/Mode/ConfigItems.cs | 1 + v2rayN/v2rayN/Resx/ResUI.Designer.cs | 36 ++ v2rayN/v2rayN/Resx/ResUI.resx | 12 + v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx | 14 +- .../ViewModels/OptionSettingViewModel.cs | 5 + v2rayN/v2rayN/Views/OptionSettingWindow.xaml | 355 ++++++++++-------- .../v2rayN/Views/OptionSettingWindow.xaml.cs | 37 ++ v2rayN/v2rayN/v2rayN.csproj | 5 +- 9 files changed, 321 insertions(+), 163 deletions(-) diff --git a/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs b/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs index fb37480a..b82d4c76 100644 --- a/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs +++ b/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs @@ -1,5 +1,6 @@ using System.IO; using System.Windows.Media; +using v2rayN.Handler; namespace v2rayN.Converters { @@ -9,8 +10,22 @@ namespace v2rayN.Converters static MaterialDesignFonts() { - var fontPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\Fonts\"); - MyFont = new FontFamily(new Uri($"file:///{fontPath}"), "./#Source Han Sans CN"); + try + { + 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}"); + } + } + catch + { + } + if (MyFont is null) + { + MyFont = new FontFamily("Microsoft YaHei"); + } } } } \ No newline at end of file diff --git a/v2rayN/v2rayN/Mode/ConfigItems.cs b/v2rayN/v2rayN/Mode/ConfigItems.cs index 1fb2e4fe..f2dfe157 100644 --- a/v2rayN/v2rayN/Mode/ConfigItems.cs +++ b/v2rayN/v2rayN/Mode/ConfigItems.cs @@ -62,6 +62,7 @@ namespace v2rayN.Mode public bool colorModeDark { get; set; } public string? colorPrimaryName { get; set; } public string currentLanguage { get; set; } + public string currentFontFamily { get; set; } public bool enableDragDropSort { get; set; } public bool doubleClick2Activate { get; set; } public Dictionary mainLvColWidth { get; set; } diff --git a/v2rayN/v2rayN/Resx/ResUI.Designer.cs b/v2rayN/v2rayN/Resx/ResUI.Designer.cs index 8597560f..9df4c5f4 100644 --- a/v2rayN/v2rayN/Resx/ResUI.Designer.cs +++ b/v2rayN/v2rayN/Resx/ResUI.Designer.cs @@ -2392,6 +2392,24 @@ namespace v2rayN.Resx { } } + /// + /// 查找类似 FontFamily(Require restart) 的本地化字符串。 + /// + public static string TbSettingsCurrentFontFamily { + get { + return ResourceManager.GetString("TbSettingsCurrentFontFamily", resourceCulture); + } + } + + /// + /// 查找类似 Copy the font TTF file to the directory Resources\Fonts, restart the settings 的本地化字符串。 + /// + public static string TbSettingsCurrentFontFamilyTip { + get { + return ResourceManager.GetString("TbSettingsCurrentFontFamilyTip", resourceCulture); + } + } + /// /// 查找类似 AllowInsecure 的本地化字符串。 /// @@ -2653,6 +2671,15 @@ namespace v2rayN.Resx { } } + /// + /// 查找类似 http port=socks port+1 的本地化字符串。 + /// + public static string TbSettingsSocksPortTip { + get { + return ResourceManager.GetString("TbSettingsSocksPortTip", resourceCulture); + } + } + /// /// 查找类似 Start on boot 的本地化字符串。 /// @@ -2662,6 +2689,15 @@ namespace v2rayN.Resx { } } + /// + /// 查找类似 Set this with admin privileges, get admin privileges after startup 的本地化字符串。 + /// + public static string TbSettingsStartBootTip { + get { + return ResourceManager.GetString("TbSettingsStartBootTip", resourceCulture); + } + } + /// /// 查找类似 Enable Statistics (Require restart) 的本地化字符串。 /// diff --git a/v2rayN/v2rayN/Resx/ResUI.resx b/v2rayN/v2rayN/Resx/ResUI.resx index cfa575dd..b1f81bd8 100644 --- a/v2rayN/v2rayN/Resx/ResUI.resx +++ b/v2rayN/v2rayN/Resx/ResUI.resx @@ -1093,4 +1093,16 @@ This parameter is valid only for tcp/http and ws + + FontFamily(Require restart) + + + Copy the font TTF file to the directory Resources\Fonts, restart the settings + + + http port=socks port+1 + + + Set this with admin privileges, get admin privileges after startup + \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx index f27e18bd..317264e6 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx @@ -1088,9 +1088,21 @@ 默认TLS指纹(fingerprint) - 用户代理(UA) + 用户代理(User-Agent) 仅对tcp/http、ws协议生效 + + 当前字体(需重启) + + + 拷贝字体TTF文件到目录Resources\Fonts,重启设置 + + + http端口=socks端口+1 + + + 以管理员权限设置此项,在启动后获得管理员权限 + \ No newline at end of file diff --git a/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs index d532dba0..23cdeeb6 100644 --- a/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs @@ -62,6 +62,8 @@ namespace v2rayN.ViewModels [Reactive] public int autoUpdateInterval { get; set; } [Reactive] public int autoUpdateSubInterval { get; set; } [Reactive] public int trayMenuServersLimit { get; set; } + [Reactive] public string currentFontFamily { get; set; } + #endregion #region System proxy @@ -146,6 +148,8 @@ namespace v2rayN.ViewModels autoUpdateInterval = _config.autoUpdateInterval; autoUpdateSubInterval = _config.autoUpdateSubInterval; trayMenuServersLimit = _config.trayMenuServersLimit; + currentFontFamily = _config.uiItem.currentFontFamily; + #endregion #region System proxy @@ -312,6 +316,7 @@ namespace v2rayN.ViewModels _config.uiItem.enableDragDropSort = EnableDragDropSort; _config.uiItem.doubleClick2Activate = DoubleClick2Activate; _config.trayMenuServersLimit = trayMenuServersLimit; + _config.uiItem.currentFontFamily = currentFontFamily; //systemProxy _config.systemProxyExceptions = systemProxyExceptions; diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml index 72dd0f6e..0cb6806c 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml @@ -64,8 +64,8 @@ - - + + @@ -74,204 +74,212 @@ + Grid.Row="0" + Grid.Column="0" + Margin="{StaticResource SettingItemMargin}" + VerticalAlignment="Center" + Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.TbSettingsSocksPort}" /> + x:Name="txtlocalPort" + Grid.Row="0" + Grid.Column="1" + Width="200" + Margin="{StaticResource SettingItemMargin}" /> + + Grid.Row="1" + Grid.Column="0" + Margin="{StaticResource SettingItemMargin}" + VerticalAlignment="Center" + Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.TbSettingsUdpEnabled}" /> + x:Name="togudpEnabled" + Grid.Row="1" + Grid.Column="1" + Margin="{StaticResource SettingItemMargin}" + HorizontalAlignment="Left" /> + Grid.Row="2" + Grid.Column="0" + Margin="{StaticResource SettingItemMargin}" + VerticalAlignment="Center" + Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.TbSettingsSniffingEnabled}" /> + x:Name="togsniffingEnabled" + Grid.Row="2" + Grid.Column="1" + Margin="{StaticResource SettingItemMargin}" + HorizontalAlignment="Left" /> + Grid.Row="3" + Grid.Column="0" + Margin="{StaticResource SettingItemMargin}" + VerticalAlignment="Center" + Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.TbSettingsRouteOnly}" /> + x:Name="togrouteOnly" + Grid.Row="3" + Grid.Column="1" + Margin="{StaticResource SettingItemMargin}" + HorizontalAlignment="Left" /> + Grid.Row="4" + Grid.Column="0" + Margin="{StaticResource SettingItemMargin}" + VerticalAlignment="Center" + Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.TbSettingsAllowLAN}" /> + x:Name="togAllowLANConn" + Grid.Row="4" + Grid.Column="1" + Margin="{StaticResource SettingItemMargin}" + HorizontalAlignment="Left" /> + Grid.Row="5" + Grid.Column="0" + Margin="{StaticResource SettingItemMargin}" + VerticalAlignment="Center" + Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.TbSettingsNewPort4LAN}" /> + x:Name="togNewPort4LAN" + Grid.Row="5" + Grid.Column="1" + Margin="{StaticResource SettingItemMargin}" + HorizontalAlignment="Left" /> + Grid.Row="6" + Grid.Column="0" + Margin="{StaticResource SettingItemMargin}" + VerticalAlignment="Center" + Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.TbSettingsUser}" /> + x:Name="txtuser" + Grid.Row="6" + Grid.Column="1" + Width="200" + Margin="{StaticResource SettingItemMargin}" /> + Grid.Row="7" + Grid.Column="0" + Margin="{StaticResource SettingItemMargin}" + VerticalAlignment="Center" + Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.TbSettingsPass}" /> + x:Name="txtpass" + Grid.Row="7" + Grid.Column="1" + Width="200" + Margin="{StaticResource SettingItemMargin}" /> + Grid.Row="8" + Grid.Column="0" + Margin="{StaticResource SettingItemMargin}" + VerticalAlignment="Center" + Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.TbSettingsMuxEnabled}" /> + x:Name="togmuxEnabled" + Grid.Row="8" + Grid.Column="1" + Margin="{StaticResource SettingItemMargin}" + HorizontalAlignment="Left" /> + Grid.Row="9" + Grid.Column="0" + Margin="{StaticResource SettingItemMargin}" + VerticalAlignment="Center" + Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.TbSettingsLogEnabled}" /> + x:Name="toglogEnabled" + Grid.Row="9" + Grid.Column="1" + Margin="{StaticResource SettingItemMargin}" + HorizontalAlignment="Left" /> + Grid.Row="10" + Grid.Column="0" + Margin="{StaticResource SettingItemMargin}" + VerticalAlignment="Center" + Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.TbSettingsLogLevel}" /> + x:Name="cmbloglevel" + Grid.Row="10" + Grid.Column="1" + Margin="{StaticResource SettingItemMargin}" + materialDesign:HintAssist.Hint="Level" /> + Grid.Row="11" + Grid.Column="0" + Margin="{StaticResource SettingItemMargin}" + VerticalAlignment="Center" + Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.TbSettingsDefAllowInsecure}" /> + x:Name="togdefAllowInsecure" + Grid.Row="11" + Grid.Column="1" + Margin="{StaticResource SettingItemMargin}" + HorizontalAlignment="Left" /> + Grid.Row="12" + Grid.Column="0" + Margin="{StaticResource SettingItemMargin}" + VerticalAlignment="Center" + Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.TbSettingsDefFingerprint}" /> + x:Name="cmbdefFingerprint" + Grid.Row="12" + Grid.Column="1" + Margin="{StaticResource SettingItemMargin}" /> + Grid.Row="13" + Grid.Column="0" + Margin="{StaticResource SettingItemMargin}" + VerticalAlignment="Center" + Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.TbSettingsDefUserAgent}" /> + x:Name="cmbdefUserAgent" + Grid.Row="13" + Grid.Column="1" + Margin="{StaticResource SettingItemMargin}" + IsEditable="True" /> + Grid.Row="13" + Grid.Column="3" + Margin="{StaticResource SettingItemMargin}" + Style="{StaticResource ToolbarTextBlock}" + Text="{x:Static resx:ResUI.TbSettingsDefUserAgentTips}" /> @@ -462,6 +470,7 @@ + + + + + + diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs index 639adb31..34e3de72 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs @@ -1,15 +1,23 @@ using ReactiveUI; +using System.Globalization; +using System.IO; using System.Reactive.Disposables; using System.Windows; +using System.Windows.Media; +using v2rayN.Handler; +using v2rayN.Mode; using v2rayN.ViewModels; namespace v2rayN.Views { public partial class OptionSettingWindow { + private static Config _config; + public OptionSettingWindow() { InitializeComponent(); + _config = LazyConfig.Instance.GetConfig(); ViewModel = new OptionSettingViewModel(this); @@ -55,6 +63,34 @@ namespace v2rayN.Views cmbCoreType6.Items.Add(it); }); + //fill fonts + try + { + var dir = new DirectoryInfo(Utils.GetPath(@"Resources\Fonts")); + 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")) + { + continue; + } + var fontFamily = glyphTypeface.Win32FamilyNames[new CultureInfo(culture)]; + if (Utils.IsNullOrEmpty(fontFamily)) + { + continue; + } + cmbcurrentFontFamily.Items.Add(fontFamily); + } + } + catch (Exception ex) + { + Utils.SaveLog("fill fonts error", ex); + } + cmbcurrentFontFamily.Items.Add(string.Empty); + this.WhenActivated(disposables => { this.Bind(ViewModel, vm => vm.localPort, v => v.txtlocalPort.Text).DisposeWith(disposables); @@ -102,6 +138,7 @@ namespace v2rayN.Views this.Bind(ViewModel, vm => vm.autoUpdateInterval, v => v.txtautoUpdateInterval.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.autoUpdateSubInterval, v => v.txtautoUpdateSubInterval.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.trayMenuServersLimit, v => v.txttrayMenuServersLimit.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.currentFontFamily, v => v.cmbcurrentFontFamily.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.systemProxyAdvancedProtocol, v => v.cmbsystemProxyAdvancedProtocol.Text).DisposeWith(disposables); diff --git a/v2rayN/v2rayN/v2rayN.csproj b/v2rayN/v2rayN/v2rayN.csproj index d12ef3aa..90b79974 100644 --- a/v2rayN/v2rayN/v2rayN.csproj +++ b/v2rayN/v2rayN/v2rayN.csproj @@ -13,7 +13,7 @@ - + @@ -105,6 +105,9 @@ PreserveNewest + + Always +