Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create PangoFont object from TTF font file?

I've been reading the gnome APIs for pango but cannot find a simple way to get a PangoFont from ttf font file that I have.

What are the sequence calls for getting a PangoFont object from a TTF file?

like image 965
Griffin Avatar asked Sep 10 '25 14:09

Griffin


1 Answers

(@Griffin of couple of hours ago) To add the font from a TTF file you need to first make sure it is first added to FcConfig and then retrieve its PangoFont via its pango_font_description_from_string as below:

//first add to FcConfig
std::string FontPath = "/path/to/font.ttf"
const FcChar8 * fontFile = (const FcChar8 *)FontPath.c_str();
FcBool fontAddStatus = FcConfigAppFontAddFile(FcConfigGetCurrent(), fontFile);

//then retrieve it via its fontDescriptor with pango
PangoFontDescription * desc = pango_font_description_from_string("SOME-FONT-FAMILY SOME-STYLE");
PangoFontMap* pfm = pango_cairo_font_map_get_default();
PangoFont* font =  pango_font_map_load_font(pfm, context, desc);
like image 134
Griffin Avatar answered Sep 13 '25 05:09

Griffin