Handle the prefix
attribute specially for the <include>
directive
#7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Currently, for all of the four directives that has the
prefix
attribute (include
,dir
,remap-dir
,cachedir
), whenprefix
is omitted or isdefault
,calculate_path
will just return the (possibly tilde-expanded) path as is, which is more or less the same as usingcwd
.However, fontconfig actually handles the
<include>
directive in a special way: if the path supplied is relative, then the "config path" instead of the CWD is prepended to it; this path is determined when fontconfig is built, and on Linux this is usually/etc/fonts
. This PR implements this behavior. Note the new behavior is by far not a 1:1 clone of the fontconfig library, but is closer.The change is important because the "builtin" config files follows this convention. For example,
/etc/fonts/fonts.conf
usuallyinclude
sconf.d
, which gets resolved as/etc/fonts/conf.d
; and there's usually/etc/fonts/conf.d/50-user.conf
whichinclude
sfontconfig/conf.d
andfontconfig/fonts.conf
withprefix="xdg"
. That's the reason fontconfig finds and loads config files in~/.config/fontconfig
. So after this change, on a usual Linux setup (Arch, NixOS, etc.), loading only/etc/fonts/fonts.conf
should be sufficient to recursively import everything in/etc/fonts/conf.d
,~/.config/fontconfig/conf.d/*
, etc.Changes
After this PR,
calculate_path
works like this:<include>
the default prefix to prepend on Linux is/etc/fonts
. On Windows, fontconfig usesGetModuleFileName
to get the path. From its docs I guess that's the path to the executable, but I cannot test so I just don't prepend any prefix. (Still, I didn't run, I just tried to make sure it can build.)./
. (The original "default" behavior here is to return the path as is, and they are equivalent for relative paths AFAIC. For absolute paths the new behavior is to return early, which AFAIC is more correct.)P.S. The issue has already been reported to some consumers of this crate, e.g. RazrFalcon/fontdb#59. I think those went to the wrong place :-)