microsoft / cascadia-code

This is a fun, new monospaced font that includes programming ligatures and is designed to enhance the modern look and feel of the Windows Terminal.
Other
25.16k stars 797 forks source link

Normal Weight Cascadia Code Does Not Work in Linux Emacs #589

Closed drcxd closed 2 years ago

drcxd commented 2 years ago

Cascadia family version

2108.03

Cascadia family variant(s)

Cascadia Code (the version with ligatures)

Font file format(s)

.ttf (variable)

Platform

Windows Subsystem for Linux 2, kali-linux

Other Software

GNU Emacs 27.2(x86_64-pc-linux-gnu, GTK+ Version 3.24.24)

What happened?

It looks like Emacs in Linux cannot use normal weight Cascadia Code.

My Emacs configuration about fonts:

(add-to-list 'default-frame-alist '(font . "Cascadia Code-18"))

After I launch Emacs, I found that the font actually takes effect is

xfthb:-SAJA-Cascadia Code-light-normal-normal-*-24-*-*-*-m-0-iso10646-1 (#xE1)

image

The light indicates the weight of the font. I tried to manually set the weight as normal, but it does not work:

(add-to-list 'default-frame-alist '(font . "Cascadia Code-18:weight=Normal"))
;; an alternative, it does not work as well
;; (add-to-list 'default-frame-alist '(font . "Cascadia Code-18:weight=normal"))

Using the font manager, I can see that the normal weight Cascadia Code is installed and could be displayed correctly.

image

Another thing worth mentioning is that by executing the Emacs command/function set-frame-font, Emacs will prompt candidates fonts. I can see that there is a font named ...Cascadia-Mono-normal-normal-normal... but there is no Cascadia Code correspondence, and if I set the normal weight Cascadia Mono font, I can tell the weight is correct (normal rather than light).

image

Now the font taking effect is

xfthb:-SAJA-Cascadia Mono-normal-normal-normal-*-24-*-*-*-m-0-iso10646-1 (#x120)
aaronbell commented 2 years ago

It is odd that the Mono version works and the regular one does not as they are practically the same file.

Out of interest, did you previously install a version of Cascadia Code on the system? Sometimes when you upgrade your font, there can be a cache-related issue wherein the OS struggles to locate the new version. If so, I'd suggest removing the font, clearing all font caches, and then re-installing.

drcxd commented 2 years ago

I install Cascadia Code by placing the .ttf files in ~/.local/share/fonts, then I execute fc-cache -fv.

I uninstall it by removing the .ttf files from ~/.local/share/fonts and execute fc-cache -fv. Does this process clear all font caches?

aaronbell commented 2 years ago

Unfortunately I cannot advice on that as I'm unfamiliar with linux, and the distro that you use. I trust you can investigate? :)

efermi commented 2 years ago

I tried to reproduce the bug and can confirm an issue, although in my case it's the Mono font that's missing the normal-normal-normal variant and Emacs picks normal-italic-normal instead. I can also see a similar issue with the variable version of the Roboto Mono font. As I understand it Emacs has its own font handling parts so the issue could lie with the program itself. Screenshot_20211031_212138

drcxd commented 2 years ago

I tried to reproduce the bug and can confirm an issue, although in my case it's the Mono font that's missing the normal-normal-normal variant and Emacs picks normal-italic-normal instead. I can also see a similar issue with the variable version of the Roboto Mono font. As I understand it Emacs has its own font handling parts so the issue could lie with the program itself. Screenshot_20211031_212138

Thanks for youre help, I'll investigate further.

ndegruchy commented 2 years ago

I was having this problem on Debian 11, with Emacs 27.1.

It turns out that I had installed the variable fonts, instead of the static ones. KDE seemed find with the variable ones, but Emacs did not. Installing the static ones worked out for me.

Still not sure where the root cause lies, but this got me working.

drcxd commented 2 years ago

Recently I found that Emacs 29 could recognize the variable fonts correctly. With Emacs 28, I still need to use the static ones.