fix: use the correct font family for CJK characters

This commit is contained in:
rockingdice
2025-06-10 18:16:56 -05:00
committed by KeatonTheBot
parent b5a1272141
commit ed0ebdec5b
+75 -10
View File
@@ -2,14 +2,29 @@ using Avalonia.Media;
using Ryujinx.Ava.UI.Windows; using Ryujinx.Ava.UI.Windows;
using Ryujinx.HLE.UI; using Ryujinx.HLE.UI;
using System; using System;
using System.Globalization;
namespace Ryujinx.Ava.UI.Applet namespace Ryujinx.Ava.UI.Applet
{ {
class AvaloniaHostUITheme : IHostUITheme class AvaloniaHostUITheme : IHostUITheme
{ {
private readonly MainWindow _parent;
public string FontFamily { get; }
public ThemeColor DefaultBackgroundColor { get; }
public ThemeColor DefaultForegroundColor { get; }
public ThemeColor DefaultBorderColor { get; }
public ThemeColor SelectionBackgroundColor { get; }
public ThemeColor SelectionForegroundColor { get; }
public AvaloniaHostUITheme(MainWindow parent) public AvaloniaHostUITheme(MainWindow parent)
{ {
FontFamily = OperatingSystem.IsWindows() && OperatingSystem.IsWindowsVersionAtLeast(10, 0, 22000) ? "Segoe UI Variable" : parent.FontFamily.Name; _parent = parent;
// Initialize font property
FontFamily = GetSystemFontFamily();
// Initialize all properties that depend on parent
DefaultBackgroundColor = BrushToThemeColor(parent.Background); DefaultBackgroundColor = BrushToThemeColor(parent.Background);
DefaultForegroundColor = BrushToThemeColor(parent.Foreground); DefaultForegroundColor = BrushToThemeColor(parent.Foreground);
DefaultBorderColor = BrushToThemeColor(parent.BorderBrush); DefaultBorderColor = BrushToThemeColor(parent.BorderBrush);
@@ -17,24 +32,74 @@ namespace Ryujinx.Ava.UI.Applet
SelectionForegroundColor = BrushToThemeColor(parent.ViewControls.SearchBox.SelectionForegroundBrush); SelectionForegroundColor = BrushToThemeColor(parent.ViewControls.SearchBox.SelectionForegroundBrush);
} }
public string FontFamily { get; } private string GetSystemFontFamily()
{
if (OperatingSystem.IsWindows())
{
return GetWindowsFontByLanguage();
}
else if (OperatingSystem.IsMacOS())
{
return GetMacOSFontByLanguage();
}
else // Linux and other platforms
{
return GetLinuxFontByLanguage();
}
}
public ThemeColor DefaultBackgroundColor { get; } private string GetWindowsFontByLanguage()
public ThemeColor DefaultForegroundColor { get; } {
public ThemeColor DefaultBorderColor { get; } var culture = CultureInfo.CurrentUICulture;
public ThemeColor SelectionBackgroundColor { get; } string langCode = culture.Name;
public ThemeColor SelectionForegroundColor { get; }
return culture.TwoLetterISOLanguageName switch
{
"zh" => langCode == "zh-CN" || langCode == "zh-Hans" || langCode == "zh-SG"
? "Microsoft YaHei UI" // Simplified Chinese
: "Microsoft JhengHei UI", // Traditional Chinese
"ja" => "Yu Gothic UI", // Japanese
"ko" => "Malgun Gothic", // Korean
_ => OperatingSystem.IsWindowsVersionAtLeast(10, 0, 22000)
? "Segoe UI Variable" // Other languages - Windows 11+
: _parent.FontFamily.Name // Fallback to parent window font
};
}
private string GetMacOSFontByLanguage()
{
return CultureInfo.CurrentUICulture.TwoLetterISOLanguageName switch
{
"zh" => "PingFang SC", // Chinese (both simplified and traditional)
"ja" => "Hiragino Sans", // Japanese
"ko" => "Apple SD Gothic Neo", // Korean
_ => _parent.FontFamily.Name // Fallback to parent window font
};
}
private string GetLinuxFontByLanguage()
{
return CultureInfo.CurrentUICulture.TwoLetterISOLanguageName switch
{
"zh" => "Noto Sans CJK SC", // Chinese
"ja" => "Noto Sans CJK JP", // Japanese
"ko" => "Noto Sans CJK KR", // Korean
_ => _parent.FontFamily.Name // Fallback to parent window font
};
}
private static ThemeColor BrushToThemeColor(IBrush brush) private static ThemeColor BrushToThemeColor(IBrush brush)
{ {
if (brush is SolidColorBrush solidColor) if (brush is SolidColorBrush solidColor)
{ {
return new ThemeColor((float)solidColor.Color.A / 255, return new ThemeColor(
(float)solidColor.Color.A / 255,
(float)solidColor.Color.R / 255, (float)solidColor.Color.R / 255,
(float)solidColor.Color.G / 255, (float)solidColor.Color.G / 255,
(float)solidColor.Color.B / 255); (float)solidColor.Color.B / 255
);
} }
return new ThemeColor(); return new ThemeColor();
} }
} }