Browse Source
this is implemented differently depending on the operating system. for MacOS, CTFontManagerRegisterFontsForURL is the call to add a temporary font. for Linux we use FontConfig, and for Windows use AddFontResourceEx. all have been tested successfully updated README and examples/font.jsmaster
Caleb Hearon
9 years ago
10 changed files with 105 additions and 23 deletions
@ -0,0 +1,21 @@ |
|||||
|
#ifdef __APPLE__ |
||||
|
#include <CoreFoundation/CoreFoundation.h> |
||||
|
#include <CoreText/CoreText.h> |
||||
|
#elif defined(_WIN32) |
||||
|
#include <windows.h> |
||||
|
#else |
||||
|
#include <fontconfig/fontconfig.h> |
||||
|
#endif |
||||
|
|
||||
|
bool |
||||
|
register_font(unsigned char *filepath) { |
||||
|
#ifdef __APPLE__ |
||||
|
CFURLRef filepathUrl = CFURLCreateFromFileSystemRepresentation(NULL, filepath, strlen((char*)filepath), false); |
||||
|
return CTFontManagerRegisterFontsForURL(filepathUrl, kCTFontManagerScopeProcess, NULL); |
||||
|
#elif defined(_WIN32) |
||||
|
return AddFontResourceEx((LPCSTR)filepath, FR_PRIVATE, 0) != 0; |
||||
|
#else |
||||
|
return FcConfigAppFontAddFile(FcConfigGetCurrent(), (FcChar8 *)(filepath)); |
||||
|
#endif |
||||
|
} |
||||
|
|
@ -0,0 +1,2 @@ |
|||||
|
bool register_font(unsigned char *filepath); |
||||
|
|
Loading…
Reference in new issue