在 Windows 看习惯 MacType 渲染之后的字体之后再看 Linux 下的字体总感觉细得发虚,很不习惯。字体的 Semibold 样式看着粗细正好,就想把它设为默认的粗细。搜了搜在 openSUSE 论坛 看到了一个同样需求的人,可是他也没找到解决办法,下面还有人回复说:“Linux 的默认字体都是为 4k 显示器准备的。拥有 4k 显示器你才配使用它…… ”
这真是个悲伤的故事……
edit 2026-02-02: 通过 fontconfig 修改默认字重的方法很麻烦,而且很多程序不吃这个配置,还是修改字体文件最省事。今天问了下 Gemini,他直接抛了个 Python 脚本给我,不得不说有了 AI 之后真是方便好多。修改后的字体最好放在 /usr/share/fonts/ 下,KDE 的字体安装器会装到 /usr/local/share/fonts/ 里,Steam 不认。
from fontTools.ttLib import TTFontdef make_semibold_appear_regular (input_path, output_path ): font = TTFont(input_path) print (f"正在处理: {input_path} " ) if 'OS/2' in font: os2 = font['OS/2' ] print (f" - 修改 usWeightClass: {os2.usWeightClass} -> 400" ) os2.usWeightClass = 400 print (" - 修改 fsSelection 标志为 Regular" ) os2.fsSelection = 0b1000000 if 'head' in font: print (" - 清除 head.macStyle (设为 0)" ) font['head' ].macStyle = 0 if 'name' in font: print (" - 更新 name 表 (ID 1, 2, 4, 6, 16, 17)..." ) for record in font['name' ].names: try : name_str = record.toUnicode() new_str = name_str if record.nameID in [2 , 17 ]: if "SemiBold" in name_str or "Semibold" in name_str: new_str = "Regular" elif name_str == "Bold" : new_str = "Regular" if "SemiBold" in name_str: new_str = name_str.replace("SemiBold" , "Regular" ) elif "Semibold" in name_str: new_str = name_str.replace("Semibold" , "Regular" ) if new_str != name_str: record.string = new_str.encode(record.getEncoding()) print (f" [ID {record.nameID} ] {name_str} -> {new_str} " ) except UnicodeDecodeError: pass font.save(output_path) print (f"完成!已保存为: {output_path} " ) if __name__ == "__main__" : input_font = "SarasaUiSC-SemiBold.ttf" output_font = "SarasaUiSC-Regular.ttf" try : make_semibold_appear_regular(input_font, output_font) except Exception as e: print (f"发生错误: {e} " ) print ("请确保文件名正确,且文件在当前目录下。" )
这个是斜体的:
from fontTools.ttLib import TTFontdef convert_semibold_italic_to_italic (input_path, output_path ): print (f"正在加载字体: {input_path} " ) font = TTFont(input_path) if 'OS/2' in font: os2 = font['OS/2' ] print (f" - 修改 usWeightClass: {os2.usWeightClass} -> 400" ) os2.usWeightClass = 400 original_sel = os2.fsSelection os2.fsSelection = (os2.fsSelection & ~0b100000 ) | 0b1 print (f" - 修改 fsSelection: {original_sel} -> {os2.fsSelection} (清除Bold, 确保Italic)" ) if 'head' in font: head = font['head' ] original_style = head.macStyle head.macStyle = (head.macStyle & ~1 ) | 2 print (f" - 修改 head.macStyle: {original_style} -> {head.macStyle} (清除Bold, 确保Italic)" ) if 'name' in font: print (" - 正在处理名称表 (Name Table)..." ) for record in font['name' ].names: try : name_str = record.toUnicode() original_str = name_str new_str = name_str if record.nameID == 6 : new_str = new_str.replace("SemiBold-Italic" , "Italic" ) new_str = new_str.replace("SemiBold" , "" ) elif record.nameID in [2 , 17 ]: if "SemiBold Italic" in new_str: new_str = "Italic" elif "SemiBold" in new_str: new_str = "Italic" else : if "SemiBold Italic" in new_str: new_str = new_str.replace("SemiBold Italic" , "Italic" ) if "SemiBold" in new_str: new_str = new_str.replace(" SemiBold" , "" ) new_str = new_str.replace("SemiBold" , "" ) new_str = " " .join(new_str.split()) if record.nameID == 6 : new_str = new_str.replace(" " , "" ) if new_str != original_str: record.string = new_str.encode(record.getEncoding()) if record.nameID in [4 , 6 ]: print (f" [ID {record.nameID} ] {original_str} -> {new_str} " ) except UnicodeDecodeError: pass font.save(output_path) print ("-" * 30 ) print (f"成功!文件已保存至: {output_path} " ) print ("提示:安装前请先卸载旧的 'Sarasa UI SC Italic' (如果存在),并重启相关软件。" ) if __name__ == "__main__" : input_file = "SarasaUiSC-SemiBoldItalic.ttf" output_file = "SarasaUiSC-Italic.ttf" try : convert_semibold_italic_to_italic(input_file, output_file) except Exception as e: print (f"发生错误: {e} " )
** 以下是旧内容,现在不需要了。 **
后来自己慢慢摸索到一个勉强能用的办法,就是在 fontconfig scan 的时候,把 Semibold 的字体的 fullname style weight 都换成 Regular 的,再把 Regular 的换成 Light 的,Light 的 的再换成 EXLight 的或者直接删掉。这样一般的程序默认的字重就是 Semibold 了。
获取字体文件 fullname 和 weight :
❯ fc-query --format="%{fullname} %{weight}\\n" /usr/local/share/fonts/s/sarasa_term_sc_nerd_regular.ttf Sarasa Term SC Nerd Regular,终端更纱黑体-简 Nerd Regular 80 ❯ fc-query --format="%{fullname} %{weight}\\n" /usr/local/share/fonts/s/sarasa_term_sc_nerd_semibold.ttf Sarasa Term SC Nerd Semibold,终端更纱黑体-简 Nerd Semibold 180
fontconfig 配置:
<match target ="scan" > <test name ="fullname" > <string > Sarasa Term SC Nerd Regular</string > </test > <edit name ="fullname" > <string > Sarasa Term SC Nerd Light</string > </edit > <edit name ="style" > <string > Light</string > </edit > <edit name ="weight" > <int > 50</int > </edit > </match > <match target ="scan" > <test name ="fullname" > <string > Sarasa Term SC Nerd Semibold</string > </test > <edit name ="fullname" > <string > Sarasa Term SC Nerd Regular</string > </edit > <edit name ="style" > <string > Regular</string > </edit > <edit name ="weight" > <int > 80</int > </edit > </match >
改完 fc-cache -f 就可以了,但 Telegram 不吃系统的 fontconfig,主要就是他的字体不好看,那就只能改用 telegram-desktop-userfonts 了。
Chromium 系及 Electron 的应用还是会默认使用 Regular ,这点在这个回答 中找到了解决办法。
<match target ="pattern" > <test compare ="eq" name ="family" > <string > Sarasa Term SC Nerd</string > </test > <edit mode ="prepend" name ="style" > <string > Semibold</string > </edit > </match >
但是自带字体的网页或 Electron 应用就没办法了,只能继续用 fontconfig 改字重/替换字体或是直接修改 CSS。比如 Discord 就可以用 BeautifulDiscord 修改 CSS。
discord-custom.css :root :lang (zh-CN) { --font-primary : "Sarasa UI SC" , "Noto Color Emoji" , sans-serif !important ; --font-display : "Sarasa UI SC" , "Noto Color Emoji" , sans-serif !important ; --font-headline : "Sarasa UI SC" , "Noto Color Emoji" sans-serif !important ; --font-code : "Sarasa Term SC Nerd" , "Noto Color Emoji" , monospace !important ; }
下面是我的配置,用的是 Sarasa UI SC 和 Sarasa Term SC Nerd。
~/.config/fontconfig/conf.d/20-replace-regular.conf <?xml version="1.0" ?> <!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd" > <fontconfig > <match target ="scan" > <test name ="fullname" > <string > Sarasa Term SC Nerd Regular</string > </test > <edit name ="fullname" > <string > Sarasa Term SC Nerd Light</string > </edit > <edit name ="style" > <string > Light</string > </edit > <edit name ="weight" > <int > 50</int > </edit > </match > <match target ="scan" > <test name ="fullname" > <string > Sarasa Term SC Nerd Semibold</string > </test > <edit name ="fullname" > <string > Sarasa Term SC Nerd Regular</string > </edit > <edit name ="style" > <string > Regular</string > </edit > <edit name ="weight" > <int > 80</int > </edit > </match > <match target ="scan" > <test name ="fullname" > <string > Sarasa UI SC</string > </test > <edit name ="fullname" > <string > Sarasa UI SC Light</string > </edit > <edit name ="style" > <string > Light</string > </edit > <edit name ="weight" > <int > 50</int > </edit > </match > <match target ="scan" > <test name ="fullname" > <string > Sarasa UI SC Semibold</string > </test > <edit name ="fullname" > <string > Sarasa UI SC</string > </edit > <edit name ="style" > <string > Regular</string > </edit > <edit name ="weight" > <int > 80</int > </edit > </match > <match target ="pattern" > <test compare ="eq" name ="family" > <string > Sarasa UI SC</string > </test > <edit mode ="prepend" name ="style" > <string > Semibold</string > </edit > </match > <match target ="pattern" > <test compare ="eq" name ="family" > <string > Sarasa Term SC Nerd</string > </test > <edit mode ="prepend" name ="style" > <string > Semibold</string > </edit > </match > </fontconfig >
对了,还要在 fonts.conf 里面把 hinting 关掉。
~/.config/fontconfig/fonts.conf <match target ="font" > <edit mode ="assign" name ="hinting" > <bool > false</bool > </edit > </match > <match target ="font" > <edit mode ="assign" name ="hintstyle" > <const > hintnone</const > </edit > </match >
参考链接:
https://forum.suse.org.cn/t/c/14990
https://unix.stackexchange.com/a/685529
https://www.freedesktop.org/software/fontconfig/fontconfig-user.html