mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-21 23:54:57 +00:00
Fix shaping ignoring variation axes of fonts loaded from descriptors
The HarfBuzz font was created before the named instance or axis coordinates were applied to the FreeType face and was only resynced if the face had a transform matrix. So shaping used the default variation coordinates, which broke fonts that substitute glyphs based on axis values via GSUB FeatureVariations, such as the cursive (CRSV) axis of Annotation Mono. Adds a test using a small subset of Annotation Mono (SIL OFL 1.1). Fixes #10897
This commit is contained in:
parent
72c2b119c3
commit
f63baf9f0b
5 changed files with 43 additions and 3 deletions
|
|
@ -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]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
BIN
kitty_tests/AnnotationMono-VF-subset.ttf
Normal file
BIN
kitty_tests/AnnotationMono-VF-subset.ttf
Normal file
Binary file not shown.
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue