The incompatibility does not seem to exist any more: programs linked against fc 2.12
on fc 2.14 system seem to at least display text, even while printing tons of errors
(as long as you generate fc cache manually), and same thing the other way around.
Hopefully it will not be an issue in the future.
This reverts commit edf2541f02.
Turns out lot of software (including Chromium) use bundled fontconfig
so we either need to wrap every one of those, or re-introduce the global
unversioned config. The latter is easier but weakens hermetic configs.
But perhaps those are not really worth the effort. Given that programs
linked against fc 2.12.6 on fc 2.13.92 system seem to at least display text,
even while printing tons of errors (as long as you generate fc cache manually),
and same thing the other way around, hopefully it will not be an issue in the future.
We give up on the hermetic configs in exchange for getting rid of lot of complexity.
ITS rules are used for extracting translatable strings and they have
been moved to external files in 2.13.92 so they are not needed in
the config files themselves.
Removing them also cuts down on errors/warnings produced when using
older versions of fontconfig (< 2.12.92). Now it will only complain
about the description element but that is fortunately just a warning,
not errors like the ones caused by the its attributes.
Thanks to this, we can change the config version in NixOS module
back to 2.11 allowing us to re-use the 2.13/2.14 configs for apps
built against 2.12 fontconfig.
With previous patch, we no longer load non-versioned fonts.conf file to avoid incompatibilities
but this also means fontconfig will not load system-wide installed fonts on non-NixOS systems.
As a compromise, let's hardcode the FHS font paths to the built-in config so that the system
fonts work there. Unlike with the system config we do not need to worry about compatibility as
incompatible font files will be simply ignored.
Of course there will still be disparity if the system install fonts to some other location than
these two but I am afraid this is the best we can do.
See https://github.com/NixOS/nixpkgs/pull/73795#issuecomment-635771967 for discussion.
Falling back to unversioned `/etc/fonts/conf.d` when versioned one does not exist
is problematic since it only occurs on non-NixOS systems and those are likely
to have a different version of fontconfig. When those versions use incompatible
elements in the config, apps using fontconfig will crash.
Instead, we are now falling back to the in-package `fonts.conf` file that loads
both the versioned global `conf.d` directory and the in-package `conf.d` since using
upstream settings on non-NixOS is preferable to not being able to use apps there.
In fact, we would not even need to link `fonts.conf`, as the in-package `fonts.conf`
will be always used unless someone creates the global one manually (the option is still
retained if one wants to write a custom NixOS module and to avoid unnecessary stat call on NixOS).
Additionally, since the `fonts.conf` will always load `conf.d` from the package, we no longer
need to install them to sytem `/etc` in the module. This needed some mucking with `50-user.conf`
which disables configs in user directories (a good thing IMO, NixOS module will turn it back on)
but otherwise, it is cleaner. The files are still prioritized by their name, regardless of their location.
See https://github.com/NixOS/nixpkgs/pull/73795#issuecomment-634370125 for more information.
This commit fixes missing fc-cache binary from make-fonts-cache.nix build:
```
builder for '/nix/store/az48nr8gdqrw3fliddmi82ghj2ljxrj4-fc-cache.drv' failed with exit code 127; last 1 log lines:
/nix/store/p3z1lgsi7xymvl7akg531ikwiisqs4x5-stdenv-linux/setup: line 1299: fc-cache: command not found
cannot build derivation '/nix/store/swaxvjsf8h0rsmm9kigp6j3f5q5h4nvg-fc-00-nixos-cache.conf.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/wiaiv0pq7w1xm2i2fqp2ngd1ljb4n6n9-fontconfig-conf.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/4zhiwpiyccs0rs26bs3q0w8fwaxrrgw0-fontconfig-etc.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/xhvljdp9b00fbkapx6cbfs4sjdh49qwv-etc.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/w63q0n0vh7vkdfrjmhb41qy1alx7qa8s-nixos-system-nixos-19.09.git.c814289.drv': 1 dependencies couldn't be built
```
The hack of using `crossConfig` to enforce stricter handling of
dependencies is replaced with a dedicated `strictDeps` for that purpose.
(Experience has shown that my punning was a terrible idea that made more
difficult and embarrising to teach teach.)
Now that is is clear, a few packages now use `strictDeps`, to fix
various bugs:
- bintools-wrapper and cc-wrapper
HFS+ (still common on macOS machines) only has a
date resolution of 1 second. This change makes sure that
`fcobjshash.h` gets a newer timestamp than `fcobjshash.gperf`.
A CACHEDIR.TAG file indicates that the contents can be automatically
re-generated. This is not really true for Nix store paths. (Well _Nix_
can recreate them, but that's different.)
I noticed this issue as I was restoring full system backup that "for
some reason" always missed /nix/store/*-fc-cache (found by `nix-store
--verify --repair`). Turns out I was excluding caches from my backup...
Commit 9b049849bf deleted the patch file
(and reference to it from fontconfig default.nix), but left the one in
2.10.nix which break evaluation.
As the package seems to build fine without the patch, just remove the
reference.
cc @ttuegel in case this was not the correct thing to do.
The Infinality bytecode interpreter is removed in favor of the new v40 TrueType
interpreter. In the past, the Infinality interpreter provided support for
ClearType-style hinting instructions while the default interpreter (then v35)
provided support only for original TrueType-style instructions. The v40
interpreter corrects this deficiency, so the Infinality interpreter is no longer
necessary.
To understand why the Infinality interpreter is no longer necessary, we should
understand how ClearType differs from TrueType and how the v40 interpreter
works. The following is a summary of information available on the FreeType
website [1] mixed with my own editorializing.
TrueType instructions use horizontal and vertical hints to improve glyph
rendering. Before TrueType, fonts were only vertically hinted; horizontal hints
improved rendering by snapping stems to pixel boundaries. Horizontal hinting is
a risk because it can significantly distort glyph shapes and kerning. Extensive
testing at different resolutions is needed to perfect the TrueType
hints. Microsoft invested significant effort to do this with its "Core fonts for
the Web" project, but few other typefaces have seen this level of attention.
With the advent of subpixel rendering, the effective horizontal resolution of
most displays increased significantly. ClearType eschews horizontal hinting in
favor of horizontal supersampling. Most fonts are designed for the Microsoft
bytecode interpreter, which implements a compatibility mode with
TrueType-style (horizontal and vertical) instructions. However, applying the
full horizontal hints to subpixel-rendered fonts leads to color fringes and
inconsistent stem widths. The Infinality interpreter implements several
techniques to mitigate these problems, going so far as to embed font- and
glyph-specific hacks in the interpreter. On the other hand, the v40 interpreter
ignores the horizontal hinting instructions so that glyphs render as they are
intended to on the Microsoft interpreter. Without the horizontal hints, the
problems of glyph and kerning distortion, color fringes, and inconsistent stem
widths--the problems the Infinality interpreter was created to solve--simply
don't occur in the first place.
There are also security concerns which motivate removing the Infinality patches.
Although there is an updated version of the Infinality interpreter for FreeType
2.7, the lack of a consistent upstream maintainer is a security concern. The
interpreter is a Turing-complete virtual machine which has had security
vulnerabilities in the past. While the default interpreter is used in billions
of devices and is maintained by an active developer, the Infinality interpreter
is neither scrutinized nor maintained. We will probably never know if there are
defects in the Infinality interpreter, and if they were discovered they would
likely never be fixed. I do not think that is an acceptable situtation for a
core library like FreeType.
Dropping the Infinality patches means that font rendering will be less
customizable. I think this is an acceptable trade-off. The Infinality
interpreter made many compromises to mitigate the problems with horizontal
hinting; the main purpose of customization is to tailor these compromises to the
user's preferences. The new interpreter does not have to make these compromises
because it renders fonts as their designers intended, so this level of
customization is not necessary.
The Infinality-associated patches are also removed from cairo. These patches
only set the default rendering options in case they aren't set though
Fontconfig. On NixOS, the rendering options are always set in Fontconfig, so
these patches never actually did anything for us!
The Fontconfig test suite is patched to account for a quirk in the way PCF fonts
are named.
The fontconfig option `hintstyle` is no longer configurable in NixOS. This
option selects the TrueType interpreter; the v40 interpreter is `hintslight` and
the older v35 interpreter is `hintmedium` or `hintfull` (which have actually
always been the same thing). The setting may still be changed through the
`localConf` option or by creating a user Fontconfig file.
Users with HiDPI displays should probably disable hinting and antialiasing: at
best they have no visible effect.
The fontconfig-ultimate settings are still available in NixOS, but they are no
longer the default. They still work, but their main purpose is to set rendering
quirks which are no longer necessary and may actually be
detrimental (e.g. setting `hintfull` for some fonts). Also, the vast array of
font substitutions provided is not an appropriate default; the default setting
should be to give the user the font they asked for.
[1]. https://www.freetype.org/freetype2/docs/subpixel-hinting.html
This reverts commit 1daf2e26d2, reversing
changes made to c0c50dfcb7.
It seems this is what has been causing all the reliability problems
on Hydra. I'm currently unable to find why it happens, so I'm forced
to revert the update for now. Discussion: #22874.