Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Locating fonts on Linux (in C++)

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.

like image 749
Kazade Avatar asked Oct 14 '22 20:10

Kazade


1 Answers

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.

like image 183
cmaster - reinstate monica Avatar answered Nov 10 '22 13:11

cmaster - reinstate monica