Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the fonts directory path in different OS?

I'm developing a module for generate CAPTCHA. This module needs a font file, but the fonts directory path are different in different operating system. Is there a universal way to get the fonts directory path that can be used in different OS?

like image 474
user805627 Avatar asked Oct 24 '25 17:10

user805627


2 Answers

I don't think there is any such library, atmost wxPython have a wxStandarPaths which can give OS specific paths, may be you can use that to get fonts folder.

But I think even with that you will have to do tweaks per OS, so easiest way is to just create you own function get_font_folder and keep on adding OS to font folder mapping as you test or find bugs :)

like image 110
Anurag Uniyal Avatar answered Oct 27 '25 08:10

Anurag Uniyal


Do it with pycairo. You don't even need to know the system font path. You just do

font_map = pangocairo.cairo_font_map_get_default()
families = font_map.list_families()

and you have a list of all the font families.

You can also get a font by its name like

font = pango.FontDescription("Utopia 22")

If you're on a Unix ecosystem then it's the way to go.

like image 37
rantanplan Avatar answered Oct 27 '25 08:10

rantanplan