mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 07:11:41 +00:00
[ui] Use fontconfig to find system fonts
I'm not sure I like fontconfig (docs are...), but it is pretty standard, and I was able to find some reasonable examples on stackexchange (https://stackoverflow.com/questions/10542832/how-to-use-fontconfig-to-get-font-list-c-c). Currently, only the one font is handled, no font sets for fall backs etc. It's meant for the debug UI I'm working on, so that shouldn't be a big deal.
This commit is contained in:
parent
31151ec5d5
commit
5fcc743d1a
5 changed files with 44 additions and 0 deletions
|
@ -30,3 +30,19 @@ AC_SUBST(HARFBUZZ_LIBS)
|
|||
if test "x$HAVE_HARFBUZZ" == "xyes"; then
|
||||
AC_DEFINE(HAVE_HARFBUZZ, 1, [Define if you have the HarfBuzz library])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(fontconfig,
|
||||
AS_HELP_STRING([--disable-fontconfig], [disable fontconfig support]))
|
||||
if test "x$enable_fontconfig" != "xno"; then
|
||||
if test "x$PKG_CONFIG" != "x"; then
|
||||
PKG_CHECK_MODULES([FONTCONFIG], [fontconfig], HAVE_FONTCONFIG=yes, HAVE_FONTCONFIG=no)
|
||||
fi
|
||||
else
|
||||
HAVE_FONTCONFIG=no
|
||||
FONTCONFIG_LIBS=
|
||||
fi
|
||||
AC_SUBST(FONTCONFIG_LIBS)
|
||||
|
||||
if test "x$HAVE_FONTCONFIG" == "xyes"; then
|
||||
AC_DEFINE(HAVE_FONTCONFIG, 1, [Define if you have the fontconfig library])
|
||||
fi
|
||||
|
|
|
@ -57,5 +57,7 @@ typedef struct font_s {
|
|||
void Font_Init (void);
|
||||
void Font_Free (font_t *font);
|
||||
font_t *Font_Load (QFile *font_file, int size);
|
||||
// free the returned string
|
||||
char *Font_SystemFont (const char *font_pattern);
|
||||
|
||||
#endif//__QF_ui_font_h
|
||||
|
|
|
@ -8,6 +8,7 @@ gui_deps = \
|
|||
libs/ui/libQFui.la
|
||||
|
||||
gui_libadd = \
|
||||
$(FONTCONFIG_LIBS) \
|
||||
$(FREETYPE_LIBS) \
|
||||
$(HARFBUZZ_LIBS)
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#include <fontconfig/fontconfig.h>
|
||||
|
||||
#include "QF/quakefs.h"
|
||||
#include "QF/sys.h"
|
||||
#include "QF/math/bitop.h"
|
||||
|
@ -144,3 +146,25 @@ Font_Load (QFile *font_file, int size)
|
|||
|
||||
return font;
|
||||
}
|
||||
|
||||
char *
|
||||
Font_SystemFont (const char *font_pattern)
|
||||
{
|
||||
auto config = FcInitLoadConfigAndFonts ();
|
||||
auto pattern = FcNameParse ((const FcChar8 *) font_pattern);
|
||||
FcConfigSubstitute (config, pattern, FcMatchPattern);
|
||||
FcDefaultSubstitute (pattern);
|
||||
|
||||
FcResult result;
|
||||
auto font = FcFontMatch (config, pattern, &result);
|
||||
char *filename = 0;
|
||||
if (font) {
|
||||
FcChar8 *str;
|
||||
if (FcPatternGetString (font, FC_FILE, 0, &str) == FcResultMatch) {
|
||||
filename = strdup ((char *) str);
|
||||
}
|
||||
FcPatternDestroy (font);
|
||||
}
|
||||
FcPatternDestroy (pattern);
|
||||
return filename;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ renderer_libs= \
|
|||
libs/util/libQFutil.la
|
||||
|
||||
renderer_libadd= \
|
||||
$(FONTCONFIG_LIBS) \
|
||||
$(FREETYPE_LIBS) \
|
||||
$(HARFBUZZ_LIBS)
|
||||
|
||||
|
|
Loading…
Reference in a new issue