From e3c27591e4ac9fa6c776095bb685da2092d2ddff Mon Sep 17 00:00:00 2001 From: Caleb Hearon Date: Mon, 22 Feb 2016 12:14:55 -0500 Subject: [PATCH] fix fonts not working after a call to getContext issue was limited to osx and windows before this, if you create a canvas and get its context, the fonts would freeze - you cannot add any fonts after getContext is called once, even if you set up a new canvas. i fixed this by refreshing the Pango FontMap (the component that does font lookups) after you create a canvas+context, that canvas+context will not be able to use new fonts, but that is less of a problem --- src/register_font.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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; }