diff --git a/src/register_font.cc b/src/register_font.cc index bdf48ef18..831d009bb 100644 --- a/src/register_font.cc +++ b/src/register_font.cc @@ -1,3 +1,7 @@ +#include +#include +#include + #ifdef __APPLE__ #include #include @@ -9,13 +13,22 @@ bool register_font(unsigned char *filepath) { + bool success; + #ifdef __APPLE__ CFURLRef filepathUrl = CFURLCreateFromFileSystemRepresentation(NULL, filepath, strlen((char*)filepath), false); - return CTFontManagerRegisterFontsForURL(filepathUrl, kCTFontManagerScopeProcess, NULL); + success = CTFontManagerRegisterFontsForURL(filepathUrl, kCTFontManagerScopeProcess, NULL); #elif defined(_WIN32) - return AddFontResourceEx((LPCSTR)filepath, FR_PRIVATE, 0) != 0; + success = AddFontResourceEx((LPCSTR)filepath, FR_PRIVATE, 0) != 0; #else - return FcConfigAppFontAddFile(FcConfigGetCurrent(), (FcChar8 *)(filepath)); + success = FcConfigAppFontAddFile(FcConfigGetCurrent(), (FcChar8 *)(filepath)); #endif + + // Tell Pango to throw away the current FontMap and create a new one. This + // has the effect of registering the new font in Pango by re-looking up all + // font families. + if (success) pango_cairo_font_map_set_default(NULL); + + return success; }