Fonts/zh-cn: Difference between revisions

ZhX589 (talk | contribs)
Created page with "并非所有字体都有 Nerd Fonts 变体,但幸运的是,您可以轻松地自行打补丁。 {{File|3=(pkgs.scientifica.overrideAttrs (o: { nativeBuildInputs = [ pkgs.nerd-font-patcher ]; postInstall = '' mkdir -p $out/share/fonts/truetype/{scientifica,scientifica-nerd} mv $out/share/fonts/truetype/*.ttf $out/share/fonts/truetype/scientifica/ for f in $out/share/fonts/truetype/scientifica/*.ttf; do nerd-font-patcher --complete --outputdir $ou..."
Tags: Mobile edit Mobile web edit
ZhX589 (talk | contribs)
Created page with "=== 在 <code>fonts.fontconfig.defaultFonts.monospace</code> 中可以使用哪些字体名称? ==="
 
(13 intermediate revisions by the same user not shown)
Line 92: Line 92:
}))|name=/etc/nixos/configuration.nix|lang=nix}}
}))|name=/etc/nixos/configuration.nix|lang=nix}}


<span lang="en" dir="ltr" class="mw-content-ltr">=== Let Fontconfig know the fonts within your Nix profile ===</span>
=== Fontconfig 识别 Nix 配置文件中的字体 ===
<div lang="en" dir="ltr" class="mw-content-ltr">
Nix 会将其用户配置文件路径插入到 <code>$XDG_DATA_DIRS</code> 中,而 Fontconfig 默认并不在此路径中查找。这会导致 KDE Plasma 等图形应用程序无法识别通过 <code>nix-env</code> <code>nix profile</code> 安装的字体。
Nix inserts its user profile path into <code>$XDG_DATA_DIRS</code>, which Fontconfig by default doesn't look in. This cause graphical applications like KDE Plasma not able to recognize the fonts installed via <code>nix-env</code> or <code>nix profile</code>.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
要解决此问题,请将 <code>100-nix.conf</code> 文件添加到 Fontconfig 用户配置目录中(通常为 <code>$XDG_CONFIG_HOME/fontconfig/conf.d</code>):
To solve this, add the file <code>100-nix.conf</code> to your Fontconfig user configuration directory (usually <code>$XDG_CONFIG_HOME/fontconfig/conf.d</code>):
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<?xml version="1.0"?>
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
<fontconfig>
<fontconfig>
   <!-- NIX_PROFILE is the path to your Nix profile. See Nix Reference Manual for details. -->
   <!-- NIX_PROFILE 是您的 Nix 配置文件的路径。详见 Nix 参考手册。 -->
   <dir>NIX_PROFILE/lib/X11/fonts</dir>
   <dir>NIX_PROFILE/lib/X11/fonts</dir>
   <dir>NIX_PROFILE/share/fonts</dir>
   <dir>NIX_PROFILE/share/fonts</dir>
