I want to be able to get the absolute path to a ttf font file on Linux when given a font name (if it exists). Is there a command or API that will return that information?
For example, given "arial.ttf" I want to find the absolute path (e.g. /usr/share/fonts/truetype/msttcorefonts/arial.ttf) wherever that may be.
The easiest way is probably to use fontconfig
with the --format
option:
$ fc-match --format=%{file} LiberationSans-Regular.ttf
will result in the output
/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf
Instead of the font file name, you can also supply a font description that may be something like mono
, DejaVu
, :weight=bold
, DejaVu-12
, or DejaVu:weight=bold
. So, for example,
$ fc-match --format=%{file} :weight=bold
results in
/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf
on my system. The only thing that does not seem to work is giving the complete path of the font file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With