mirror of
https://github.com/2dust/v2rayN.git
synced 2025-11-29 03:02:53 +00:00
Update AppBuilderExtension.cs
This commit is contained in:
parent
995097801d
commit
036dda7a11
1 changed files with 31 additions and 23 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Avalonia;
|
using System.Linq;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace v2rayN.Desktop.Common;
|
namespace v2rayN.Desktop.Common;
|
||||||
|
|
||||||
|
|
@ -18,25 +18,20 @@ public static class AppBuilderExtension
|
||||||
{
|
{
|
||||||
FontFallbacks = new[]
|
FontFallbacks = new[]
|
||||||
{
|
{
|
||||||
new FontFallback { FontFamily = new FontFamily(uri) }
|
new FontFallback
|
||||||
|
{
|
||||||
|
FontFamily = new FontFamily(uri)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
List<FontFallback> fallbacks = new();
|
var fallbacks = new List<FontFallback>();
|
||||||
|
|
||||||
string? zhFamily = RunFcMatchFamily("sans:lang=zh-cn");
|
var emojiFamily = DetectFontFamily("emoji");
|
||||||
string? emojiFamily = RunFcMatchFamily("emoji");
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(zhFamily))
|
if (!string.IsNullOrWhiteSpace(emojiFamily) &&
|
||||||
{
|
emojiFamily.Contains("Noto Color Emoji", StringComparison.OrdinalIgnoreCase))
|
||||||
fallbacks.Add(new FontFallback
|
|
||||||
{
|
|
||||||
FontFamily = new FontFamily(zhFamily)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(emojiFamily))
|
|
||||||
{
|
{
|
||||||
fallbacks.Add(new FontFallback
|
fallbacks.Add(new FontFallback
|
||||||
{
|
{
|
||||||
|
|
@ -44,10 +39,10 @@ public static class AppBuilderExtension
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var localFont = Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC");
|
var notoScUri = Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC");
|
||||||
fallbacks.Add(new FontFallback
|
fallbacks.Add(new FontFallback
|
||||||
{
|
{
|
||||||
FontFamily = new FontFamily(localFont)
|
FontFamily = new FontFamily(notoScUri)
|
||||||
});
|
});
|
||||||
|
|
||||||
return appBuilder.With(new FontManagerOptions
|
return appBuilder.With(new FontManagerOptions
|
||||||
|
|
@ -56,23 +51,36 @@ public static class AppBuilderExtension
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string? RunFcMatchFamily(string pattern)
|
private static string? DetectFontFamily(string pattern)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var psi = new ProcessStartInfo
|
var psi = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = "/bin/bash",
|
FileName = "/bin/bash",
|
||||||
ArgumentList = { "-c", $"fc-match -f \"%{{family}}\\n\" \"{pattern}\" | head -n 1" },
|
ArgumentList =
|
||||||
|
{
|
||||||
|
"-c",
|
||||||
|
$"fc-match -f \"%{{family}}\\n\" \"{pattern}\" | head -n 1"
|
||||||
|
},
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
UseShellExecute = false
|
RedirectStandardError = true,
|
||||||
|
UseShellExecute = false
|
||||||
};
|
};
|
||||||
|
|
||||||
using var p = Process.Start(psi);
|
using var p = Process.Start(psi);
|
||||||
if (p == null) return null;
|
if (p == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
string output = p.StandardOutput.ReadToEnd().Trim();
|
p.WaitForExit(2000);
|
||||||
return string.IsNullOrWhiteSpace(output) ? null : output;
|
|
||||||
|
var output = p.StandardOutput.ReadToEnd();
|
||||||
|
var family = output
|
||||||
|
.Split('\n', StringSplitOptions.RemoveEmptyEntries)
|
||||||
|
.FirstOrDefault()
|
||||||
|
?.Trim();
|
||||||
|
|
||||||
|
return string.IsNullOrWhiteSpace(family) ? null : family;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue