From b5d2d701d1e983fe82770905e8fce703ba38caa3 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Mon, 20 Mar 2023 18:39:50 +0100 Subject: [PATCH] nixos/fontconfig: refactor antialias option for fontconfig 2.14.1 `sub-pixel` has been enabled by default since 2.14.1: https://gitlab.freedesktop.org/fontconfig/fontconfig/-/commit/2b6afa02ab2b7dd3796a48cf47896c4c6de4d6ba `antialias` since 2.14.1: https://gitlab.freedesktop.org/fontconfig/fontconfig/-/commit/0825a178e82c58ae97e908d49e5ad7abe88ed7f5 `lcdfilter` since 2.13.95: https://gitlab.freedesktop.org/fontconfig/fontconfig/-/commit/e1c7c6d7442ace9c20c424265880ff57c23881f8 `hintstyle` since 2.12.1: https://gitlab.freedesktop.org/fontconfig/fontconfig/-/commit/98434b3392172233094cac25ade7225c93da9f1c Signed-off-by: Sefa Eyeoglu --- nixos/modules/config/fonts/fontconfig.nix | 59 ++++++++++++++++------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/nixos/modules/config/fonts/fontconfig.nix b/nixos/modules/config/fonts/fontconfig.nix index 5781679241ef..a49595c58e1c 100644 --- a/nixos/modules/config/fonts/fontconfig.nix +++ b/nixos/modules/config/fonts/fontconfig.nix @@ -77,18 +77,6 @@ let ${fcBool cfg.hinting.autohint} - - ${cfg.hinting.style} - - - ${fcBool cfg.antialias} - - - ${cfg.subpixel.rgba} - - - lcd${cfg.subpixel.lcdfilter} - @@ -177,6 +165,13 @@ let ''; + # Replace default linked config with a different variant + replaceDefaultConfig = defaultConfig: newConfig: '' + rm $dst/${defaultConfig} + ln -s ${pkg.out}/share/fontconfig/conf.avail/${newConfig} \ + dst/ + ''; + # fontconfig configuration package confPkg = pkgs.runCommand "fontconfig-conf" { preferLocalBuild = true; @@ -196,6 +191,26 @@ let ln -s ${pkg.out}/etc/fonts/conf.d/*.conf \ $dst/ + ${optionalString (!cfg.antialias) + (replaceDefaultConfig "10-yes-antialias.conf" + "10-no-antialias.conf") + } + + ${optionalString (cfg.hinting.style != "slight") + (replaceDefaultConfig "10-hinting-slight.conf" + "10-hinting-${cfg.hinting.style}.conf") + } + + ${optionalString (cfg.subpixel.rgba != "none") + (replaceDefaultConfig "10-sub-pixel-none.conf" + "10-sub-pixel-${cfg.subpixel.rgba}.conf") + } + + ${optionalString (cfg.subpixel.lcdfilter != "default") + (replaceDefaultConfig "11-lcdfilter-default.conf" + "11-lcdfilter-${cfg.subpixel.lcdfilter}.conf") + } + # 00-nixos-cache.conf ln -s ${cacheConf} $dst/00-nixos-cache.conf @@ -367,17 +382,25 @@ in }; style = mkOption { - type = types.enum [ "hintnone" "hintslight" "hintmedium" "hintfull" ]; - default = "hintslight"; + type = types.enum ["none" "slight" "medium" "full"]; + default = "slight"; description = lib.mdDoc '' Hintstyle is the amount of font reshaping done to line up to the grid. - hintslight will make the font more fuzzy to line up to the grid - but will be better in retaining font shape, while hintfull will - be a crisp font that aligns well to the pixel grid but will lose - a greater amount of font shape. + slight will make the font more fuzzy to line up to the grid but + will be better in retaining font shape, while full will be a + crisp font that aligns well to the pixel grid but will lose a + greater amount of font shape. ''; + apply = + val: + let + from = "fonts.fontconfig.hinting.style"; + val' = lib.removePrefix "hint" val; + warning = "The option `${from}` contains a deprecated value `${val}`. Use `${val'}` instead."; + in + lib.warnIf (lib.hasPrefix "hint" val) warning val'; }; };