fix: use the correct font family for CJK characters

See merge request ryubing/ryujinx!52
This commit is contained in:
rockingdice 2025-06-10 15:41:39 -05:00 committed by GreemDev
parent eed6ef632d
commit b97fae08b5

View File

@ -2,29 +2,104 @@ 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(MainWindow parent) : IHostUITheme class AvaloniaHostUITheme : IHostUITheme
{ {
public string FontFamily { get; } = OperatingSystem.IsWindows() && OperatingSystem.IsWindowsVersionAtLeast(10, 0, 22000) ? "Segoe UI Variable" : parent.FontFamily.Name; private readonly MainWindow _parent;
public ThemeColor DefaultBackgroundColor { get; } = BrushToThemeColor(parent.Background); public string FontFamily { get; }
public ThemeColor DefaultForegroundColor { get; } = BrushToThemeColor(parent.Foreground); public ThemeColor DefaultBackgroundColor { get; }
public ThemeColor DefaultBorderColor { get; } = BrushToThemeColor(parent.BorderBrush); public ThemeColor DefaultForegroundColor { get; }
public ThemeColor SelectionBackgroundColor { get; } = BrushToThemeColor(parent.ViewControls.SearchBox.SelectionBrush); public ThemeColor DefaultBorderColor { get; }
public ThemeColor SelectionForegroundColor { get; } = BrushToThemeColor(parent.ViewControls.SearchBox.SelectionForegroundBrush); public ThemeColor SelectionBackgroundColor { get; }
public ThemeColor SelectionForegroundColor { get; }
public AvaloniaHostUITheme(MainWindow parent)
{
_parent = parent;
// Initialize font property
FontFamily = GetSystemFontFamily();
// Initialize all properties that depend on parent
DefaultBackgroundColor = BrushToThemeColor(parent.Background);
DefaultForegroundColor = BrushToThemeColor(parent.Foreground);
DefaultBorderColor = BrushToThemeColor(parent.BorderBrush);
SelectionBackgroundColor = BrushToThemeColor(parent.ViewControls.SearchBox.SelectionBrush);
SelectionForegroundColor = BrushToThemeColor(parent.ViewControls.SearchBox.SelectionForegroundBrush);
}
private string GetSystemFontFamily()
{
if (OperatingSystem.IsWindows())
{
return GetWindowsFontByLanguage();
}
else if (OperatingSystem.IsMacOS())
{
return GetMacOSFontByLanguage();
}
else // Linux and other platforms
{
return GetLinuxFontByLanguage();
}
}
private string GetWindowsFontByLanguage()
{
var culture = CultureInfo.CurrentUICulture;
string langCode = culture.Name;
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();
} }
} }