kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.12k stars 971 forks source link

Private Use Unicode characters not rendered on macOS with bold/italic set #6043

Closed antoineco closed 6 months ago

antoineco commented 1 year ago

Describe the bug

With Symbols Nerd Font Mono used as fallback font, characters in the Private Use Unicode range disappear or are rendered improperly when the italic or bold attributes are set.

For example:

I assume this is happening because the fallback font doesn't have a Bold or Italic variant installed, which might not even be true because things work fine with a Regular patched font (see additional comments).

To Reproduce

  1. Install Symbols Nerd Font Mono 2048-em, which kitty should automatically fall back to.

  2. Open (Neo)vim (defaults)

  3. Ensure the StatusLine highlight group has cterm=bold or cterm=italic.

  4. :set statusline=\ main
    :set statusline=\ main

Screenshots

default_status_hl nf_merge nf_branch

Below, there should be a U+E725 symbol between the two x, but not when the line is commented: default_comment_italic

Environment details

Debug output ``` kitty 0.27.1 () created by Kovid Goyal Darwin acotten-mbp13 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:04:44 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T8103 arm64 ProductName: macOS ProductVersion: 13.1 BuildVersion: 22C65 Frozen: True Paths: kitty: /Applications/kitty.app/Contents/MacOS/kitty base dir: /Applications/kitty.app/Contents/Resources/kitty extensions dir: /Applications/kitty.app/Contents/Resources/Python/lib/kitty-extensions system shell: /bin/zsh Loaded config files: /Users/acotten/.config/kitty/kitty.conf Config options different from defaults: active_tab_font_style (True, False) disable_ligatures 1 font_family Cascadia Code font_size 15.0 initial_window_height (32, 'cells') initial_window_width (140, 'cells') remember_window_size False tab_bar_style powerline tab_powerline_style slanted Colors: active_border_color #a7c080 active_tab_background #2d353b active_tab_foreground #d3c6aa background #2d353b bell_border_color #e69875 color0 #343f44 color1 #e67e80 color10 #a7c080 color11 #dbbc7f color12 #7fbbb3 color13 #d699b6 color14 #83c092 color15 #9da9a0 color2 #a7c080 color3 #dbbc7f color4 #7fbbb3 color5 #d699b6 color6 #83c092 color7 #859289 color8 #3d484d color9 #e67e80 cursor #d3c6aa cursor_text_color #343f44 foreground #d3c6aa inactive_border_color #56635f inactive_tab_background #3d484d inactive_tab_foreground #9da9a0 mark1_background #7fbbb3 mark1_foreground #2d353b mark2_background #d3c6aa mark2_foreground #2d353b mark3_background #d699b6 mark3_foreground #2d353b selection_background #543a48 selection_foreground #9da9a0 tab_bar_background #343f44 url_color #7fbbb3 Important environment variables seen by the kitty process: PATH /Applications/kitty.app/Contents/MacOS:/usr/bin:/bin:/usr/sbin:/sbin LANG en_US.UTF-8 SHELL /bin/zsh USER acotten ```

Additional context

Can't reproduce with a patched Nerd Font, even if I only install the Regular style.

image

$ kitty +list-fonts
CaskaydiaCove Nerd Font Mono
    CaskaydiaCove Nerd Font Mono Regular

Symbols Nerd Font Mono
    Symbols Nerd Font Mono 2048-em
# kitty.conf
font_family CaskaydiaCove Nerd Font Mono
font_size   15.0
kovidgoyal commented 1 year ago

This will be a limitation of CoreText, which is used for fallback on macOS. You can fix it by defining symbol_map in kitty.conf as described in the FAQ https://sw.kovidgoyal.net/kitty/faq/#kitty-is-not-able-to-use-my-favorite-font

It might be worth working around this by detecting when CoreText is falling back to the last resort font for a PUA and nuking bold/italic and retrying. Something for a rainy day, or of course, patches welcome.

antoineco commented 1 year ago

symbol_map U+E725 Symbols Nerd Font Mono solves the problem for me indeed 👍 Thanks for the hint.

kovidgoyal commented 6 months ago

master now correctly applies bold and italics to fallback fonts. My diagnosis of this issue was likely incorrect to start with, as before my latest fix kitty did not use bold/italic attributes at all when looking for fallback fonts on macOS. The problem was likely CoreText fallback using a different font than nerd font for those code points. In any case the proper fix is to use symbol_map to ensure kitty uses the font you want for these symbols, regardless of CoreText's mysterious fallback algorithms.