Steam cant display asian fonts

Steam cannot display Asian fonts

I’m certain that I checked the relevant issues on GitHub, but the problem has not been resolved.

My configuration is:

# configuration.nix

  i18n.defaultLocale = "zh_CN.UTF-8";

  i18n.inputMethod = {
    type   = "fcitx5";
    enable = true;
    fcitx5 = {
      waylandFrontend = true;
      addons = with pkgs; [
        qt6Packages.fcitx5-chinese-addons
      ];
    };
  };
  
  
  fonts = {
    packages = with pkgs; [
      noto-fonts-color-emoji
      noto-fonts-cjk-sans
      noto-fonts-cjk-serif
      wqy_zenhei
    ];
    
    fontconfig.cache32Bit = true;
    
    fontconfig.defaultFonts = {
      emoji     = [ "Noto Color Emoji" ];
      monospace = [
        "Noto Sans Mono CJK SC"
        "Sarasa Mono SC"
        "DejaVu Sans Mono"
      ];
      sansSerif = [
        "Noto Sans CJK SC"
        "Source Han Sans SC"
        "DejaVu Sans"
      ];
      serif     = [
        "Noto Serif CJK SC"
        "Source Han Serif SC"
        "DejaVu Serif"
      ];
    };
  };
  
  environment.systemPackages = with pkgs; [
    git
    home-manager
    vim
    firefox
  ];
  
  programs.steam = {
    enable = true;
    remotePlay.openFirewall = true;
    dedicatedServer.openFirewall = true;
    fontPackages  = with pkgs; [ noto-fonts-cjk-sans ];
    extraPackages = with pkgs; [ noto-fonts-cjk-sans ];
  };

Then I installed Steam in the “home.nix”.

  home.packages = with pkgs; [
    steam
    steam-run
  ];

However, Asian fonts still cannot be displayed, like this:

Have I done something wrong? What should I do now?

i think you forgot to add them to your steam and/or system..?

  programs.steam.fontPackages = with pkgs; [
    noto-fonts-cjk-sans
    noto-fonts-cjk-serif
    wqy_zenhei
  ];

and i usually reboot if im changing fonts, because they need to update their cache (also try using fc-cache?)…

but if you want wqy_zenhei to be used (or seen) on your system (in other apps),

look up font’s name via fc-list | grep -i "fontname", like "zenhei" (you can also use GUI font viewer apps, because font packages usually come with multiple typefaces / font families…)

/nix/store/.../share/fonts/wqy-zenhei.ttc: WenQuanYi Zen Hei Mono,文泉驛等寬正黑,文泉驿等宽正黑:style=Regular
/nix/store/.../share/fonts/wqy-zenhei.ttc: WenQuanYi Zen Hei Sharp,文泉驛點陣正黑,文泉驿点阵正黑:style=Regular
/nix/store/.../share/fonts/wqy-zenhei.ttc: WenQuanYi Zen Hei,文泉驛正黑,文泉驿正黑:style=Regular

you only need the middle part (but you can also specify "WenQuanYi Zen Hei Mono" if you want it to be monospaced) - add it as a “string”

  fonts.fontDir.enable = true; # optional X11 paths for steam
  fonts.defaultFonts.serif = [
    "Noto Serif CJK SC"
    "Source Han Serif SC"
    "DejaVu Serif"
    "WenQuanYi Zen Hei" # this
  ];
  fonts.defaultFonts.sansSerif = [
    "Noto Sans CJK SC"
    "Source Han Sans SC"
    "DejaVu Sans"
    "WenQuanYi Zen Hei" # this
  ];

(afaik) this makes apps try to find fonts from top to bottom, in descending order, so the first one has the highest priority!

for example, i use a zpix-pixel-font pixelated bitmap CJK font and its name is just "Zpix" (EDIT: i found ark-pixel-font to be better, because zpix is very heavy on rendering, apparently???), but it only has chinese and japanese characters, no latin, so make sure you have other fallback fonts, otherwise they will be rendered as empty squares..! but i think noto and han fonts should cover them all, including latin ones..? and yeah, steam comes preinstalled with some font families that you cant easily change (especially latin typefaces, in fact, i found that you cant change any GUI fonts if they are baked in!), so i dont know if its actually a more tricky situation here or not… like, i can change their hinting and aliasing, but not actual font families, yeah…

…also, isnt "SC" small CAPS? i wonder if steam supports this font variant..? you could try without the "SC" part, maybe..? edit: ohh. stupid brain. its not what i thought it is… sorry :sob: its just that i was messing with CSS recently and many fonts didnt support small-caps, so everything was broken and stuff…

1 Like

No, it’s not. “Simplified Chinese”.

No, because the default value already includes those…

2 Likes

根据你的配置,我假设你在用中文,所以我直接说中文了。

简短说明:
直接删掉这一段

  home.packages = with pkgs; [
    steam
    steam-run
  ];

nixos模块已经自动安装steam和steam-run了,重复在home-manager里面安装这两个包只会导致正确的包被不含字体的包覆盖。

详细一点的解释是这样的:
这是steam模块的其中一段:

        steam.override (
          prev:
          {
            extraEnv =
              (lib.optionalAttrs (cfg.extraCompatPackages != [ ]) {
                STEAM_EXTRA_COMPAT_TOOLS_PATHS = extraCompatPaths;
              })
              // (lib.optionalAttrs cfg.extest.enable {
                LD_PRELOAD = "${pkgs.pkgsi686Linux.extest}/lib/libextest.so";
              })
              // (prev.extraEnv or { });
            extraLibraries =
              pkgs:
              let
                prevLibs = if prev ? extraLibraries then prev.extraLibraries pkgs else [ ];
                additionalLibs =
                  with config.hardware.graphics;
                  if pkgs.stdenv.hostPlatform.is64bit then
                    [ package ] ++ extraPackages
                  else
                    [ package32 ] ++ extraPackages32;
              in
              prevLibs ++ additionalLibs;
            extraPkgs = p: (cfg.extraPackages ++ lib.optionals (prev ? extraPkgs) (prev.extraPkgs p));
          }
          // lib.optionalAttrs (cfg.gamescopeSession.enable && gamescopeCfg.capSysNice) {
            buildFHSEnv = pkgs.buildFHSEnv.override {
              # use the setuid wrapped bubblewrap
              bubblewrap = "${config.security.wrapperDir}/..";
            };
          }

看不懂没关系,这一段的意思就是把programs.steam.选项里面的定义的选项通过override添加到steam包里面,也就是说实际上就是安装了一个修改过的steam包。

# 实际上起作用的只有这个
    environment.systemPackages = [
      cfg.package
      cfg.package.run
    ]

这种情况下你再安装一个没有添加字体的steam包,那么正确的包就被覆盖了。

2 Likes

原来是这样子。

抱歉,我没有理解清楚 configuration.nix 和 home manager 的关系,home.nix 里安装好后,发现没有字体,我就到 configuration.nix 里捣鼓了。

谢谢你,问题解决了,是我的问题!

1 Like

It’s okay. Thank you for your effort!

1 Like

抱歉, 我有另外的 提问, 我搜索了很多网页,包括但不限于此网页。 基本都聚焦于steam 客户端的 中文显示。 我是客户端正常,但是游戏 中 的中文缺失。 您有什么方式帮助定位问题吗?

比如这一款游戏, 中间两个 我猜测 一个是简体中文,一个是繁体中文。

这是切换后的景象

客户端正常截图

具体游戏的问题应该问游戏开发者,这游戏我没玩过,可能帮不上忙。另外我建议你开个新贴,这样更符合论坛规范,并且看到的人也更多。

1 Like

这个应该是proton版本的问题,具体情况我也不太清楚,但应该是旧proton环境中查找字体的机制和nix管理不兼容。可以在游戏的管理页面切换使用的proton到最新的experimental版试下,我有个游戏内中文显示就是这么解决的。

1 Like

出于这个目的

具体游戏的问题应该问游戏开发者,这游戏我没玩过,可能帮不上忙。另外我建议你开个新贴,这样更符合论坛规范,并且看到的人也更多。

介意 回复这个吗? 因为 我不知道怎么 ‘在论坛上转载某一个回复, 并选为解决方案’ Steam 游戏 中文字体显示 (游戏内字体,而非 Steam UI)

我觉得 这个回答就是 “终结” , 剩下的是我自己的好奇, 无所谓有没有 仁兄解答了。