mirror of
				https://github.com/2dust/v2rayN.git
				synced 2025-11-04 06:22:52 +00:00 
			
		
		
		
	Add custom font settings
This commit is contained in:
		
							parent
							
								
									976087ce97
								
							
						
					
					
						commit
						373d89874c
					
				
					 9 changed files with 321 additions and 163 deletions
				
			
		| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
using System.IO;
 | 
			
		||||
using System.Windows.Media;
 | 
			
		||||
using v2rayN.Handler;
 | 
			
		||||
 | 
			
		||||
namespace v2rayN.Converters
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -8,9 +9,23 @@ namespace v2rayN.Converters
 | 
			
		|||
        public static FontFamily MyFont { get; }
 | 
			
		||||
 | 
			
		||||
        static MaterialDesignFonts()
 | 
			
		||||
        {
 | 
			
		||||
            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}"), "./#Source Han Sans CN");
 | 
			
		||||
                    MyFont = new FontFamily(new Uri($"file:///{fontPath}"), $"./#{fontFamily}");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            catch
 | 
			
		||||
            {
 | 
			
		||||
            }
 | 
			
		||||
            if (MyFont is null)
 | 
			
		||||
            {
 | 
			
		||||
                MyFont = new FontFamily("Microsoft YaHei");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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<string, int> mainLvColWidth { get; set; }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										36
									
								
								v2rayN/v2rayN/Resx/ResUI.Designer.cs
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										36
									
								
								v2rayN/v2rayN/Resx/ResUI.Designer.cs
									
									
									
										generated
									
									
									
								
							| 
						 | 
				
			
			@ -2392,6 +2392,24 @@ namespace v2rayN.Resx {
 | 
			
		|||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   查找类似 FontFamily(Require restart) 的本地化字符串。
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static string TbSettingsCurrentFontFamily {
 | 
			
		||||
            get {
 | 
			
		||||
                return ResourceManager.GetString("TbSettingsCurrentFontFamily", resourceCulture);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   查找类似 Copy the font TTF file to the directory Resources\Fonts, restart the settings 的本地化字符串。
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static string TbSettingsCurrentFontFamilyTip {
 | 
			
		||||
            get {
 | 
			
		||||
                return ResourceManager.GetString("TbSettingsCurrentFontFamilyTip", resourceCulture);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   查找类似 AllowInsecure 的本地化字符串。
 | 
			
		||||
        /// </summary>
 | 
			
		||||
| 
						 | 
				
			
			@ -2653,6 +2671,15 @@ namespace v2rayN.Resx {
 | 
			
		|||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   查找类似 http port=socks port+1 的本地化字符串。
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static string TbSettingsSocksPortTip {
 | 
			
		||||
            get {
 | 
			
		||||
                return ResourceManager.GetString("TbSettingsSocksPortTip", resourceCulture);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   查找类似 Start on boot 的本地化字符串。
 | 
			
		||||
        /// </summary>
 | 
			
		||||
| 
						 | 
				
			
			@ -2662,6 +2689,15 @@ namespace v2rayN.Resx {
 | 
			
		|||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   查找类似 Set this with admin privileges, get admin privileges after startup 的本地化字符串。
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static string TbSettingsStartBootTip {
 | 
			
		||||
            get {
 | 
			
		||||
                return ResourceManager.GetString("TbSettingsStartBootTip", resourceCulture);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///   查找类似 Enable Statistics (Require restart) 的本地化字符串。
 | 
			
		||||
        /// </summary>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1093,4 +1093,16 @@
 | 
			
		|||
  <data name="TbSettingsDefUserAgentTips" xml:space="preserve">
 | 
			
		||||
    <value>This parameter is valid only for tcp/http and ws</value>
 | 
			
		||||
  </data>
 | 
			
		||||
  <data name="TbSettingsCurrentFontFamily" xml:space="preserve">
 | 
			
		||||
    <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>
 | 
			
		||||
  </data>
 | 
			
		||||
  <data name="TbSettingsSocksPortTip" xml:space="preserve">
 | 
			
		||||
    <value>http port=socks port+1</value>
 | 
			
		||||
  </data>
 | 
			
		||||
  <data name="TbSettingsStartBootTip" xml:space="preserve">
 | 
			
		||||
    <value>Set this with admin privileges, get admin privileges after startup</value>
 | 
			
		||||
  </data>
 | 
			
		||||
</root>
 | 
			
		||||
| 
						 | 
				
			
			@ -1088,9 +1088,21 @@
 | 
			
		|||
    <value>默认TLS指纹(fingerprint)</value>
 | 
			
		||||
  </data>
 | 
			
		||||
  <data name="TbSettingsDefUserAgent" xml:space="preserve">
 | 
			
		||||
    <value>用户代理(UA)</value>
 | 
			
		||||
    <value>用户代理(User-Agent)</value>
 | 
			
		||||
  </data>
 | 
			
		||||
  <data name="TbSettingsDefUserAgentTips" xml:space="preserve">
 | 
			
		||||
    <value>仅对tcp/http、ws协议生效</value>
 | 
			
		||||
  </data>
 | 
			
		||||
  <data name="TbSettingsCurrentFontFamily" xml:space="preserve">
 | 
			
		||||
    <value>当前字体(需重启)</value>
 | 
			
		||||
  </data>
 | 
			
		||||
  <data name="TbSettingsCurrentFontFamilyTip" xml:space="preserve">
 | 
			
		||||
    <value>拷贝字体TTF文件到目录Resources\Fonts,重启设置</value>
 | 
			
		||||
  </data>
 | 
			
		||||
  <data name="TbSettingsSocksPortTip" xml:space="preserve">
 | 
			
		||||
    <value>http端口=socks端口+1</value>
 | 
			
		||||
  </data>
 | 
			
		||||
  <data name="TbSettingsStartBootTip" xml:space="preserve">
 | 
			
		||||
    <value>以管理员权限设置此项,在启动后获得管理员权限</value>
 | 
			
		||||
  </data>
 | 
			
		||||
</root>
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -86,6 +86,13 @@
 | 
			
		|||
                            Grid.Column="1"
 | 
			
		||||
                            Width="200"
 | 
			
		||||
                            Margin="{StaticResource SettingItemMargin}" />
 | 
			
		||||
                        <TextBlock
 | 
			
		||||
                            Grid.Row="0"
 | 
			
		||||
                            Grid.Column="2"
 | 
			
		||||
                            Margin="{StaticResource ServerItemMargin}"
 | 
			
		||||
                            VerticalAlignment="Center"
 | 
			
		||||
                            Style="{StaticResource ToolbarTextBlock}"
 | 
			
		||||
                            Text="{x:Static resx:ResUI.TbSettingsSocksPortTip}" />
 | 
			
		||||
 | 
			
		||||
                        <TextBlock
 | 
			
		||||
                            Grid.Row="1"
 | 
			
		||||
| 
						 | 
				
			
			@ -265,7 +272,8 @@
 | 
			
		|||
                            x:Name="cmbdefUserAgent"
 | 
			
		||||
                            Grid.Row="13"
 | 
			
		||||
                            Grid.Column="1"
 | 
			
		||||
                        Margin="{StaticResource SettingItemMargin}" IsEditable="True" />
 | 
			
		||||
                            Margin="{StaticResource SettingItemMargin}"
 | 
			
		||||
                            IsEditable="True" />
 | 
			
		||||
                        <TextBlock
 | 
			
		||||
                            Grid.Row="13"
 | 
			
		||||
                            Grid.Column="3"
 | 
			
		||||
| 
						 | 
				
			
			@ -462,6 +470,7 @@
 | 
			
		|||
                        <Grid.ColumnDefinitions>
 | 
			
		||||
                            <ColumnDefinition Width="Auto" />
 | 
			
		||||
                            <ColumnDefinition Width="Auto" />
 | 
			
		||||
                            <ColumnDefinition Width="Auto" />
 | 
			
		||||
                        </Grid.ColumnDefinitions>
 | 
			
		||||
 | 
			
		||||
                        <TextBlock
 | 
			
		||||
| 
						 | 
				
			
			@ -477,6 +486,13 @@
 | 
			
		|||
                            Grid.Column="1"
 | 
			
		||||
                            Margin="{StaticResource SettingItemMargin}"
 | 
			
		||||
                            HorizontalAlignment="Left" />
 | 
			
		||||
                        <TextBlock
 | 
			
		||||
                            Grid.Row="1"
 | 
			
		||||
                            Grid.Column="2"
 | 
			
		||||
                            Margin="{StaticResource ServerItemMargin}"
 | 
			
		||||
                            VerticalAlignment="Center"
 | 
			
		||||
                            Style="{StaticResource ToolbarTextBlock}"
 | 
			
		||||
                            Text="{x:Static resx:ResUI.TbSettingsStartBootTip}" />
 | 
			
		||||
 | 
			
		||||
                        <TextBlock
 | 
			
		||||
                            Grid.Row="2"
 | 
			
		||||
| 
						 | 
				
			
			@ -659,6 +675,27 @@
 | 
			
		|||
                            Grid.Column="1"
 | 
			
		||||
                            Width="200"
 | 
			
		||||
                            Margin="{StaticResource SettingItemMargin}" />
 | 
			
		||||
 | 
			
		||||
                        <TextBlock
 | 
			
		||||
                            Grid.Row="15"
 | 
			
		||||
                            Grid.Column="0"
 | 
			
		||||
                            Margin="{StaticResource SettingItemMargin}"
 | 
			
		||||
                            VerticalAlignment="Center"
 | 
			
		||||
                            Style="{StaticResource ToolbarTextBlock}"
 | 
			
		||||
                            Text="{x:Static resx:ResUI.TbSettingsCurrentFontFamily}" />
 | 
			
		||||
                        <ComboBox
 | 
			
		||||
                            x:Name="cmbcurrentFontFamily"
 | 
			
		||||
                            Grid.Row="15"
 | 
			
		||||
                            Grid.Column="1"
 | 
			
		||||
                            Margin="{StaticResource SettingItemMargin}"
 | 
			
		||||
                            MaxDropDownHeight="1000" />
 | 
			
		||||
                        <TextBlock
 | 
			
		||||
                            Grid.Row="15"
 | 
			
		||||
                            Grid.Column="2"
 | 
			
		||||
                            Margin="{StaticResource ServerItemMargin}"
 | 
			
		||||
                            VerticalAlignment="Center"
 | 
			
		||||
                            Style="{StaticResource ToolbarTextBlock}"
 | 
			
		||||
                            Text="{x:Static resx:ResUI.TbSettingsCurrentFontFamilyTip}" />
 | 
			
		||||
                    </Grid>
 | 
			
		||||
                </ScrollViewer>
 | 
			
		||||
            </TabItem>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,7 +13,7 @@
 | 
			
		|||
	</PropertyGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>		
 | 
			
		||||
		<PackageReference Include="MaterialDesignThemes" Version="4.6.1" />
 | 
			
		||||
		<PackageReference Include="MaterialDesignThemes" Version="4.7.1" />
 | 
			
		||||
		<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />		 
 | 
			
		||||
		<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
 | 
			
		||||
		<PackageReference Include="NHotkey" Version="2.1.0" />
 | 
			
		||||
| 
						 | 
				
			
			@ -105,6 +105,9 @@
 | 
			
		|||
	  <None Update="Resources\Fonts\SourceHanSansCN-Regular.ttf">
 | 
			
		||||
	    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
 | 
			
		||||
	  </None>
 | 
			
		||||
	  <None Update="Resources\Fonts\微软雅黑.ttf">
 | 
			
		||||
	    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
 | 
			
		||||
	  </None>
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
 | 
			
		||||
</Project>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue