Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sarasa Term fonts do not work with kitty terminal emulator on Linux #192

Closed
terrywang opened this issue Oct 12, 2020 · 7 comments
Closed

Comments

@terrywang
Copy link

A bit of background can be found here kovidgoyal/kitty#3021

TL;DR

Iosevka has spacing values for its Term variants. Sarasa Gothic fonts (ttc and ttf) does not.

Problem

kitty on macOS somehow works fine with Sarasa Gothic (Term SC in my case).

kitty list-fonts show the fonts correctly, so does font fallback

$  kitty --version
kitty 0.19.1 created by Kovid Goyal
$  kitty --debug-font-fallback
[285 23:32:57.485745] Preloaded font faces:
[285 23:32:57.485804] normal face: /Users/terry.wang/Library/Fonts/sarasa-regular.ttc
[285 23:32:57.485818] bold face: /Users/terry.wang/Library/Fonts/sarasa-semibold.ttc
[285 23:32:57.485833] italic face: /Users/terry.wang/Library/Fonts/sarasa-italic.ttc
[285 23:32:57.485847] bi face: /Users/terry.wang/Library/Fonts/sarasa-semibolditalic.ttc

`fc-list` output
```bash
/Users/terry.wang/Library/Fonts/sarasa-regular.ttc: Sarasa Term SC:style=Regular:outline=True:scalable=True

However, kitty on Linux does not work with the same font (TTC or specific TTF file).

kitty list-fonts does not show

fc-list output

# sarasa
/home/terry/.fonts/sarasa-term-sc-regular.ttf: Sarasa Term SC:style=Regular:outline=True:scalable=True

# compare with iosevka
Iosevka Term,Iosevka Term Medium:spacing=90:outline=True:scalable=True

fc-scan --format "%{postscriptname}\n" ~/.fonts/*.ttf
Sarasa-Term-SC-Regular

OS info

/terry@manjaro:~$  kitty --debug-config
kitty 0.19.1 created by Kovid Goyal
Linux manjaro 5.8.11-1-MANJARO #1 SMP PREEMPT Wed Sep 23 14:35:40 UTC 2020 x86_64
Manjaro Linux \r  (\n) (\l)
DISTRIB_ID=ManjaroLinux
DISTRIB_RELEASE=20.1.1
DISTRIB_CODENAME=Mikah
DISTRIB_DESCRIPTION="Manjaro Linux"
Loaded config files: /home/terry/.config/kitty/kitty.conf
Running under: X11

Config options different from defaults:
background           Color(red=44, green=44, blue=44)
color1               Color(red=241, green=119, blue=121)
color10              Color(red=153, green=204, blue=153)
color11              Color(red=255, green=204, blue=102)
color12              Color(red=102, green=153, blue=204)
color13              Color(red=204, green=153, blue=204)
color14              Color(red=102, green=204, blue=204)
color15              Color(red=255, green=254, blue=254)
color2               Color(red=153, green=204, blue=153)
color3               Color(red=255, green=204, blue=102)
color4               Color(red=102, green=153, blue=204)
color5               Color(red=204, green=153, blue=204)
color6               Color(red=102, green=204, blue=204)
color7               Color(red=255, green=254, blue=254)
color8               Color(red=0, green=0, blue=0)
color9               Color(red=241, green=119, blue=121)
font_family          Sarasa Term SC Regular
foreground           Color(red=204, green=204, blue=204)
selection_background Color(red=80, green=80, blue=80)
selection_foreground Color(red=44, green=44, blue=44)

Workaround

Recommended by kitty FAQ

Tried to override (both add in ~/.config/fontconfig/fonts.conf and a separate config file in conf.d ) and force cache rebuild via fc-cache -rv but still kitty list-fonts does not show the font

I am no fongconfig expert so don't laugh if I did it wrong (font family string may be wrong...).

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match target="font">
    <test name="family">
        <string>Sarasa-Term-SC-Regular</string>
    </test>
    <edit name="spacing">
        <int>100</int>
    </edit>
</match>
</fontconfig>

My ask: what is the easiest (at the best cost, scalable, others can easily adopt) way to get Sarasa Gothic working with kitty on Linux?

@be5invis
Copy link
Owner

Looks like related with FontConfig's "spacing" which requires all the advance widths in the font to be 0, 500 or 1000. I did not knock out (U+2E3A) and (U+2E3B) so that may be the reason.

@terrywang
Copy link
Author

@be5invis Thanks for the prompt response ;-)

Could you please explain in plain language what the problem is (e.g. a bug in the fonts) and potential workaround (a patch for the fonts) to people like me with limited knowledge of fonts? 😹

@be5invis
Copy link
Owner

be5invis commented Oct 12, 2020

A bug in the fonts

Yes (for pleasing FontConfig at least).

A patch for the fonts

I plan to knock out these problematic glyphs in next release, you could test whether it worked.

@terrywang
Copy link
Author

Thank you. I am more than happy (and keen) to test it out, will keep an eye on new release.

@terrywang
Copy link
Author

Self-educated a bit more on fonts (bitmap, vector / outline and etc.) and fontconfig, quite entertaining ;-)

For those who are curious, the cause, as @be5invis pointed out, some problematic glyphs in Sarasa Gothic v0.14.3 and earlier failed to please fontconfig on Linux (didn't know why it worked on macOS) for it to calculate the spacing property based on actual glyph widths in the font.

The outcome is that kitty is not happy ;-)

@be5invis
Copy link
Owner

Resolve as fixed. Will land in next version (0.14.5 or 0.15.0).

@terrywang
Copy link
Author

I can confirm that v0.14.5 has fixed the problem. Thanks ;-)

kitty --debug-font-fallback
[304 18:28:04.391779] Preloaded font faces:
[304 18:28:04.391849] normal face: /home/terry/.fonts/sarasa-term-sc-regular.ttf:0
[304 18:28:04.391883] bold face: /home/terry/.fonts/sarasa-term-sc-regular.ttf:0
[304 18:28:04.391912] italic face: /home/terry/.fonts/sarasa-term-sc-regular.ttf:0
[304 18:28:04.391938] bi face: /home/terry/.fonts/sarasa-term-sc-regular.ttf:0

fontconfig can now correctly calculate the spacing property based on actual glyph widths in the font.

fc-list : family spacing outline scalable | awk '/spacing=100/ || /spacing=90/' | awk '/outline=True/ && /scalable=True/' | grep -i Sarasa
Sarasa Term SC:spacing=90:outline=True:scalable=True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants