Search code examples
fontsemacs

Emacs not listing semilight fonts?


I wanted to use a semilight font. But, for some reason, emacs is not listing semilight fonts. Am I missing anything?

In my init.el, I have the following:

(set-face-attribute 'default nil :family "Cascadia Code" :weight 'semilight)

However, when running describe-char on any character, I get that it's using -SAJA-Cascadia Code-light-normal-normal-*-13-*-*-*-m-0-iso10646-1, which turns out to be from CascadiaCode-Regular.otf.

I tried to find the main reason why it was happening:

  • When I run describe-font, I can't seem to find any of the semilight fonts in my system (i.e. weight=55). The only font that shows up as semilight is a font whose weight is 75.

  • Running x-select-font lists the semilight fonts.

I'm not really sure what is happening here. Shouldn't emacs show these fonts whose weight=55? If so, any thought on why that isn't happening?


Environment:

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

Solution

  • Changing the font files is a bit too heavy-handed, and unmaintainable, as Cascadia is fairly new, and is released often.

    It is possible to substitute semilight weight value (55) to book (75) during cache rebuild, which makes Emacs happily display the Cascadia SemiLight variants when 'semi-light is assigned as the :weight property of a face. Unfortunately, this trick can be pulled only with a cached font description. Fontconfig is esoteric.

    Place this config file into a location that is scanned by fc-cache: per-user, or into /etc/fonts/conf.d for all users (usually; fc-conflist will tell which directories it's looking into; file 50-user.conf normally includes .conf files from home directories). The files that affect cache scan customarily prefixed with a number in the range 80 to 89. I have this file as /etc/fonts/conf.d/80-cascadia-semilight.conf; you may have your own preferences.

    <?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>
    

    Or get it lock, stock and barrel from this Gist.