From b529ddf5dbe025310be0aaf7caa84806e4ad2741 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 1 Oct 2020 16:59:10 -0400 Subject: [PATCH] started implementing font loading function --- inc/libui.h | 4 ++++ src/libui/font_load.c | 36 ++++++++++++++++++++++++++++++++++++ src/libui/libui_impl.h | 4 ++++ 3 files changed, 44 insertions(+) create mode 100644 src/libui/font_load.c diff --git a/inc/libui.h b/inc/libui.h index b074aaf..984aaee 100644 --- a/inc/libui.h +++ b/inc/libui.h @@ -1,6 +1,10 @@ +typedef struct UIFont UIFont; typedef struct UIWin UIWin; UIWin* WindowCreate(char* title); void WindowDelete(UIWin* win); void WindowShow(UIWin* win); void WindowHide(UIWin* win); + +UIFont FontLoad(char* patt); +void FontClose(UIFont font); \ No newline at end of file diff --git a/src/libui/font_load.c b/src/libui/font_load.c new file mode 100644 index 0000000..71eed5c --- /dev/null +++ b/src/libui/font_load.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include "libui_impl.h" + +UIFont FontLoad(char* patt) +{ + static bool inited = false; + if (!inited && !FcInit()) + { + fatal("failed to initialize fontconfig"); + } + inited = true; + + XftFont* font = NULL; + FcPattern* pattern = FcNameParse((FcChar8 *)patt); + if (pattern) + { +// /* load the base font */ +// FcResult result; +// FcPattern* match = XftFontMatch(X.display, X.screen_num, pattern, &result); +// if (match) +// { +// font = XftFontOpenPattern(X.display, match); +// } +// FcPatternDestroy(pattern); +// FcPatternDestroy(match); + } + + if (!font) + { + fatal("failed to load font"); + } + + return (UIFont){ .font = font }; +} diff --git a/src/libui/libui_impl.h b/src/libui/libui_impl.h index 31ba9b9..1da7734 100644 --- a/src/libui/libui_impl.h +++ b/src/libui/libui_impl.h @@ -2,6 +2,10 @@ #include #include +struct UIFont { + XftFont* font; +}; + struct UIWin { struct UIWin* next; -- 2.52.0