diff --git a/docs/changelog.rst b/docs/changelog.rst index 29087fa0d..bfa4a04fc 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -131,6 +131,8 @@ Detailed list of changes - Fix animated images stopping when switching to a tab without animations and then back (:iss:`10894`) +- Linux: Fix variable fonts that use axis values to substitute glyphs, such as the cursive axis of Annotation Mono, not rendering the substituted glyphs (:iss:`10897`) + 0.51.0 [2026-11-18] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/fonts/render.py b/kitty/fonts/render.py index 84efd5935..34ff60e11 100644 --- a/kitty/fonts/render.py +++ b/kitty/fonts/render.py @@ -164,7 +164,7 @@ def create_narrow_symbols(opts: Options) -> tuple[tuple[int, int, int], ...]: return tuple((a, b, v) for (a, b), v in coalesce_symbol_maps(opts.narrow_symbols).items()) -descriptor_overrides: dict[int, tuple[str, bool, bool]] = {} +descriptor_overrides: dict[int, tuple[FontObject | str, bool, bool]] = {} def descriptor_for_idx(idx: int) -> tuple[FontObject | str, bool, bool]: @@ -236,9 +236,17 @@ class setup_for_testing: ynum = 100 baseline = 0 - def __init__(self, family: str = 'monospace', size: float = 11.0, dpi: float = 96.0, main_face_path: str = ''): + def __init__( + self, + family: str = 'monospace', + size: float = 11.0, + dpi: float = 96.0, + main_face_path: str = '', + main_face_descriptor: FontObject | None = None, + ): self.family, self.size, self.dpi = family, size, dpi self.main_face_path = main_face_path + self.main_face_descriptor = main_face_descriptor def __enter__(self) -> tuple[dict[tuple[int, int, int], bytes], int, int]: global descriptor_overrides @@ -253,7 +261,9 @@ class setup_for_testing: set_send_sprite_to_gpu(send_to_gpu) self.orig_desc_overrides = descriptor_overrides descriptor_overrides = {} - if self.main_face_path: + if self.main_face_descriptor is not None: + descriptor_overrides[0] = self.main_face_descriptor, False, False + elif self.main_face_path: descriptor_overrides[0] = self.main_face_path, False, False try: set_font_family(opts) diff --git a/kitty/freetype.c b/kitty/freetype.c index 9f3e5f9bf..9ee6136bb 100644 --- a/kitty/freetype.c +++ b/kitty/freetype.c @@ -417,6 +417,12 @@ face_from_descriptor(PyObject *descriptor, FONTS_DATA_HANDLE fg) { } if ((error = FT_Set_Var_Design_Coordinates(self->face, sz, coords))) return set_load_error(path, error); } + // The HarfBuzz font was created in init_ft_face() using the default + // variation coordinates, sync it with the ones set above, otherwise + // shaping ignores them, which breaks fonts that substitute glyphs based + // on axis values via GSUB FeatureVariations, see + // https://github.com/kovidgoyal/kitty/issues/10897 + if ((ns || axes) && self->harfbuzz_font) hb_ft_font_changed(self->harfbuzz_font); if (!create_features_for_face(postscript_name_for_face((PyObject *)self), PyDict_GetItemString(descriptor, "features"), &self->font_features)) return NULL; if (!read_matrix_from_descriptor(descriptor, &self->matrix, &self->has_matrix)) return NULL; diff --git a/kitty_tests/AnnotationMono-VF-subset.ttf b/kitty_tests/AnnotationMono-VF-subset.ttf new file mode 100644 index 000000000..be2bbccc5 Binary files /dev/null and b/kitty_tests/AnnotationMono-VF-subset.ttf differ diff --git a/kitty_tests/fonts.py b/kitty_tests/fonts.py index 13f651883..b64203e19 100644 --- a/kitty_tests/fonts.py +++ b/kitty_tests/fonts.py @@ -480,6 +480,28 @@ class Rendering(FontBaseTest): self.assertGreater(w, 64) self.assertGreater(h, 64) + @unittest.skipIf(is_macos, 'fontconfig descriptors are not used on macOS') + def test_shaping_uses_variation_axes(self): + # Annotation Mono switches to cursive glyphs via GSUB FeatureVariations + # conditioned on its CRSV axis, so shaping must use the variation + # coordinates set on the face, see https://github.com/kovidgoyal/kitty/issues/10897 + path = self.path_for_font('AnnotationMono-VF-subset.ttf') + plain, cursive = [1, 3, 6, 8], [2, 4, 7, 9] # a f k l and a.ital f.ital k.ital l.ital + + def shaped_glyphs(**extra): + descriptor = {'descriptor_type': 'fontconfig', 'path': path, 'index': 0, 'hinting': True, 'hint_style': 3, **extra} + with setup_for_testing(size=self.font_size, dpi=self.dpi, main_face_descriptor=descriptor): + s = Screen(None, 1, 8) + s.draw('afkl') + return [g for group in test_shape(s.line(0), None) for g in group[3]] + + # axes are in the order: wght, slnt, CRSV + self.ae(shaped_glyphs(axes=(250.0, 0.0, 0.0)), plain) + self.ae(shaped_glyphs(axes=(250.0, 0.0, 1.0)), cursive) + self.ae(shaped_glyphs(axes=(250.0, -15.0, 0.5)), cursive) + self.ae(shaped_glyphs(named_style=5), plain) # DemiBold + self.ae(shaped_glyphs(named_style=35), cursive) # DemiBold Upright Italic + def test_color_emoji_not_shrunk(self): # Regression test for https://github.com/kovidgoyal/kitty/issues/10144. # fontconfig gives fixed-size color faces (e.g. Noto Color Emoji) a