</fontconfig>
</fontconfig>
</syntaxhighlight>
</syntaxhighlight>
and run <code>fc-cache</code>.
然后运行 <code>fc-cache</code>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
或者,在您的 Home Manager 配置 <code>opt-fonts.fontconfig.enable</code> 中启用 Fontconfig 配置。
Alternatively, [https://nix-community.github.io/home-manager/options.xhtml#opt-fonts.fontconfig.enable enable Fontconfig configuration] in your Home Manager configuration.
</div>


<span lang="en" dir="ltr" class="mw-content-ltr">=== Imperative installation of user fonts ===</span>
=== 命令式安装用户字体 ===
<span lang="en" dir="ltr" class="mw-content-ltr">This is useful for quick font experiments.</span>
<span lang="en" dir="ltr" class="mw-content-ltr">This is useful for quick font experiments.</span>


Line 158: Line 152:
</div>
</div>


<span lang="en" dir="ltr" class="mw-content-ltr">== Configuring fonts ==</span>
== 配置字体 ==


<div lang="en" dir="ltr" class="mw-content-ltr">
NixOS 的 [https://search.nixos.org/options?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=fonts.fontconfig <code>fonts.fontconfig</code>] 配置项(点击查看完整列表!)用于处理 fontconfig 选项。部分选项已被 nix 很好地封装;此外始终可以使用 <code>localConf</code> 直接编写 XML 配置。
The nixos key [https://search.nixos.org/options?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=fonts.fontconfig <code>fonts.fontconfig</code>] (click to see the full list!) handles the fontconfig options. Some options are nicely wrapped in nix; there's always <code>localConf</code> to go straight to the XML.
</div>


<span lang="en" dir="ltr" class="mw-content-ltr">=== Set multiple fonts for different languages ===</span>
=== 为不同语言设置多种字体 ===
<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
If you want to use other languages alongside English, you may want to set appropriate fonts for each language in your whole OS. For example, a Persian speaker might want to use the
If you want to use other languages alongside English, you may want to set appropriate fonts for each language in your whole OS. For example, a Persian speaker might want to use the
Line 201: Line 193:
</div>
</div>


<span lang="en" dir="ltr" class="mw-content-ltr">=== Use custom font substitutions ===</span>
=== 使用自定义字体替换 ===


<div lang="en" dir="ltr" class="mw-content-ltr">
有时,由于不恰当的替换,文档可能会出现字距不佳或字间距难以阅读的问题。
Sometimes, documents may appear to have bad kerning or hard-to-read letter spacing, due to a bad substitution.
例如,Okular 可能在“文档属性”对话框中显示已将 DejaVu Sans Mono(一种无衬线字体)替换为 "NewCenturySchlbk"。运行 <code>fc-match NewCenturySchlbk</code> 会显示类似信息。
For example, Okular may show in the ''Document Properties'' dialog that it has substituted DejaVu Sans Mono (a sans-serif font) in place of "NewCenturySchlbk". <code>fc-match NewCenturySchlbk</code> would display similiar info.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
将此添加到您的 <code>/etc/nixos/configuration.nix</code> 中,应能促使其改用更相似(且更美观)的衬线字体 ''Schola'' 作为替代:
Adding this to your <code>/etc/nixos/configuration.nix</code> should prompt it to use the more similar (and nicer) serif ''Schola'' font instead:
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
{{File|3=fonts = {
{{File|3=fonts = {
   packages = with pkgs; [ gyre-fonts ];
   packages = with pkgs; [ gyre-fonts ];
Line 225: Line 212:
   };
   };
};|name=/etc/nixos/configuration.nix|lang=nix}}
};|name=/etc/nixos/configuration.nix|lang=nix}}
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
有关 XML 配置语言的更多信息和示例:
For more information and examples on the xml configuration language:
</div>


* https://www.mankier.com/5/fonts-conf
* https://www.mankier.com/5/fonts-conf
Line 235: Line 219:
* https://wiki.archlinux.org/index.php/Font_configuration/Examples
* https://wiki.archlinux.org/index.php/Font_configuration/Examples


<div lang="en" dir="ltr" class="mw-content-ltr">
有关合适的替代字体列表:
For a list of suitable replacement fonts:
</div>
* https://wiki.archlinux.org/title/Metric-compatible_fonts
* https://wiki.archlinux.org/title/Metric-compatible_fonts


<span lang="en" dir="ltr" class="mw-content-ltr">== Troubleshooting ==</span>
== 故障排除 ==


<span lang="en" dir="ltr" class="mw-content-ltr">=== What font names can be used in <code>fonts.fontconfig.defaultFonts.monospace</code>? ===</span>
=== <code>fonts.fontconfig.defaultFonts.monospace</code> 中可以使用哪些字体名称? ===


<span lang="en" dir="ltr" class="mw-content-ltr">Those that fontconfig will understand. This can be queried from a font file using <code>fc-query</code>.</span>
<span lang="en" dir="ltr" class="mw-content-ltr">Those that fontconfig will understand. This can be queried from a font file using <code>fc-query</code>.</span>