Location of truetype fonts

21

3

I would like to create a small script that installs a few truetype fonts on the user's system. On my Ubuntu machine the truetype fonts are located at /usr/share/fonts/truetype. However, I'm not sure if this location is the same on all machines. Is there a way to find out where truetypes fonts are stored on any Linux system?

Update
After some research I found that the path usr/share/fonts/truetype is specified in the XML file /etc/fonts/fonts.conf. It's an XML file, so I can use XPath to get the dir:

xpath -q -e 'fontconfig/dir[1]/text()[1]' /etc/fonts/fonts.conf

I don't know however if this file will exist on all (or most) Linux systems.

StackedCrooked

Posted 2010-05-05T13:55:46.803

Reputation: 2 525

Also see fc-cache(1) man page, which allows you add new fonts to the system.

– jww – 2019-12-23T12:28:54.407

Answers

22

Every font that is located under any subdirectory of /usr/share/fonts and ~/.fonts is scanned and added to the collection you're able to use. So as long as your font is inside one of those two directories it is correclty located, that location is the same for almost every major linux distro.

Update:

By the way I can confirm that fonts.conf file is present on both Fedora and Ubuntu (and their derivates: Xubuntu, Lubuntu, Linux Mint, Cinnammon, Peppermint OS, Fedora and all its spins, to mention some).

arielnmz

Posted 2010-05-05T13:55:46.803

Reputation: 2 960

1Then, why do I have fonts in Firefox and gnome-font-viewer which are not exist in those locations (/usr/share/fonts and ~/.fonts) ? I use Fedora 28 – Accountant م – 2018-07-08T20:55:21.403

You might also want to check FONTCONFIG_PATH first. FONTCONFIG_PATH is used to override the default configuration directory. – jww – 2019-12-23T12:45:48.853

4

In Fedora the folder path is /home/{user}/.local/share/fonts

you can copy/paste font files here.

AliMo

Posted 2010-05-05T13:55:46.803

Reputation: 41

1

All distributions are differents, you're better to set a default path and let the user select between the default and a custom one.

Edit:

In my opinion, you have three solutions because there is no environment variable or function for that.

  1. Set a default path and let the user select between the default and a custom one.
  2. Like dtrosset said, you could create packages with your fonts for the different distributions.
  3. You could use if/elif/else and test -e to determine if the different font server paths exist. If no one exist, show the default path and let the user select between it and a custom one.

Ex:

DEFAULT="$home/.fonts/"
UBUNTU_XFSTT="/usr/share/fonts/truetype/"
RHL52_XFS="/usr/X11R6/lib/X11/fonts/ttfonts/"
RHL6_XFSTT="/usr/X11R6/lib/X11/fonts/"
DEBIAN_XFSTT="/usr/share/fonts/truetype/"

#Test if directory exist
if test -e ${UBUNTU_XFSTT} ; then
    echo ${UBUNTU_XFSTT}
elif test -e ${RHL52_XFS} ; then
    echo ${RHL52_XFS}
elif test -e ${RHL6_XFSTT} ; then
    echo ${RHL6_XFSTT}
elif test -e ${DEBIAN_XFSTT} ; then
    echo ${DEBIAN_XFSTT}
else
    echo ${DEFAULT}
fi

P.S. That's only MY opinion...

geek1983

Posted 2010-05-05T13:55:46.803

Reputation: 114

-1 Hack. This is not a solution and it'll only cause woe for the developer, StackedCrooked, in this case since we can't depend on each user knowing where their ttf files are. If even the developer doesn't even know where the files are, how are we supposed to expect a user to know? – Nitrodist – 2010-05-05T17:29:22.653

You might also want to check FONTCONFIG_PATH first. FONTCONFIG_PATH is used to override the default configuration directory. – jww – 2019-12-23T12:39:39.253

0

Maybe you could consider creating a package with your fonts. It is a bit of work creating the package description files, and creation rules. But you gain ability to update and uninstall for free. For Ubuntu, you should create .deb files.

Didier Trosset

Posted 2010-05-05T13:55:46.803

Reputation: 629