Skip to content

Conversation

@xujiegb
Copy link
Contributor

@xujiegb xujiegb commented Nov 18, 2025

内容

此PR旨在改进部分Linux发行版的字体兼容性

已知缺陷

此次修改未涉及这些问题

1、此方案在部分配置换乱、字体劫持的发行版中无效

需要和对应发行版取得支持
或者Linux版打包字体文件,强制指定字体(可能会增加打包占用空间)

2、在采用COLRv1字体的发行版中,无法显示Emoji

Fedora 43 用户需要降级字体包

sudo dnf install */NotoColorEmoji.ttf --releasever=42

需要等上游将渲染器完全适配COLRv1字体
或者Linux版打包字体文件,强制指定字体(可能会增加打包占用空间)

3、用户在安装个人字体后会导致字体默认选择行为出错
用户可以指定显示的字体

4、更改字体后,部分区域的字体将不会改变

测试通过系统

Red Hat Enterprise Linux 10
截屏2025-11-18 21 29 59
Rocky Linux 10
截屏2025-11-18 21 28 58
Rocky Linux 10
截屏2025-11-18 21 30 51
AlmaLinux 10
截屏2025-11-18 21 29 38
Fedora Linux 43
截屏2025-11-18 21 34 32
Elementary OS 8
截屏2025-11-18 21 31 17
Debian Linux 12
截屏2025-11-18 21 36 33
Debian Linux 13
截屏2025-11-18 21 26 49
Ubuntu Linux 25.10
截屏2025-11-18 21 38 58
Manjaro Linux
截屏2025-11-18 21 28 38

@2dust
Copy link
Owner

2dust commented Nov 18, 2025

如果这个代码没有用,是否可以利用这个设置起来,在启动的时候应用这个用户设置的字体,而不是调用命令获取后再应用。
并不是所有的 Linux 用户都需要使用 emoji 的,所以只给设置了字体的用户启用更好

@xujiegb
Copy link
Contributor Author

xujiegb commented Nov 18, 2025

如果这个代码没有用,是否可以利用这个设置起来,在启动的时候应用这个用户设置的字体,而不是调用命令获取后再应用。 并不是所有的 Linux 用户都需要使用 emoji 的,所以只给设置了字体的用户启用更好

确实,多跑一个进程不太好

@xujiegb
Copy link
Contributor Author

xujiegb commented Nov 18, 2025

@fujiwarabach Most Linux distributions seem to use only the noto sans emoji. We can either let v2rayN use it, or fallback if it doesn't support it.

@2dust
Copy link
Owner

2dust commented Nov 18, 2025

 public static AppBuilder WithFontByDefault(this AppBuilder appBuilder)
 {
     var notoSansSc = new FontFamily(Path.Combine(Global.AvaAssets, "Fonts#Noto Sans SC"));

     var fallbacks = new List<FontFallback>
     {
         new() { FontFamily = notoSansSc }
     };

     if (OperatingSystem.IsLinux())
     {
         if (AppManager.Instance.Config.UiItem.CurrentFontFamily.IsNotEmpty())
         {
             fallbacks.Add(new FontFallback
             {
                 FontFamily = new FontFamily(AppManager.Instance.Config.UiItem.CurrentFontFamily)
             });
         }
     }

     return appBuilder.With(new FontManagerOptions
     {
         FontFallbacks = fallbacks.ToArray()
     });
 }

以上代码没有测试过,只是可以使用这样的方式尝试是否可以?

@2dust
Copy link
Owner

2dust commented Nov 18, 2025

public static AppBuilder BuildAvaloniaApp()
{
    var builder = AppBuilder.Configure<App>()
       .UsePlatformDetect()
       //.WithInterFont()
       //.WithFontByDefault()
       .LogToTrace()
       .UseReactiveUI();

    if (OperatingSystem.IsLinux()
        && AppManager.Instance.Config.UiItem.CurrentFontFamily.IsNotEmpty())
    {
        builder = builder.WithFontByLinux();
    }
    else
    {
        builder = builder.WithFontByDefault();
    }

    if (OperatingSystem.IsMacOS())
    {
        var showInDock = Design.IsDesignMode || AppManager.Instance.Config.UiItem.MacOSShowInDock;
        builder = builder.With(new MacOSPlatformOptions { ShowInDock = showInDock });
    }

    return builder;
}

或者用这样的方式,增加一个 WithFontByLinux()

@fujiwarabach
Copy link

@xujiegb @2dust Let’s still add the condition — it’s much better than using a command.

@xujiegb
Copy link
Contributor Author

xujiegb commented Nov 18, 2025

@xujiegb @2dust Let’s still add the condition — it’s much better than using a command.

It has been updated. Please test it.

@xujiegb
Copy link
Contributor Author

xujiegb commented Nov 18, 2025

以上代码没有测试过,只是可以使用这样的方式尝试是否可以?

@2dust 增加命令检测不是我们的本意,只是希望更能精准的抓到字体,刚刚调查了一下几个主流发行版,几乎都用同一个,考虑很久,认为直接兜底即可。
Ubuntu server、Rocky base 安装gnome-desktop会附加字体包

@xujiegb
Copy link
Contributor Author

xujiegb commented Nov 18, 2025

截屏2025-11-18 21 42 37
不影响更改字体的情况下可以显示emoji

@fujiwarabach
Copy link

Well:

Fedora Linux 10
Red Hat Enterprise Linux 10
Rocky Linux 10
AlmaLinux 10
Ubuntu Linux 24.04 | 25.10
Debian Linux 12 | 13
Elementary OS 8

Issue:

OpenSUSE Leap 16

@xujiegb
Copy link
Contributor Author

xujiegb commented Nov 18, 2025

Well:

Fedora Linux 10
Red Hat Enterprise Linux 10
Rocky Linux 10
AlmaLinux 10
Ubuntu Linux 24.04 | 25.10
Debian Linux 12 | 13
Elementary OS 8

Issue:

OpenSUSE Leap 16

This looks good.

@fujiwarabach
Copy link

@xujiegb Yeah, that means most people can get their problems solved.

@xujiegb xujiegb closed this Nov 18, 2025
@xujiegb xujiegb reopened this Nov 18, 2025
@alphonca99
Copy link

@xujiegb I saw Firefox calling fontconfig to handle this.

@xujiegb
Copy link
Contributor Author

xujiegb commented Nov 19, 2025

@xujiegb I saw Firefox calling fontconfig to handle this.

Using libfontconfig would probably be even more troublesome.

@xujiegb
Copy link
Contributor Author

xujiegb commented Nov 19, 2025

@fujiwarabach @alphonca99 The current modification seems fine. Have you found any problems?
@2dust 如果没有问题,请考虑一下

@2dust 2dust merged commit 054efeb into 2dust:master Nov 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants