我想使用
semilight
字体。但是,由于某种原因,emacs 没有列出 semilight
字体。我错过了什么吗?
在我的
init.el
中,我有以下内容:
(set-face-attribute 'default nil :family "Cascadia Code" :weight 'semilight)
但是,当在任何角色上运行
describe-char
时,我发现它正在使用 -SAJA-Cascadia Code-light-normal-normal-*-13-*-*-*-m-0-iso10646-1
,结果来自 CascadiaCode-Regular.otf。
我试图找到发生这种情况的主要原因:
当我运行
describe-font
时,我似乎在系统中找不到任何semilight
字体(即weight=55
)。唯一显示为 semilight
的字体是粗细为 75 的字体。
运行
x-select-font
会列出 semilight
字体。
我不太确定这里发生了什么。 emacs 不应该显示这些带有
weight=55
的字体吗?如果是这样,有想过为什么没有发生吗?
环境:
更改字体文件有点过于繁琐,而且难以维护,因为 Cascadia 相当新,而且经常发布。
可以在缓存重建期间将
semilight
权重值 (55) 替换为 book
(75),这使得当 'semi-light
被指定为面的 :weight
属性时,Emacs 可以愉快地显示 Cascadia SemiLight 变体。不幸的是,这个技巧只能通过缓存的字体描述来实现。 Fontconfig 很深奥。
将此配置文件放入
fc-cache
扫描的位置:每个用户,或所有用户的 /etc/fonts/conf.d
中(通常;fc-conflist
将告诉它正在查找哪些目录;文件 50-user.conf
通常包含 .conf
)
主目录中的文件)。影响缓存扫描的文件通常以 80 到 89 范围内的数字作为前缀。我将此文件设置为 /etc/fonts/conf.d/80-cascadia-semilight.conf
;您可能有自己的喜好。
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<description>Adjust weight of Cascadia fonts for Emacs</description>
<match target="scan">
<test target="font" name="family" ignore-blanks="true">
<string>Cascadia Mono</string>
</test>
<test target="font" name="weight">
<const>semilight</const>
</test>
<edit name="weight">
<const>book</const>
</edit>
</match>
<!-- Repeat the same match stanza for the other three fonts,
Cascadia Mono PL, Cascadia Code and Cascadia Code PL. -->
</fontconfig>
或者从这个要点获取它锁、枪托和枪管。
深入了解
fontconfig
对 OTF 文件做了什么,以及 Emacs 如何解析 fontconfig
给出的字体粗细后,我找到了真正的罪魁祸首。
fontconfig
spec 和 Emacs 如何理解字体粗细,可以发现一些差异。值得注意的是,其中之一涉及 semilight
字体粗细。
解决这个问题的一种方法是使用
fontforge
,并将 OTF 字体粗细更改为 Emacs 可以理解的内容。因此,例如:
fontconfig
的半亮)更改为 380(fontconfig
的书)fontconfig
将根据 他们的表将该值转换为 FC_WEIGHT_BOOK
(75)