#include <FL/Fl.H>
#include <cfltk/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__
#elif __EMSCRIPTEN__
#else
#include <fontconfig/fontconfig.h>
#define USE_XFT 1
#define i_load_private_font(PATH) \
(int)FcConfigAppFontAddFile(nullptr, (const FcChar8 *)(PATH))
#define v_unload_private_font(PATH) FcConfigAppFontClear(nullptr)
#endif
#if defined(_MSC_VER) && _MSC_VER < 1900
#define snprintf _snprintf
#endif
int Fl_load_font(const char *path) {
#if defined(__ANDROID__) || defined(__EMSCRIPTEN__)
return 0;
#else
return i_load_private_font(path);
#endif
}
void Fl_unload_font(const char *path) {
#if defined(__ANDROID__) || defined(__EMSCRIPTEN__)
#else
v_unload_private_font(path);
#endif
}