Skip to content

Help Fontconfig to discover hidden fonts

Notifications You must be signed in to change notification settings

eric-brechemier/fontconfig-bridge-for-hidden-fonts

Repository files navigation

fontconfig-bridge-for-hidden-fonts

Help Fontconfig to discover hidden fonts.

Usage

Run the script help-fontconfig-discover-hidden-fonts-for.sh to refresh the list of fonts available in Fontconfig:

$ ./help-fontconfig-discover-hidden-fonts-for.sh [name] [cache]

The script takes two parameters:

  • name: string, used to create a distinct folder for each font service
  • cache: path, location of the parent folder of hidden fonts

For each hidden font in the hidden cache folder of the subscription service, the script creates a symbolic links in a location known to Fontconfig, in a subfolder with the given service name.

For example, if you are subscribed to a fictitious font subscription service called fontitious which stores its fonts locally as hidden font files in the folder ~/Library/Application Support/Fontitious/.fonts/, you would need to call the script after each change in your font subscriptions as:

$ ./help-fontconfig-discover-hidden-fonts-for.sh fontitious \
              ~/Library/Application\ Support/Fontitious/.fonts

I am using this script on macOS Catalina; the hidden fonts get listed successfully in Gimp, Krita, Inkscape and Scribus after running the script and restarting each app.

Inkscape 1.x ships its own version of fontconfig, with a restricted configuration which requires a bit more work: if the folder ~/Library/Application\ Support/org.inkscape.Inkscape is found, an extra configuration file, 00-load-xdg-fonts.conf is created in org.inkscape.Inkscape/config/fontconfig/conf.d/ by the script, to allow loading fonts from the same local location which is shared out of the box with Gimp, Krita and Scribus.

Rationale

Font subscription services tend to store their fonts on the local drive of the subscribers as hidden files in a hidden cache folder.

While scanning font folders recursively, Fontconfig silently ignores any hidden file or folder. It is still possible to get Fontconfig to consider a hidden font folder, such as ~/.fonts, when it is included explicitly in Fontconfig configuration. But there is currently no way to make Fontconfig consider hidden font files.

The source code explicitly filters out any file name starting with a .:

    while ((e = readdir (d)))
    {
	if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN)
	{
	    strcpy ((char *) base, (char *) e->d_name);
	    if (!FcStrSetAdd (files, file_prefix)) {
		ret = FcFalse;
		goto bail2;
	    }
	}
    }

fontconfig/src/fcdir.c, lines 256–266

This project offers a simple workaround by creating symbolic links for hidden font files in a subfolder of one of the local folders configured in Fontconfig.

References

  1. Fontconfig
  2. man fonts-conf
  3. XDG Base Directory Specification
  4. Fontconfig source repository
  5. Restrictive fonts.conf config in Inkscape

Author

Eric Bréchemier

License

Creative Commons CC0 “No Rights Reserved”