diff --git a/kitty/config_data.py b/kitty/config_data.py index c792d31cd..48d6df8eb 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -277,7 +277,8 @@ def disable_ligatures(x): map alt+2 disable_ligatures_in all never map alt+3 disable_ligatures_in tab cursor -Note: If font_feature_settings is enabled, this feature has no effect. +Note: This function is equivalent to setting :code:`font_feature_settings` to +:code:`-liga -dlig -calt`. ''')) o('font_feature_settings', 'none', long_text=_(''' @@ -292,12 +293,8 @@ def disable_ligatures(x): family; this allows you to define very precise feature settings; e.g. you can disable a feature in the italic font but not in the regular font. -Note that this feature ignores the value of :code:`disable_ligatures`, because -it assumes you want to fine tune exactly which OpenType tags are -enabled/disabled. See examples below. - To get the PostScript name for a font, ask Fontconfig for it, using your family -name: +name:: $ fc-match "Fira Code" postscriptname :postscriptname=FiraCode-Regular @@ -306,16 +303,16 @@ def disable_ligatures(x): $ fc-match "TT2020Base:style=italic" postscriptname :postscriptname=TT2020Base-Italic -Enable alternate zero and oldstyle numerals: +Enable alternate zero and oldstyle numerals:: font_feature_settings FiraCode-Retina: +zero +onum -Enable only alternate zero: +Enable only alternate zero:: font_feature_settings FiraCode-Retina: +zero Disable the normal ligatures, but keep the :code:`calt` feature which (in this -font) breaks up monotony: +font) breaks up monotony:: font_feature_settings TT2020StyleB-Regular: -liga +calt ''')) diff --git a/kitty/fonts.c b/kitty/fonts.c index b91125ad6..9deffa669 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -360,24 +360,24 @@ init_font(Font *f, PyObject *face, bool bold, bool italic, bool emoji_presentati f->bold = bold; f->italic = italic; f->emoji_presentation = emoji_presentation; f->num_hb_features = 0; const char *psname = postscript_name_for_face(face); - if (strstr(psname, "NimbusMonoPS-") == psname) { - copy_hb_feature(f, LIGA_FEATURE); copy_hb_feature(f, DLIG_FEATURE); - } + copy_hb_feature(f, LIGA_FEATURE); + copy_hb_feature(f, DLIG_FEATURE); copy_hb_feature(f, CALT_FEATURE); if (font_feature_settings != NULL){ - const char* face = postscript_name_for_face(f->face); - - PyObject* o = PyDict_GetItemString(font_feature_settings, face); + PyObject* o = PyDict_GetItemString(font_feature_settings, psname); if (o != NULL) { long len = PyList_Size(o); - hb_feature_t* hb_feat = calloc(len, sizeof(hb_feature_t)); + if (len==0) return true; + f->num_ffs_hb_features = len + f->num_hb_features; + hb_feature_t* hb_feat = calloc(f->num_ffs_hb_features, sizeof(hb_feature_t)); for (long i = len-1; i >= 0; i--) { PyObject* item = PyList_GetItem(o, i); const char* feat = PyUnicode_AsUTF8(item); hb_feature_from_string(feat, -1, &hb_feat[i]); } + for (size_t i = 0; i < f->num_hb_features; i++) + hb_feat[len+i] = hb_features[i]; f->ffs_hb_features = hb_feat; - f->num_ffs_hb_features = len; } } return true; @@ -386,6 +386,8 @@ init_font(Font *f, PyObject *face, bool bold, bool italic, bool emoji_presentati static inline void del_font(Font *f) { Py_CLEAR(f->face); + if (f->num_ffs_hb_features > 0) + free(f->ffs_hb_features); free_maps(f); f->bold = false; f->italic = false; } @@ -794,9 +796,9 @@ shape(CPUCell *first_cpu_cell, GPUCell *first_gpu_cell, index_type num_cells, hb load_hb_buffer(first_cpu_cell, first_gpu_cell, num_cells); if (fobj->num_ffs_hb_features > 0) - hb_shape(font, harfbuzz_buffer, fobj->ffs_hb_features, fobj->num_ffs_hb_features); + hb_shape(font, harfbuzz_buffer, fobj->ffs_hb_features, fobj->num_ffs_hb_features - (disable_ligature ? 0 : fobj->num_hb_features)); else - hb_shape(font, harfbuzz_buffer, fobj->hb_features, fobj->num_hb_features - (disable_ligature ? 0 : 1)); + hb_shape(font, harfbuzz_buffer, fobj->hb_features, fobj->num_hb_features - (disable_ligature ? 0 : fobj->num_hb_features)); unsigned int info_length, positions_length; group_state.info = hb_buffer_get_glyph_infos(harfbuzz_buffer, &info_length); @@ -1079,7 +1081,7 @@ render_run(FontGroup *fg, CPUCell *first_cpu_cell, GPUCell *first_gpu_cell, inde default: shape_run(first_cpu_cell, first_gpu_cell, num_cells, &fg->fonts[font_idx], disable_ligature_strategy == DISABLE_LIGATURES_ALWAYS); if (pua_space_ligature) merge_groups_for_pua_space_ligature(); - else if (cursor_offset > -1) { + else if (cursor_offset > -1) { // false if DISABLE_LIGATURES_NEVER index_type left, right; split_run_at_offset(cursor_offset, &left, &right); if (right > left) {