2017-03-12 22:06:44 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2017-04-03 14:48:50 +01:00
|
|
|
cfg = config.fonts.fontconfig;
|
2017-03-12 22:06:44 +00:00
|
|
|
|
2017-04-11 17:08:51 +01:00
|
|
|
fcBool = x: "<bool>" + (boolToString x) + "</bool>";
|
2017-04-03 14:48:50 +01:00
|
|
|
|
|
|
|
# back-supported fontconfig version and package
|
|
|
|
# version is used for font cache generation
|
|
|
|
supportVersion = "210";
|
|
|
|
supportPkg = pkgs."fontconfig_${supportVersion}";
|
|
|
|
|
|
|
|
# latest fontconfig version and package
|
|
|
|
# version is used for configuration folder name, /etc/fonts/VERSION/
|
|
|
|
# note: format differs from supportVersion and can not be used with makeCacheConf
|
2017-03-12 22:06:44 +00:00
|
|
|
latestVersion = pkgs.fontconfig.configVersion;
|
2017-04-03 14:48:50 +01:00
|
|
|
latestPkg = pkgs.fontconfig;
|
|
|
|
|
|
|
|
# supported version fonts.conf
|
|
|
|
supportFontsConf = pkgs.makeFontsConf { fontconfig = supportPkg; fontDirectories = config.fonts.fonts; };
|
|
|
|
|
|
|
|
# configuration file to read fontconfig cache
|
|
|
|
# version dependent
|
|
|
|
# priority 0
|
|
|
|
cacheConfSupport = makeCacheConf { version = supportVersion; };
|
|
|
|
cacheConfLatest = makeCacheConf {};
|
|
|
|
|
|
|
|
# generate the font cache setting file for a fontconfig version
|
|
|
|
# use latest when no version is passed
|
|
|
|
makeCacheConf = { version ? null }:
|
|
|
|
let
|
2019-04-24 04:48:22 +01:00
|
|
|
fcPackage = if version == null
|
2017-04-03 14:48:50 +01:00
|
|
|
then "fontconfig"
|
|
|
|
else "fontconfig_${version}";
|
|
|
|
makeCache = fontconfig: pkgs.makeFontsCache { inherit fontconfig; fontDirectories = config.fonts.fonts; };
|
2019-08-13 22:52:01 +01:00
|
|
|
cache = makeCache pkgs.${fcPackage};
|
|
|
|
cache32 = makeCache pkgs.pkgsi686Linux.${fcPackage};
|
2017-04-03 14:48:50 +01:00
|
|
|
in
|
|
|
|
pkgs.writeText "fc-00-nixos-cache.conf" ''
|
|
|
|
<?xml version='1.0'?>
|
|
|
|
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
|
|
|
|
<fontconfig>
|
|
|
|
<!-- Font directories -->
|
|
|
|
${concatStringsSep "\n" (map (font: "<dir>${font}</dir>") config.fonts.fonts)}
|
|
|
|
<!-- Pre-generated font caches -->
|
|
|
|
<cachedir>${cache}</cachedir>
|
|
|
|
${optionalString (pkgs.stdenv.isx86_64 && cfg.cache32Bit) ''
|
|
|
|
<cachedir>${cache32}</cachedir>
|
|
|
|
''}
|
|
|
|
</fontconfig>
|
|
|
|
'';
|
2017-03-12 22:06:44 +00:00
|
|
|
|
2019-08-20 12:42:39 +01:00
|
|
|
# local configuration file
|
2017-11-10 21:55:43 +00:00
|
|
|
localConf = pkgs.writeText "fc-local.conf" cfg.localConf;
|
|
|
|
|
2019-08-20 12:42:39 +01:00
|
|
|
# rendering settings configuration files
|
|
|
|
# priority 10
|
2017-04-03 14:48:50 +01:00
|
|
|
hintingConf = pkgs.writeText "fc-10-hinting.conf" ''
|
|
|
|
<?xml version='1.0'?>
|
|
|
|
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
|
|
|
|
<fontconfig>
|
|
|
|
|
|
|
|
<!-- Default rendering settings -->
|
|
|
|
<match target="pattern">
|
|
|
|
<edit mode="append" name="hinting">
|
|
|
|
${fcBool cfg.hinting.enable}
|
|
|
|
</edit>
|
|
|
|
<edit mode="append" name="autohint">
|
|
|
|
${fcBool cfg.hinting.autohint}
|
|
|
|
</edit>
|
|
|
|
<edit mode="append" name="hintstyle">
|
|
|
|
<const>hintslight</const>
|
|
|
|
</edit>
|
|
|
|
</match>
|
|
|
|
|
|
|
|
</fontconfig>
|
|
|
|
'';
|
|
|
|
|
|
|
|
antialiasConf = pkgs.writeText "fc-10-antialias.conf" ''
|
|
|
|
<?xml version='1.0'?>
|
|
|
|
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
|
|
|
|
<fontconfig>
|
|
|
|
|
|
|
|
<!-- Default rendering settings -->
|
|
|
|
<match target="pattern">
|
|
|
|
<edit mode="append" name="antialias">
|
|
|
|
${fcBool cfg.antialias}
|
|
|
|
</edit>
|
|
|
|
</match>
|
|
|
|
|
|
|
|
</fontconfig>
|
|
|
|
'';
|
|
|
|
|
|
|
|
subpixelConf = pkgs.writeText "fc-10-subpixel.conf" ''
|
|
|
|
<?xml version='1.0'?>
|
|
|
|
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
|
|
|
|
<fontconfig>
|
|
|
|
|
|
|
|
<!-- Default rendering settings -->
|
|
|
|
<match target="pattern">
|
|
|
|
<edit mode="append" name="rgba">
|
|
|
|
<const>${cfg.subpixel.rgba}</const>
|
|
|
|
</edit>
|
|
|
|
<edit mode="append" name="lcdfilter">
|
|
|
|
<const>lcd${cfg.subpixel.lcdfilter}</const>
|
|
|
|
</edit>
|
|
|
|
</match>
|
|
|
|
|
|
|
|
</fontconfig>
|
|
|
|
'';
|
|
|
|
|
|
|
|
dpiConf = pkgs.writeText "fc-11-dpi.conf" ''
|
|
|
|
<?xml version='1.0'?>
|
|
|
|
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
|
|
|
|
<fontconfig>
|
|
|
|
|
|
|
|
<match target="pattern">
|
|
|
|
<edit name="dpi" mode="assign">
|
|
|
|
<double>${toString cfg.dpi}</double>
|
|
|
|
</edit>
|
|
|
|
</match>
|
|
|
|
|
|
|
|
</fontconfig>
|
|
|
|
'';
|
|
|
|
|
2019-08-20 12:42:39 +01:00
|
|
|
# default fonts configuration file
|
|
|
|
# priority 52
|
2017-04-03 14:48:50 +01:00
|
|
|
defaultFontsConf =
|
|
|
|
let genDefault = fonts: name:
|
|
|
|
optionalString (fonts != []) ''
|
|
|
|
<alias>
|
|
|
|
<family>${name}</family>
|
|
|
|
<prefer>
|
|
|
|
${concatStringsSep ""
|
|
|
|
(map (font: ''
|
|
|
|
<family>${font}</family>
|
|
|
|
'') fonts)}
|
|
|
|
</prefer>
|
|
|
|
</alias>
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
pkgs.writeText "fc-52-nixos-default-fonts.conf" ''
|
|
|
|
<?xml version='1.0'?>
|
|
|
|
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
|
|
|
|
<fontconfig>
|
|
|
|
|
|
|
|
<!-- Default fonts -->
|
|
|
|
${genDefault cfg.defaultFonts.sansSerif "sans-serif"}
|
|
|
|
|
|
|
|
${genDefault cfg.defaultFonts.serif "serif"}
|
|
|
|
|
|
|
|
${genDefault cfg.defaultFonts.monospace "monospace"}
|
|
|
|
|
|
|
|
</fontconfig>
|
|
|
|
'';
|
|
|
|
|
2019-08-20 12:42:39 +01:00
|
|
|
# reject Type 1 fonts
|
|
|
|
# priority 53
|
2019-08-20 12:32:15 +01:00
|
|
|
rejectType1 = pkgs.writeText "fc-53-nixos-reject-type1.conf" ''
|
2017-04-03 14:48:50 +01:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
|
|
|
|
<fontconfig>
|
|
|
|
|
|
|
|
<!-- Reject Type 1 fonts -->
|
|
|
|
<selectfont>
|
|
|
|
<rejectfont>
|
|
|
|
<pattern>
|
|
|
|
<patelt name="fontformat"><string>Type 1</string></patelt>
|
|
|
|
</pattern>
|
|
|
|
</rejectfont>
|
|
|
|
</selectfont>
|
|
|
|
|
|
|
|
</fontconfig>
|
2017-03-12 22:06:44 +00:00
|
|
|
'';
|
|
|
|
|
2019-08-20 12:50:52 +01:00
|
|
|
# The configuration to be included in /etc/font/
|
2019-08-20 12:32:15 +01:00
|
|
|
penultimateConf = pkgs.runCommand "fontconfig-penultimate-conf" {
|
2019-08-20 12:50:52 +01:00
|
|
|
preferLocalBuild = true;
|
2019-08-20 12:24:21 +01:00
|
|
|
} ''
|
2019-08-20 12:50:52 +01:00
|
|
|
support_folder=$out/etc/fonts/conf.d
|
|
|
|
latest_folder=$out/etc/fonts/${latestVersion}/conf.d
|
|
|
|
|
|
|
|
mkdir -p $support_folder
|
|
|
|
mkdir -p $latest_folder
|
|
|
|
|
2019-08-20 12:42:39 +01:00
|
|
|
# fonts.conf
|
2019-08-20 12:50:52 +01:00
|
|
|
ln -s ${supportFontsConf} $support_folder/../fonts.conf
|
|
|
|
ln -s ${latestPkg.out}/etc/fonts/fonts.conf \
|
|
|
|
$latest_folder/../fonts.conf
|
|
|
|
|
|
|
|
# fontconfig-penultimate various configuration files
|
|
|
|
ln -s ${pkgs.fontconfig-penultimate}/etc/fonts/conf.d/*.conf \
|
|
|
|
$support_folder
|
|
|
|
ln -s ${pkgs.fontconfig-penultimate}/etc/fonts/conf.d/*.conf \
|
|
|
|
$latest_folder
|
|
|
|
|
|
|
|
ln -s ${cacheConfSupport} $support_folder/00-nixos-cache.conf
|
|
|
|
ln -s ${cacheConfLatest} $latest_folder/00-nixos-cache.conf
|
|
|
|
|
|
|
|
rm $support_folder/10-antialias.conf $latest_folder/10-antialias.conf
|
|
|
|
ln -s ${antialiasConf} $support_folder/10-antialias.conf
|
|
|
|
ln -s ${antialiasConf} $latest_folder/10-antialias.conf
|
|
|
|
|
|
|
|
rm $support_folder/10-hinting.conf $latest_folder/10-hinting.conf
|
|
|
|
ln -s ${hintingConf} $support_folder/10-hinting.conf
|
|
|
|
ln -s ${hintingConf} $latest_folder/10-hinting.conf
|
|
|
|
|
|
|
|
${optionalString cfg.useEmbeddedBitmaps ''
|
|
|
|
rm $support_folder/10-no-embedded-bitmaps.conf
|
|
|
|
rm $latest_folder/10-no-embedded-bitmaps.conf
|
|
|
|
''}
|
|
|
|
|
|
|
|
rm $support_folder/10-subpixel.conf $latest_folder/10-subpixel.conf
|
|
|
|
ln -s ${subpixelConf} $support_folder/10-subpixel.conf
|
|
|
|
ln -s ${subpixelConf} $latest_folder/10-subpixel.conf
|
|
|
|
|
|
|
|
${optionalString (cfg.dpi != 0) ''
|
|
|
|
ln -s ${dpiConf} $support_folder/11-dpi.conf
|
|
|
|
ln -s ${dpiConf} $latest_folder/11-dpi.conf
|
|
|
|
''}
|
|
|
|
|
2019-08-20 12:42:39 +01:00
|
|
|
# 50-user.conf
|
2019-08-20 12:50:52 +01:00
|
|
|
${optionalString (!cfg.includeUserConf) ''
|
|
|
|
rm $support_folder/50-user.conf
|
|
|
|
rm $latest_folder/50-user.conf
|
|
|
|
''}
|
|
|
|
|
|
|
|
# 51-local.conf
|
|
|
|
rm $latest_folder/51-local.conf
|
|
|
|
substitute \
|
|
|
|
${pkgs.fontconfig-penultimate}/etc/fonts/conf.d/51-local.conf \
|
|
|
|
$latest_folder/51-local.conf \
|
|
|
|
--replace local.conf /etc/fonts/${latestVersion}/local.conf
|
|
|
|
|
|
|
|
# local.conf (indirect priority 51)
|
|
|
|
${optionalString (cfg.localConf != "") ''
|
2019-08-20 12:29:54 +01:00
|
|
|
ln -s ${localConf} $support_folder/../local.conf
|
|
|
|
ln -s ${localConf} $latest_folder/../local.conf
|
2019-08-20 12:50:52 +01:00
|
|
|
''}
|
|
|
|
|
2019-08-20 12:42:39 +01:00
|
|
|
# 52-nixos-default-fonts.conf
|
2019-08-20 12:32:15 +01:00
|
|
|
ln -s ${defaultFontsConf} $support_folder/52-nixos-default-fonts.conf
|
|
|
|
ln -s ${defaultFontsConf} $latest_folder/52-nixos-default-fonts.conf
|
2019-08-20 12:50:52 +01:00
|
|
|
|
2019-08-20 12:42:39 +01:00
|
|
|
# 53-no-bitmaps.conf
|
2019-08-20 12:50:52 +01:00
|
|
|
${optionalString cfg.allowBitmaps ''
|
|
|
|
rm $support_folder/53-no-bitmaps.conf
|
|
|
|
rm $latest_folder/53-no-bitmaps.conf
|
|
|
|
''}
|
|
|
|
|
|
|
|
${optionalString (!cfg.allowType1) ''
|
2019-08-20 12:42:39 +01:00
|
|
|
# 53-nixos-reject-type1.conf
|
2019-08-20 12:32:15 +01:00
|
|
|
ln -s ${rejectType1} $support_folder/53-nixos-reject-type1.conf
|
|
|
|
ln -s ${rejectType1} $latest_folder/53-nixos-reject-type1.conf
|
2019-08-20 12:50:52 +01:00
|
|
|
''}
|
|
|
|
'';
|
|
|
|
|
2017-03-12 22:06:44 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
fonts = {
|
|
|
|
|
|
|
|
fontconfig = {
|
|
|
|
|
|
|
|
penultimate = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Enable fontconfig-penultimate settings to supplement the
|
|
|
|
NixOS defaults by providing per-font rendering defaults and
|
|
|
|
metric aliases.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-11-16 20:33:53 +00:00
|
|
|
config = mkIf (config.fonts.fontconfig.enable && config.fonts.fontconfig.penultimate.enable) {
|
2017-03-12 22:06:44 +00:00
|
|
|
|
2017-04-03 14:48:50 +01:00
|
|
|
fonts.fontconfig.confPackages = [ penultimateConf ];
|
2017-03-12 22:06:44 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|