Use builtin NERD fonts

Prevents users from having to install their own NERD font. System fonts
are still used preferentially on Linux but on macOS the builtin one is
used preferentially. Cant find any CoreText API to change this.

Still has to be implemented on macOS. And need to add code to the build
system to bundle the font when building.
This commit is contained in:
Kovid Goyal
2024-06-30 13:24:36 +05:30
parent 99258f6621
commit 98c85d2923
5 changed files with 16 additions and 3 deletions

1
.gitignore vendored
View File

@@ -12,6 +12,7 @@
/dependencies
/tags
/build/
/fonts/
/linux-package/
/kitty.app/
/glad/out/

View File

@@ -72,6 +72,8 @@ Detailed list of changes
- A new ``choose-fonts`` kitten that provides a UI with font previews to ease selection of fonts. Also has support for font features and variable fonts.
- Add NERD fonts builtin so that users don't have to install them to use NERD symbols in kitty
- Wayland: Allow fractional scales less than one (:pull:`7549`)
- Wayland: Fix specifying the output name for the panel kitten not working (:iss:`7573`)

View File

@@ -177,6 +177,7 @@ terminfo_dir = os.path.join(kitty_base_dir, 'terminfo')
logo_png_file = os.path.join(kitty_base_dir, 'logo', 'kitty.png')
beam_cursor_data_file = os.path.join(kitty_base_dir, 'logo', 'beam-cursor.png')
shell_integration_dir = os.path.join(kitty_base_dir, 'shell-integration')
fonts_dir = os.path.join(kitty_base_dir, 'fonts')
try:
shell_path = pwd.getpwuid(os.geteuid()).pw_shell or '/bin/sh'
except KeyError:

View File

@@ -2,12 +2,13 @@
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
import ctypes
import os
import sys
from functools import partial
from math import ceil, cos, floor, pi
from typing import TYPE_CHECKING, Any, Callable, Dict, Generator, List, Literal, Optional, Tuple, Union, cast
from kitty.constants import is_macos
from kitty.constants import fonts_dir, is_macos
from kitty.fast_data_types import (
NUM_UNDERLINE_STYLES,
Screen,
@@ -197,6 +198,14 @@ def set_font_family(opts: Optional[Options] = None, override_font_size: Optional
)
def add_application_fonts() -> None:
for font in ('SymbolsNerdFontMono-Regular.ttf',):
path = os.path.join(fonts_dir, font)
if os.path.exists(path):
if not add_font_file(path):
log_error(f'Failed to add application font: {path}')
if TYPE_CHECKING:
CBufType = ctypes.Array[ctypes.c_ubyte]
else:
@@ -528,7 +537,6 @@ def test_fallback_font(qtext: Optional[str] = None, bold: bool = False, italic:
def showcase() -> None:
add_font_file
f = 'monospace' if is_macos else 'Liberation Mono'
test_render_string('He\u0347\u0305llo\u0337, w\u0302or\u0306l\u0354d!', family=f)
test_render_string('你好,世界', family=f)

View File

@@ -44,7 +44,7 @@ from .fast_data_types import (
set_options,
)
from .fonts.box_drawing import set_scale
from .fonts.render import dump_font_debug, set_font_family
from .fonts.render import add_application_fonts, dump_font_debug, set_font_family
from .options.types import Options
from .options.utils import DELETE_ENV_VAR
from .os_window_size import edge_spacing, initial_window_size_func
@@ -249,6 +249,7 @@ class AppRunner:
set_options(opts, is_wayland(), args.debug_rendering, args.debug_font_fallback)
try:
set_font_family(opts)
add_application_fonts()
_run_app(opts, args, bad_lines, talk_fd)
finally:
set_options(None)