wch / extrafont

Tools for using fonts in R graphics
312 stars 49 forks source link

add ~/.local/share/fonts to search path for linux #52

Open jwhendy opened 7 years ago

jwhendy commented 7 years ago

Greetings,

I used this for the first time and was a bit perplexed as I knew I had a font installed but font_import() wasn't finding it. It was in ~/.local/share/fonts/, which according to the arch linux wiki is the recommended path for user fonts:

To install fonts system-wide (available for all users), move the folder to the /usr/share/fonts/ directory. The files need to be readable by every user, use chmod to set the correct permissions (i.e. at least 0444 for files and 0555 for directories). To install fonts for only a single user, use ~/.local/share/fonts (~/.fonts/ is now deprecated).

Could you add this to your search paths? From looking at the path building, I figured it would just be this change, but I didn't look everywhere:

 # Possible font paths, depending on the system
    paths <-
      c("/usr/share/fonts/",                    # Ubuntu/Debian/Arch/Gentoo
        "/usr/X11R6/lib/X11/fonts/TrueType/",   # RH 6
        "~/.fonts/",                            # User fonts
        "~/.local/share/fonts)                  # User fonts (added)
    return(paths[file.exists(paths)])

It seems both may be advised... I'm on arch linux, but in googling to find out how widespread this is, it's a mixed bag. Arch and gentoo mention the new location, but ubuntu, freebsd, and debian still reference the ~/.fonts directory in their docs.

The new recommendation appears to be a combination of:

$XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.

This element contains a directory name which will be scanned for font files to include in the set of available fonts. If 'prefix' is set to "xdg", the value in the XDG_DATA_HOME environment variable will be added as the path prefix. please see XDG Base Directory Specification for more details.

So, perhaps depending on the distro the xdg value is set as the prefix and thus the path needs to be $XDG_DATA_HOME/fonts ($HOME/.local/share/fonts), not just ~/.fonts.

P.S. Credit to this bug for putting those last two points together. For this being a "thing" to mention on the arch linux wiki, I was surprised at the lack of information on why one vs. the other.

statnmap commented 5 years ago

I faced the same problem with Ubuntu. I just opened a PR for that: https://github.com/wch/extrafont/pull/64