diff options
| -rw-r--r-- | AdwaitaMono-Regular.ttf | bin | 0 -> 1417460 bytes | |||
| -rw-r--r-- | src/text.cc | 24 | ||||
| -rw-r--r-- | src/text.h | 13 | ||||
| -rw-r--r-- | src/wayclock.cc | 7 |
4 files changed, 43 insertions, 1 deletions
diff --git a/AdwaitaMono-Regular.ttf b/AdwaitaMono-Regular.ttf Binary files differnew file mode 100644 index 0000000..b00063e --- /dev/null +++ b/AdwaitaMono-Regular.ttf diff --git a/src/text.cc b/src/text.cc index cf5345d..600220e 100644 --- a/src/text.cc +++ b/src/text.cc @@ -1,11 +1,33 @@ #include "text.h" +#include "utils.h" + enum font_context_error_e wayc_font_context_init(struct font_context_s* ctx) { + wayc_notnull(ctx); + FT_Error err = FT_Init_FreeType(&ctx->library); if (err) return FONT_CONTEXT_ERROR_LIBRARY; return FONT_CONTEXT_ERROR_NONE; } void wayc_font_context_deinit(struct font_context_s* ctx) { + wayc_notnull(ctx); + FT_Done_FreeType(ctx->library); -}
\ No newline at end of file +} + +enum font_error_e wayc_font_init(struct font_s* font, + struct font_context_s* ctx, const char* path) { + wayc_notnull(font); + wayc_notnull(ctx); + wayc_notnull(path); + + FT_Error err = FT_New_Face(ctx->library, path, 0, &font->face); + if (err) return FONT_ERROR_LOAD; + return FONT_ERROR_NONE; +} + +void wayc_font_deinit(struct font_s* font) { + wayc_notnull(font); + FT_Done_Face(font->face); +} @@ -13,3 +13,16 @@ struct font_context_s { enum font_context_error_e wayc_font_context_init(struct font_context_s* ctx); void wayc_font_context_deinit(struct font_context_s* ctx); + +enum font_error_e { + FONT_ERROR_NONE, + FONT_ERROR_LOAD, +}; + +struct font_s { + FT_Face face; +}; + +enum font_error_e wayc_font_init(struct font_s* font, + struct font_context_s* ctx, const char* path); +void wayc_font_deinit(struct font_s* font); diff --git a/src/wayclock.cc b/src/wayclock.cc index d089ea6..0852176 100644 --- a/src/wayclock.cc +++ b/src/wayclock.cc @@ -10,6 +10,7 @@ #define WAYC_APP_NAME "Wayclock" #define WAYC_APP_WIDTH 1280 #define WAYC_APP_HEIGHT 1080 +#define WAYC_FONT "AdwaitaMono-Regular.ttf" struct app_s { struct renderer_s* renderer; @@ -61,6 +62,12 @@ int main() { wayc_defer(wayc_font_context_deinit(&fctx)); + struct font_s font; + if (wayc_font_init(&font, &fctx, WAYC_FONT) != FONT_ERROR_NONE) + wayc_panic("Failed to load font"); + + wayc_defer(wayc_font_deinit(&font)); + struct eventloop_s loop; if (wayc_eventloop_init(&loop, wayc_handle) != EVENTLOOP_ERROR_NONE) wayc_panic("Failed to initialize event loop"); |
