Friday 7 January 2011

Fonts: Find font files by font family name

Sometime you want to use a piece of software or a library, such as  Imager Graph are not linked to the fontconfig lib. Because of that, you can't specify fonts by simply using their family name (Like 'FreeSerif' for instance).

So you need a way to resolve a font's family name to the full path of the font files on disk. Here's how to do it for the FreeSerif one:


$ fc-list -f "%{family} %{style[0]} %{file}\n" 'FreeSerif'
FreeSerif Bold /usr/share/fonts/truetype/freefont/FreeSerifBold.ttf
FreeSerif Medium /usr/share/fonts/truetype/freefont/FreeSerif.ttf
FreeSerif Italic /usr/share/fonts/truetype/freefont/FreeSerifItalic.ttf
FreeSerif BoldItalic /usr/share/fonts/truetype/freefont/FreeSerifBoldItalic.ttf

Maybe one day there will be a Perl module bound to the libfontconfig. Until there, a simple system call will probably do for me :)

EDIT 31st Jan 2011:

There's no -f option in older systems, you can also use

$ fc-list  'FreeSerif' file
/usr/share/fonts/truetype/freefont/FreeSerifBoldItalic.ttf: 
/usr/share/fonts/truetype/freefont/FreeSerif.ttf: 
/usr/share/fonts/truetype/freefont/FreeSerifBold.ttf: 
/usr/share/fonts/truetype/freefont/FreeSerifItalic.ttf:

No comments:

Post a Comment