#include <FL/Fl.H>
#include "cfl.h"
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
#define i_load_private_font(PATH) AddFontResourceEx((PATH), FR_PRIVATE, 0)
#define v_unload_private_font(PATH) RemoveFontResourceEx((PATH), FR_PRIVATE, 0)
#include <windows.h>
#elif __APPLE__
#include <ApplicationServices/ApplicationServices.h>
static int i_load_private_font(const char *pf) {
int result = 0;
CFErrorRef err;
CFURLRef fontURL = CFURLCreateFromFileSystemRepresentation(
kCFAllocatorDefault, (const UInt8 *)pf, strlen(pf), false);
if (CTFontManagerRegisterFontsForURL(fontURL, kCTFontManagerScopeProcess, &err)) {
result = 1; } else {
printf("Failed loading font: %s\n", pf);
}
if (fontURL)
CFRelease(fontURL);
return result;
}
static void v_unload_private_font(const char *pf) {
CFErrorRef err;
CFURLRef fontURL = CFURLCreateFromFileSystemRepresentation(
kCFAllocatorDefault, (const UInt8 *)pf, strlen(pf), false);
CTFontManagerUnregisterFontsForURL(fontURL, kCTFontManagerScopeProcess, &err);
if (fontURL)
CFRelease(fontURL);
} #elif __ANDROID__
#else
#include <fontconfig/fontconfig.h>
#define USE_XFT 1
#define i_load_private_font(PATH) (int)FcConfigAppFontAddFile(NULL, (const FcChar8 *)(PATH))
#define v_unload_private_font(PATH) FcConfigAppFontClear(NULL)
#endif
#if defined(_MSC_VER) && _MSC_VER < 1900
#define snprintf _snprintf
#endif
int Fl_load_font(const char *path) {
#ifndef __ANDROID__
return i_load_private_font(path);
#else
return 0;
#endif
}
void Fl_unload_font(const char *path) {
#ifndef __ANDROID__
v_unload_private_font(path);
#endif
}