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
036dda7a11
commit
a660409f06
1 changed files with 19 additions and 23 deletions
|
|
@ -2,7 +2,6 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
|
|
||||||
namespace v2rayN.Desktop.Common;
|
namespace v2rayN.Desktop.Common;
|
||||||
|
|
@ -18,20 +17,24 @@ public static class AppBuilderExtension
|
||||||
{
|
{
|
||||||
FontFallbacks = new[]
|
FontFallbacks = new[]
|
||||||
{
|
{
|
||||||
new FontFallback
|
new FontFallback { FontFamily = new FontFamily(uri) }
|
||||||
{
|
|
||||||
FontFamily = new FontFamily(uri)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var fallbacks = new List<FontFallback>();
|
var fallbacks = new List<FontFallback>();
|
||||||
|
|
||||||
var emojiFamily = DetectFontFamily("emoji");
|
string? zhFamily = RunFcMatchFamily("sans:lang=zh-cn");
|
||||||
|
if (!string.IsNullOrWhiteSpace(zhFamily))
|
||||||
|
{
|
||||||
|
fallbacks.Add(new FontFallback
|
||||||
|
{
|
||||||
|
FontFamily = new FontFamily(zhFamily)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(emojiFamily) &&
|
string? emojiFamily = RunFcMatchFamily("emoji");
|
||||||
emojiFamily.Contains("Noto Color Emoji", StringComparison.OrdinalIgnoreCase))
|
if (!string.IsNullOrWhiteSpace(emojiFamily))
|
||||||
{
|
{
|
||||||
fallbacks.Add(new FontFallback
|
fallbacks.Add(new FontFallback
|
||||||
{
|
{
|
||||||
|
|
@ -39,10 +42,10 @@ public static class AppBuilderExtension
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var notoScUri = Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC");
|
var notoUri = Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC");
|
||||||
fallbacks.Add(new FontFallback
|
fallbacks.Add(new FontFallback
|
||||||
{
|
{
|
||||||
FontFamily = new FontFamily(notoScUri)
|
FontFamily = new FontFamily(notoUri)
|
||||||
});
|
});
|
||||||
|
|
||||||
return appBuilder.With(new FontManagerOptions
|
return appBuilder.With(new FontManagerOptions
|
||||||
|
|
@ -51,7 +54,7 @@ public static class AppBuilderExtension
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string? DetectFontFamily(string pattern)
|
private static string? RunFcMatchFamily(string pattern)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -61,26 +64,19 @@ public static class AppBuilderExtension
|
||||||
ArgumentList =
|
ArgumentList =
|
||||||
{
|
{
|
||||||
"-c",
|
"-c",
|
||||||
$"fc-match -f \"%{{family}}\\n\" \"{pattern}\" | head -n 1"
|
$"fc-match -f \"%{{family[0]}}\\n\" \"{pattern}\" | head -n 1"
|
||||||
},
|
},
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
RedirectStandardError = true,
|
RedirectStandardError = false,
|
||||||
UseShellExecute = false
|
UseShellExecute = false
|
||||||
};
|
};
|
||||||
|
|
||||||
using var p = Process.Start(psi);
|
using var p = Process.Start(psi);
|
||||||
if (p == null)
|
if (p == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
p.WaitForExit(2000);
|
var output = p.StandardOutput.ReadToEnd().Trim();
|
||||||
|
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