【问题标题】:Emacs not listing semilight fonts?Emacs 没有列出半轻字体?
【发布时间】:2021-08-05 20:33:06
【问题描述】:

我想使用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 的这些字体吗?如果是这样,有什么想法为什么没有发生?


环境:

  • GNU Emacs 27.2 (build 1, x86_64-redhat-linux-gnu, GTK+ Version 3.24.29, cairo 版本 1.17.4) 的 2021-04-27
  • Fedora 34

【问题讨论】:

    标签: fonts emacs


    【解决方案1】:

    在深入了解fontconfig 对 OTF 文件所做的工作以及 emacs 如何解析fontconfig 给出的字体权重之后,我找到了真正的罪魁祸首。

    这可能是 emacs 中的一个错误。这是因为通过比较fontconfig spechow emacs understands font-weights,有一些不同之处。值得注意的是,其中之一涉及semilight font-weight。

    解决它的一种方法是使用fontforge,并将 OTF 字体粗细更改为 emacs 可以理解的内容。所以,例如:

    1. Cascadia Code SemiLight.otf 的 OTF 字体粗细从 350(fontconfig's semilight)更改为 380(fontconfig's book)
    2. fontconfig 将根据 their table 将该值转换为 FC_WEIGHT_BOOK (75)
    3. emacs 将显示为半光

    【讨论】:

      【解决方案2】:

      更改字体文件有点过于繁琐,而且无法维护,因为 Cascadia 相当新,而且经常发布。

      可以在缓存重建期间将 semilight 权重值 (55) 替换为 book (75),这使得 Emacs 在将 'semi-light 分配为脸。不幸的是,这个技巧只能通过缓存的字体描述来实现。 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>
      

      或者得到它lock, stock and barrel from this Gist

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-06
        • 2012-03-16
        • 2012-12-12
        • 2012-02-03
        • 1970-01-01
        相关资源
        最近更新 更多