Disabling the GNOME UI font's contextual substitutions

I know this is the sort of nitpicky detail that maybe only one other person is ever going to care about, but GNOME 48 is shipping with a new default UI font that is a little too eager to do things like replace ‘->’ with ‘→’ and render ‘*I*’ as ‘∗I*’. It drives me nuts. Here’s a cheap and cheerful overlay that will erase this misfeature from the font, just in case you’re that one person.

self: super: {
  adwaita-fonts = super.adwaita-fonts.overrideAttrs (oldAttrs: {
    nativeBuildInputs = oldAttrs.nativeBuildInputs or [ ] ++ [
      self.python3Packages.fonttools
    ];
    preInstall = oldAttrs.preInstall or "" + ''
      python - ../{mono,sans}/*.ttf <<EOF
      import fontTools.ttLib as ttLib
      import sys
      for arg in sys.argv[1:]:
          print(f"patching {arg}")
          ttf = ttLib.TTFont(arg)
          feats = ttf['GSUB'].table.FeatureList.FeatureRecord
          for feat in feats:
              if feat.FeatureTag == 'calt':
                  feats.remove(feat)
                  break
          ttf.save(arg)
      EOF
    '';
  });
}
7 Likes

In case that single other person is as curious as I was, calt probably stands for Contextual Alternates.

Nice, I guess this could also be used to disable the Jetbrains Mono ligatures or how its called, turning e.g. }} into some weird }-. And this is supposed to help with coding :sweat_smile: