3

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?

Griffin
  • 716
  • 7
  • 25

1 Answers1

2

(@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);
Griffin
  • 716
  • 7
  • 25