mirror of
https://github.com/nix-community/home-manager.git
synced 2025-12-07 17:41:03 +01:00
fontconfig: add options for font rendering
This commit is contained in:
parent
672381a34e
commit
74b4edc2d2
4 changed files with 128 additions and 0 deletions
|
|
@ -90,6 +90,41 @@ in
|
|||
'';
|
||||
};
|
||||
};
|
||||
|
||||
antialiasing = lib.mkOption {
|
||||
type = with lib.types; nullOr bool;
|
||||
default = null;
|
||||
description = "Whether to enable font antialiasing.";
|
||||
example = true;
|
||||
};
|
||||
hinting = lib.mkOption {
|
||||
type =
|
||||
with lib.types;
|
||||
nullOr (enum [
|
||||
"none"
|
||||
"slight"
|
||||
"medium"
|
||||
"full"
|
||||
]);
|
||||
default = null;
|
||||
description = "The font hinting mode.";
|
||||
example = "slight";
|
||||
};
|
||||
subpixelRendering = lib.mkOption {
|
||||
type =
|
||||
with lib.types;
|
||||
nullOr (enum [
|
||||
"none"
|
||||
"rgb"
|
||||
"bgr"
|
||||
"vertical-rgb"
|
||||
"vertical-bgr"
|
||||
]);
|
||||
default = null;
|
||||
description = "The sub-pixel rendering mode.";
|
||||
example = "rgb";
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -157,6 +192,42 @@ in
|
|||
<cachedir>${config.home.path}/lib/fontconfig/cache</cachedir>
|
||||
'';
|
||||
|
||||
"fontconfig/conf.d/10-hm-rendering.conf" =
|
||||
let
|
||||
set =
|
||||
name: value:
|
||||
let
|
||||
xmlValue =
|
||||
if builtins.isBool value then
|
||||
"<bool>${lib.boolToString value}</bool>"
|
||||
else if builtins.isString value then
|
||||
"<const>${value}</const>"
|
||||
else
|
||||
throw ("expected bool or string but got ${builtins.typeOf value}: ${toString value}");
|
||||
in
|
||||
''
|
||||
<match target="font">
|
||||
<edit mode="assign" name="${name}">
|
||||
${xmlValue}
|
||||
</edit>
|
||||
</match>
|
||||
'';
|
||||
content =
|
||||
lib.optional (cfg.antialiasing != null) (set "antialias" cfg.antialiasing)
|
||||
++ lib.optionals (cfg.hinting != null) [
|
||||
(set "hinting" true)
|
||||
(set "hintstyle" ("hint" + cfg.hinting))
|
||||
]
|
||||
++ lib.optional (cfg.subpixelRendering != null) (
|
||||
set "rgba" (builtins.replaceStrings [ "ertical-" ] [ "" ] cfg.subpixelRendering)
|
||||
);
|
||||
in
|
||||
lib.mkIf (builtins.length content > 0) {
|
||||
text = mkFontconfigConf (
|
||||
lib.concatStrings ([ "<description>Set the rendering mode</description>\n" ] ++ content)
|
||||
);
|
||||
};
|
||||
|
||||
"fontconfig/conf.d/52-hm-default-fonts.conf".text =
|
||||
let
|
||||
genDefault =
|
||||
|
|
|
|||
47
tests/modules/misc/fontconfig/custom-rendering.nix
Normal file
47
tests/modules/misc/fontconfig/custom-rendering.nix
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
fonts.fontconfig = {
|
||||
enable = true;
|
||||
antialiasing = false;
|
||||
hinting = "none";
|
||||
subpixelRendering = "vertical-bgr";
|
||||
};
|
||||
|
||||
nmt.script =
|
||||
let
|
||||
configFile = "home-files/.config/fontconfig/conf.d/10-hm-rendering.conf";
|
||||
in
|
||||
''
|
||||
assertFileExists ${configFile}
|
||||
assertFileContent ${configFile} ${builtins.toFile "rendering.conf" ''
|
||||
<?xml version='1.0'?>
|
||||
|
||||
<!-- Generated by Home Manager. -->
|
||||
|
||||
<!DOCTYPE fontconfig SYSTEM 'urn:fontconfig:fonts.dtd'>
|
||||
<fontconfig>
|
||||
<description>Set the rendering mode</description>
|
||||
<match target="font">
|
||||
<edit mode="assign" name="antialias">
|
||||
<bool>false</bool>
|
||||
</edit>
|
||||
</match>
|
||||
<match target="font">
|
||||
<edit mode="assign" name="hinting">
|
||||
<bool>true</bool>
|
||||
</edit>
|
||||
</match>
|
||||
<match target="font">
|
||||
<edit mode="assign" name="hintstyle">
|
||||
<const>hintnone</const>
|
||||
</edit>
|
||||
</match>
|
||||
<match target="font">
|
||||
<edit mode="assign" name="rgba">
|
||||
<const>vbgr</const>
|
||||
</edit>
|
||||
</match>
|
||||
|
||||
</fontconfig>
|
||||
''}
|
||||
'';
|
||||
}
|
||||
7
tests/modules/misc/fontconfig/default-rendering.nix
Normal file
7
tests/modules/misc/fontconfig/default-rendering.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
fonts.fontconfig.enable = true;
|
||||
|
||||
nmt.script = ''
|
||||
assertPathNotExists home-files/.config/fontconfig/conf.d/10-hm-rendering.conf
|
||||
'';
|
||||
}
|
||||
|
|
@ -19,4 +19,7 @@
|
|||
# /nix/store/da…g5-home-manager-path/lib/fontconfig/cache: invalid cache file: 786068e7df13f7c2105017ef3d78e351-x86_64.cache-7
|
||||
# /nix/store/da…g5-home-manager-path/lib/fontconfig/cache: invalid cache file: 4766193978ddda4bd196f2b98c00fb00-x86_64.cache-7
|
||||
#fontconfig-multiple-font-packages = ./multiple-font-packages.nix;
|
||||
|
||||
fontconfig-default-rendering = ./default-rendering.nix;
|
||||
fontconfig-custom-rendering = ./custom-rendering.nix;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue