mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-07-03 11:12:30 +08:00
fontconfig's FcFontList omits FC_MATRIX from its object set (kitty/fontconfig.c), so a roman font that find_best_match finds there (e.g. Fira Code, which ships no italic, in both its static and variable builds) carries no synthetic-italic shear and its "italic" renders upright. A family that is not found is substituted, and when the substitute resolves through the listed faces those descriptors are equally matrix-less, so this attach covers them too. Only raw fc_match descriptors (runtime glyph-fallback faces via create_fallback_face, and find_best_match's last-resort return) already carry the matrix from substitution. The italic intent for the configured faces exists only during selection, not at face construction, so attach the matrix at the end of get_font_files: for an italic slot whose chosen face is upright and has no matrix, ask fc_match what fontconfig would do. fc_match returns a synthetic matrix only when there is no real italic to use (no italic face and no slanted named instance or variable slant axis), so a font that is already italic, static or variable, is never double-slanted. Face construction applies the matrix via FT_Set_Transform; the previous commit makes it survive the size specialization step the render path builds faces from. Only the matrix is taken, so selection is unchanged. FontConfigPattern declared matrix as a required key, but pattern_as_dict sets it only when the pattern has one, so declare it NotRequired. With that and narrowing on descriptor_type the attach needs no cast. Add a regression test (test_synthetic_italic_matrix): a roman no-italic font gets a non-identity matrix on its italic slot while a real-italic control does not, and the matrix survives specialize_font_descriptor. It asserts the invariant rather than the exact shear (the value is fontconfig's, version-dependent) and skips when the synthetic rule is inactive. Covers the four configured faces. Limitation: fc_match re-matches by family name, so under an uncommon config (a multi-face family key plus a user per-font FC_MATRIX rule keyed on width/style) it can attach a matrix computed for a different face; the 90-synthetic shear this targets is weight-independent and unaffected. A production version should re-match the selected face by path+index+slant.