mirror of https://github.com/2dust/v2rayN
Add font settings for Desktop
parent
1273d2aee1
commit
b7f4fd7469
|
@ -818,6 +818,13 @@ namespace ServiceLib.Common
|
|||
return await GetCliWrapOutput("/bin/bash", arg);
|
||||
}
|
||||
|
||||
public static async Task<string?> GetLinuxFontFamily(string lang)
|
||||
{
|
||||
// var arg = new List<string>() { "-c", $"fc-list :lang={lang} family" };
|
||||
var arg = new List<string>() { "-c", $"fc-list : family" };
|
||||
return await GetCliWrapOutput("/bin/bash", arg);
|
||||
}
|
||||
|
||||
#endregion Platform
|
||||
}
|
||||
}
|
|
@ -2860,6 +2860,15 @@ namespace ServiceLib.Resx {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Install the font to the system and restart the settings 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string TbSettingsCurrentFontFamilyLinuxTip {
|
||||
get {
|
||||
return ResourceManager.GetString("TbSettingsCurrentFontFamilyLinuxTip", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Copy the font TTF/TTC file to the directory guiFonts, restart the settings 的本地化字符串。
|
||||
/// </summary>
|
||||
|
|
|
@ -1360,4 +1360,7 @@
|
|||
<data name="InsecureUrlProtocol" xml:space="preserve">
|
||||
<value>Please do not use the insecure HTTP protocol subscription address</value>
|
||||
</data>
|
||||
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
||||
<value>Install the font to the system and restart the settings</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1357,4 +1357,7 @@
|
|||
<data name="InsecureUrlProtocol" xml:space="preserve">
|
||||
<value>请不要使用不安全的HTTP协议订阅地址</value>
|
||||
</data>
|
||||
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
||||
<value>安装字体到系统中,重启设置</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1237,4 +1237,7 @@
|
|||
<data name="InsecureUrlProtocol" xml:space="preserve">
|
||||
<value>請不要使用不安全的HTTP協定訂閱位址</value>
|
||||
</data>
|
||||
<data name="TbSettingsCurrentFontFamilyLinuxTip" xml:space="preserve">
|
||||
<value>安裝字體到系統中,重新啟動設定</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1,5 +1,7 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Styling;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
|
@ -9,14 +11,11 @@ namespace v2rayN.Desktop.ViewModels
|
|||
{
|
||||
public class ThemeSettingViewModel : MyReactiveObject
|
||||
{
|
||||
[Reactive]
|
||||
public bool ColorModeDark { get; set; }
|
||||
[Reactive] public bool ColorModeDark { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public int CurrentFontSize { get; set; }
|
||||
[Reactive] public int CurrentFontSize { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string CurrentLanguage { get; set; }
|
||||
[Reactive] public string CurrentLanguage { get; set; }
|
||||
|
||||
public ThemeSettingViewModel()
|
||||
{
|
||||
|
@ -29,6 +28,7 @@ namespace v2rayN.Desktop.ViewModels
|
|||
private void RestoreUI()
|
||||
{
|
||||
ModifyTheme(_config.UiItem.ColorModeDark);
|
||||
ModifyFontFamily();
|
||||
}
|
||||
|
||||
private void BindingUI()
|
||||
|
@ -38,34 +38,34 @@ namespace v2rayN.Desktop.ViewModels
|
|||
CurrentLanguage = _config.UiItem.CurrentLanguage;
|
||||
|
||||
this.WhenAnyValue(x => x.ColorModeDark)
|
||||
.Subscribe(c =>
|
||||
{
|
||||
if (_config.UiItem.ColorModeDark != ColorModeDark)
|
||||
{
|
||||
_config.UiItem.ColorModeDark = ColorModeDark;
|
||||
ModifyTheme(ColorModeDark);
|
||||
ConfigHandler.SaveConfig(_config);
|
||||
}
|
||||
});
|
||||
.Subscribe(c =>
|
||||
{
|
||||
if (_config.UiItem.ColorModeDark != ColorModeDark)
|
||||
{
|
||||
_config.UiItem.ColorModeDark = ColorModeDark;
|
||||
ModifyTheme(ColorModeDark);
|
||||
ConfigHandler.SaveConfig(_config);
|
||||
}
|
||||
});
|
||||
|
||||
this.WhenAnyValue(
|
||||
x => x.CurrentFontSize,
|
||||
y => y > 0)
|
||||
.Subscribe(c =>
|
||||
{
|
||||
if (CurrentFontSize >= Global.MinFontSize)
|
||||
{
|
||||
_config.UiItem.CurrentFontSize = CurrentFontSize;
|
||||
double size = CurrentFontSize;
|
||||
ModifyFontSize(size);
|
||||
x => x.CurrentFontSize,
|
||||
y => y > 0)
|
||||
.Subscribe(c =>
|
||||
{
|
||||
if (CurrentFontSize >= Global.MinFontSize)
|
||||
{
|
||||
_config.UiItem.CurrentFontSize = CurrentFontSize;
|
||||
double size = CurrentFontSize;
|
||||
ModifyFontSize(size);
|
||||
|
||||
ConfigHandler.SaveConfig(_config);
|
||||
}
|
||||
});
|
||||
ConfigHandler.SaveConfig(_config);
|
||||
}
|
||||
});
|
||||
|
||||
this.WhenAnyValue(
|
||||
x => x.CurrentLanguage,
|
||||
y => y != null && !y.IsNullOrEmpty())
|
||||
x => x.CurrentLanguage,
|
||||
y => y != null && !y.IsNullOrEmpty())
|
||||
.Subscribe(c =>
|
||||
{
|
||||
if (Utils.IsNotEmpty(CurrentLanguage) && _config.UiItem.CurrentLanguage != CurrentLanguage)
|
||||
|
@ -89,53 +89,51 @@ namespace v2rayN.Desktop.ViewModels
|
|||
|
||||
private void ModifyFontSize(double size)
|
||||
{
|
||||
Style buttonStyle = new(x => x.OfType<Button>());
|
||||
buttonStyle.Add(new Setter()
|
||||
Style style = new(x => Selectors.Or(
|
||||
x.OfType<Button>(),
|
||||
x.OfType<TextBox>(),
|
||||
x.OfType<TextBlock>(),
|
||||
x.OfType<Menu>(),
|
||||
x.OfType<DataGridRow>(),
|
||||
x.OfType<ListBoxItem>()
|
||||
));
|
||||
style.Add(new Setter()
|
||||
{
|
||||
Property = Button.FontSizeProperty,
|
||||
Property = TemplatedControl.FontSizeProperty,
|
||||
Value = size,
|
||||
});
|
||||
Application.Current?.Styles.Add(buttonStyle);
|
||||
Application.Current?.Styles.Add(style);
|
||||
}
|
||||
|
||||
Style textStyle = new(x => x.OfType<TextBox>());
|
||||
textStyle.Add(new Setter()
|
||||
private void ModifyFontFamily()
|
||||
{
|
||||
var currentFontFamily = _config.UiItem.CurrentFontFamily;
|
||||
if (currentFontFamily.IsNullOrEmpty())
|
||||
{
|
||||
Property = TextBox.FontSizeProperty,
|
||||
Value = size,
|
||||
});
|
||||
Application.Current?.Styles.Add(textStyle);
|
||||
return;
|
||||
}
|
||||
|
||||
Style textBlockStyle = new(x => x.OfType<TextBlock>());
|
||||
textBlockStyle.Add(new Setter()
|
||||
try
|
||||
{
|
||||
Property = TextBlock.FontSizeProperty,
|
||||
Value = size,
|
||||
});
|
||||
Application.Current?.Styles.Add(textBlockStyle);
|
||||
|
||||
Style menuStyle = new(x => x.OfType<Menu>());
|
||||
menuStyle.Add(new Setter()
|
||||
Style style = new(x => Selectors.Or(
|
||||
x.OfType<Button>(),
|
||||
x.OfType<TextBox>(),
|
||||
x.OfType<TextBlock>(),
|
||||
x.OfType<Menu>(),
|
||||
x.OfType<DataGridRow>(),
|
||||
x.OfType<ListBoxItem>()
|
||||
));
|
||||
style.Add(new Setter()
|
||||
{
|
||||
Property = TemplatedControl.FontFamilyProperty,
|
||||
Value = new FontFamily(currentFontFamily),
|
||||
});
|
||||
Application.Current?.Styles.Add(style);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Property = Menu.FontSizeProperty,
|
||||
Value = size,
|
||||
});
|
||||
Application.Current?.Styles.Add(menuStyle);
|
||||
|
||||
Style dataStyle = new(x => x.OfType<DataGridRow>());
|
||||
dataStyle.Add(new Setter()
|
||||
{
|
||||
Property = DataGridRow.FontSizeProperty,
|
||||
Value = size,
|
||||
});
|
||||
Application.Current?.Styles.Add(dataStyle);
|
||||
|
||||
Style listStyle = new(x => x.OfType<ListBoxItem>());
|
||||
listStyle.Add(new Setter()
|
||||
{
|
||||
Property = ListBoxItem.FontSizeProperty,
|
||||
Value = size,
|
||||
});
|
||||
Application.Current?.Styles.Add(listStyle);
|
||||
Logging.SaveLog("ModifyFontFamily", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -533,7 +533,6 @@
|
|||
Grid.Column="0"
|
||||
VerticalAlignment="Center"
|
||||
Classes="Margin8"
|
||||
IsVisible="False"
|
||||
Text="{x:Static resx:ResUI.TbSettingsCurrentFontFamily}" />
|
||||
<ComboBox
|
||||
x:Name="cmbcurrentFontFamily"
|
||||
|
@ -541,15 +540,13 @@
|
|||
Grid.Column="1"
|
||||
Width="200"
|
||||
Classes="Margin8"
|
||||
IsVisible="False"
|
||||
MaxDropDownHeight="1000" />
|
||||
<TextBlock
|
||||
Grid.Row="16"
|
||||
Grid.Column="2"
|
||||
VerticalAlignment="Center"
|
||||
Classes="Margin8"
|
||||
IsVisible="False"
|
||||
Text="{x:Static resx:ResUI.TbSettingsCurrentFontFamilyTip}"
|
||||
Text="{x:Static resx:ResUI.TbSettingsCurrentFontFamilyLinuxTip}"
|
||||
TextWrapping="Wrap" />
|
||||
|
||||
<TextBlock
|
||||
|
@ -677,7 +674,6 @@
|
|||
Classes="Margin8"
|
||||
Text="{x:Static resx:ResUI.TbSettingsChinaUserTip}"
|
||||
TextWrapping="Wrap" />
|
||||
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</TabItem>
|
||||
|
|
|
@ -15,7 +15,6 @@ namespace v2rayN.Desktop.Views
|
|||
|
||||
btnCancel.Click += (s, e) => this.Close();
|
||||
_config = AppHandler.Instance.Config;
|
||||
// var lstFonts = GetFonts(Utils.GetFontsPath());
|
||||
|
||||
ViewModel = new OptionSettingViewModel(UpdateViewHandler);
|
||||
|
||||
|
@ -100,9 +99,6 @@ namespace v2rayN.Desktop.Views
|
|||
cmbMainGirdOrientation.Items.Add(it.ToString());
|
||||
}
|
||||
|
||||
//lstFonts.ForEach(it => { cmbcurrentFontFamily.Items.Add(it); });
|
||||
//cmbcurrentFontFamily.Items.Add(string.Empty);
|
||||
|
||||
this.WhenActivated(disposables =>
|
||||
{
|
||||
this.Bind(ViewModel, vm => vm.localPort, v => v.txtlocalPort.Text).DisposeWith(disposables);
|
||||
|
@ -182,58 +178,53 @@ namespace v2rayN.Desktop.Views
|
|||
// WindowsUtils.SetAutoRun(Global.AutoRunRegPath, Global.AutoRunName, togAutoRun.IsChecked ?? false);
|
||||
this.Close(true);
|
||||
break;
|
||||
|
||||
case EViewAction.InitSettingFont:
|
||||
await InitSettingFont();
|
||||
break;
|
||||
}
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
//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;
|
||||
//}
|
||||
private async Task InitSettingFont()
|
||||
{
|
||||
var lstFonts = await GetFonts();
|
||||
lstFonts.ForEach(it => { cmbcurrentFontFamily.Items.Add(it); });
|
||||
cmbcurrentFontFamily.Items.Add(string.Empty);
|
||||
}
|
||||
|
||||
private async Task<List<string>> GetFonts()
|
||||
{
|
||||
var lstFonts = new List<string>();
|
||||
try
|
||||
{
|
||||
if (Utils.IsWindows())
|
||||
{
|
||||
return lstFonts;
|
||||
}
|
||||
else if (Utils.IsLinux())
|
||||
{
|
||||
var result = await Utils.GetLinuxFontFamily("zh");
|
||||
if (result.IsNullOrEmpty())
|
||||
{
|
||||
return lstFonts;
|
||||
}
|
||||
|
||||
var lst = result.Split(Environment.NewLine)
|
||||
.Where(t => t.IsNotEmpty())
|
||||
.ToList()
|
||||
.Select(t => t.Split(",").FirstOrDefault() ?? "")
|
||||
.OrderBy(t => t)
|
||||
.ToList();
|
||||
return lst;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog("fill fonts error", ex);
|
||||
}
|
||||
return lstFonts;
|
||||
}
|
||||
|
||||
private void ClbdestOverride_SelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue