mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 13:04:35 +00:00
Don't link Fontconfig
Load it dynamically instead.
This commit is contained in:
parent
4a2883b4e2
commit
7ae1427156
@ -50,11 +50,7 @@ if (RT_LIBRARY)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (GLFW_BUILD_X11 OR GLFW_BUILD_WAYLAND)
|
if (GLFW_BUILD_X11 OR GLFW_BUILD_WAYLAND)
|
||||||
find_package(Fontconfig)
|
target_compile_definitions(input_text PRIVATE FONTCONFIG_ENABLED)
|
||||||
if (FONTCONFIG_FOUND)
|
|
||||||
target_compile_definitions(input_text PRIVATE FONTCONFIG_ENABLED)
|
|
||||||
target_link_libraries(input_text fontconfig)
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(GUI_ONLY_BINARIES empty gamma icon input_text inputlag joysticks tearing
|
set(GUI_ONLY_BINARIES empty gamma icon input_text inputlag joysticks tearing
|
||||||
|
@ -85,10 +85,6 @@
|
|||||||
|
|
||||||
#include "getopt.h"
|
#include "getopt.h"
|
||||||
|
|
||||||
#if defined(FONTCONFIG_ENABLED)
|
|
||||||
#include <fontconfig/fontconfig.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MAX_BUFFER_LEN 1024
|
#define MAX_BUFFER_LEN 1024
|
||||||
|
|
||||||
// https://github.com/Immediate-Mode-UI/Nuklear/wiki/Complete-font-guide
|
// https://github.com/Immediate-Mode-UI/Nuklear/wiki/Complete-font-guide
|
||||||
@ -231,24 +227,89 @@ static int load_custom_font()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(FONTCONFIG_ENABLED)
|
#if defined(FONTCONFIG_ENABLED)
|
||||||
|
|
||||||
|
#include <dlfcn.h>
|
||||||
|
|
||||||
|
typedef struct _FcConfig FcConfig;
|
||||||
|
|
||||||
|
typedef struct _FcFontSet
|
||||||
|
{
|
||||||
|
int nfont;
|
||||||
|
int sfont;
|
||||||
|
void **fonts;
|
||||||
|
} FcFontSet;
|
||||||
|
|
||||||
|
typedef struct _FcValue
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
union
|
||||||
|
{
|
||||||
|
const unsigned char* s;
|
||||||
|
double d;
|
||||||
|
} u;
|
||||||
|
} FcValue;
|
||||||
|
|
||||||
|
struct FcLib
|
||||||
|
{
|
||||||
|
void* handle;
|
||||||
|
void* (*InitLoadConfigAndFonts)(void);
|
||||||
|
void* (*ConfigGetFonts)(void*, int);
|
||||||
|
void (*ConfigDestroy)(void*);
|
||||||
|
int (*PatternGet)(const void*, const char*, int, void*);
|
||||||
|
} fcLib;
|
||||||
|
|
||||||
|
static int init_fontconfig(void)
|
||||||
|
{
|
||||||
|
if (fcLib.handle)
|
||||||
|
return GLFW_TRUE;
|
||||||
|
|
||||||
|
fcLib.handle = dlopen("libfontconfig.so.1", RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
if (!fcLib.handle)
|
||||||
|
return GLFW_FALSE;
|
||||||
|
|
||||||
|
#define GET_FC_SYMBOL(name) \
|
||||||
|
fcLib.name = dlsym(fcLib.handle, "Fc"#name); \
|
||||||
|
if (!fcLib.name) \
|
||||||
|
{ \
|
||||||
|
dlclose(fcLib.handle); \
|
||||||
|
fcLib.handle = NULL; \
|
||||||
|
return GLFW_FALSE; \
|
||||||
|
}
|
||||||
|
|
||||||
|
GET_FC_SYMBOL(InitLoadConfigAndFonts);
|
||||||
|
GET_FC_SYMBOL(ConfigGetFonts);
|
||||||
|
GET_FC_SYMBOL(ConfigDestroy);
|
||||||
|
GET_FC_SYMBOL(PatternGet);
|
||||||
|
|
||||||
|
#undef GET_FC_SYMBOL
|
||||||
|
|
||||||
|
return GLFW_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static void load_font_list_by_fontconfig()
|
static void load_font_list_by_fontconfig()
|
||||||
{
|
{
|
||||||
FcConfig* config = FcInitLoadConfigAndFonts();
|
FcConfig* config;
|
||||||
FcFontSet* fontset = FcConfigGetFonts(config, FcSetSystem);
|
FcFontSet* fontset;
|
||||||
|
|
||||||
|
if (!init_fontconfig())
|
||||||
|
return;
|
||||||
|
|
||||||
|
config = fcLib.InitLoadConfigAndFonts();
|
||||||
|
fontset = fcLib.ConfigGetFonts(config, 0 /* FcSetSystem */);
|
||||||
|
|
||||||
if (!fontset)
|
if (!fontset)
|
||||||
{
|
{
|
||||||
printf("load_font_list_by_fontconfig failed.\n");
|
printf("load_font_list_by_fontconfig failed.\n");
|
||||||
FcConfigDestroy(config);
|
fcLib.ConfigDestroy(config);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < fontset->nfont; i++)
|
for (int i = 0; i < fontset->nfont; i++)
|
||||||
{
|
{
|
||||||
FcValue fvalue, dvalue;
|
FcValue fvalue, dvalue;
|
||||||
if (FcResultMatch == FcPatternGet(fontset->fonts[i], FC_FAMILY, 0, &fvalue))
|
if (fcLib.PatternGet(fontset->fonts[i], "family", 0, &fvalue) == 0)
|
||||||
{
|
{
|
||||||
if (FcResultMatch == FcPatternGet(fontset->fonts[i], FC_FILE, 0, &dvalue))
|
if (fcLib.PatternGet(fontset->fonts[i], "file", 0, &dvalue) == 0)
|
||||||
{
|
{
|
||||||
const char* familyName = (const char*) fvalue.u.s;
|
const char* familyName = (const char*) fvalue.u.s;
|
||||||
const char* filePath = (const char*) dvalue.u.s;
|
const char* filePath = (const char*) dvalue.u.s;
|
||||||
@ -288,7 +349,7 @@ static void load_font_list_by_fontconfig()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FcConfigDestroy(config);
|
fcLib.ConfigDestroy(config);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user