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
c70182432b
commit
12b6580819
1 changed files with 47 additions and 14 deletions
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Avalonia;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
|
|
||||||
namespace v2rayN.Desktop.Common;
|
namespace v2rayN.Desktop.Common;
|
||||||
|
|
@ -24,25 +25,31 @@ public static class AppBuilderExtension
|
||||||
|
|
||||||
var fallbacks = new List<FontFallback>();
|
var fallbacks = new List<FontFallback>();
|
||||||
|
|
||||||
string? zhFont = RunFcMatch("sans:lang=zh-cn");
|
string? zhPath = RunFcMatch("sans:lang=zh-cn");
|
||||||
|
if (zhPath != null)
|
||||||
if (!string.IsNullOrWhiteSpace(zhFont))
|
{
|
||||||
|
var (dir, family) = ConvertPathToFontFamily(zhPath);
|
||||||
|
if (dir != null && family != null)
|
||||||
{
|
{
|
||||||
fallbacks.Add(new FontFallback
|
fallbacks.Add(new FontFallback
|
||||||
{
|
{
|
||||||
FontFamily = new FontFamily(zhFont)
|
FontFamily = new FontFamily($"file://{dir}#{family}")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string? emojiFont = RunFcMatch("emoji");
|
string? emojiPath = RunFcMatch("emoji");
|
||||||
|
if (emojiPath != null)
|
||||||
if (!string.IsNullOrWhiteSpace(emojiFont))
|
{
|
||||||
|
var (dir, family) = ConvertPathToFontFamily(emojiPath);
|
||||||
|
if (dir != null && family != null)
|
||||||
{
|
{
|
||||||
fallbacks.Add(new FontFallback
|
fallbacks.Add(new FontFallback
|
||||||
{
|
{
|
||||||
FontFamily = new FontFamily(emojiFont)
|
FontFamily = new FontFamily($"file://{dir}#{family}")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var notoUri = 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
|
||||||
|
|
@ -65,14 +72,13 @@ public static class AppBuilderExtension
|
||||||
FileName = "/bin/bash",
|
FileName = "/bin/bash",
|
||||||
ArgumentList = { "-c", $"fc-match -f \"%{{file}}\\n\" \"{pattern}\" | head -n 1" },
|
ArgumentList = { "-c", $"fc-match -f \"%{{file}}\\n\" \"{pattern}\" | head -n 1" },
|
||||||
RedirectStandardOutput = true,
|
RedirectStandardOutput = true,
|
||||||
RedirectStandardError = true,
|
|
||||||
UseShellExecute = false
|
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();
|
var output = p.StandardOutput.ReadToEnd().Trim();
|
||||||
return string.IsNullOrWhiteSpace(output) ? null : output;
|
return string.IsNullOrWhiteSpace(output) ? null : output;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|
@ -80,4 +86,31 @@ public static class AppBuilderExtension
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static (string? Dir, string? Family) ConvertPathToFontFamily(string filePath)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string dir = Path.GetDirectoryName(filePath)!;
|
||||||
|
string file = Path.GetFileNameWithoutExtension(filePath);
|
||||||
|
|
||||||
|
if (file.StartsWith("NotoColorEmoji", StringComparison.OrdinalIgnoreCase))
|
||||||
|
return (dir, "Noto Color Emoji");
|
||||||
|
|
||||||
|
if (file.StartsWith("NotoEmoji", StringComparison.OrdinalIgnoreCase))
|
||||||
|
return (dir, "Noto Emoji");
|
||||||
|
|
||||||
|
if (file.StartsWith("NotoSansCJK", StringComparison.OrdinalIgnoreCase))
|
||||||
|
return (dir, "Noto Sans CJK SC");
|
||||||
|
|
||||||
|
if (file.StartsWith("DroidSansFallbackFull", StringComparison.OrdinalIgnoreCase))
|
||||||
|
return (dir, "Droid Sans Fallback");
|
||||||
|
|
||||||
|
return (dir, file);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return (null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue