4

I am trying to load a non system font to my GTK application. I have tried using pango to achieve that. Here's my code:

string fontPath = "res/fonts/FreeSans.ttf";
const FcChar8 *fontFile = (const FcChar8*) fontPath.c_str();
FcBool fontAddStatus = FcConfigAppFontAddFile(FcConfigGetCurrent(), fontFile);
if(fontAddStatus)
{
    FcFontSet *fontSet = FcConfigGetFonts (FcConfigGetCurrent(), FcSetApplication);
    PangoFontDescription *desc = pango_fc_font_description_from_pattern(fontSet->fonts[0], false);
    pango_font_description_set_family(desc, "FreeSans");
    PangoAttribute *attr = pango_attr_font_desc_new(desc);
    PangoAttrList *attrs = gtk_label_get_attributes(GTK_LABEL(lbl_0));
    pango_attr_list_change(attrs, attr);
    pango_layout_set_attributes (gtk_label_get_layout(GTK_LABEL(lbl_0)), attrs);
}

When I run that code it gives me:

Pango-WARNING **: couldn't load font "FreeSans Not-Rotated 10", falling back to "Sans Not-Rotated 10", expect ugly output.

How can I do that successfully?

Many thanks

Ramywhite
  • 92
  • 1
  • 7

0 Answers0