From 8bb8fe61649ceab5e9b2ba231b767a5a7bbc344c Mon Sep 17 00:00:00 2001 From: Fabrice Date: Thu, 12 Feb 2026 22:18:30 +0100 Subject: creating font --- src/text.cc | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src/text.cc') diff --git a/src/text.cc b/src/text.cc index 0cd81d6..6753061 100644 --- a/src/text.cc +++ b/src/text.cc @@ -109,4 +109,39 @@ void wayc_font_context_deinit(struct font_context_s* context) { sg_destroy_pipeline(context->pipeline); sg_destroy_sampler(context->sampler); FT_Done_FreeType(context->ft); -} \ No newline at end of file +} + +enum font_error_e wayc_font_init(struct font_s* font, + struct font_context_s* context, + const char* path, u32 font_size, + u32 atlas_width, u32 atlas_height) { + wayc_notnull(font); + wayc_notnull(context); + memset(font, 0, sizeof(*font)); + bool success = false; + + FT_Face face; + FT_Error fterr = FT_New_Face(context->ft, path, 0, &face); + if (fterr) return FONT_ERROR_LOAD_FACE; + + wayc_defer_cond(FT_Done_Face(face), success, true); + + struct atlas_s atlas; + enum atlas_error_e aterr = + wayc_atlas_init(&atlas, atlas_width, atlas_height, SG_PIXELFORMAT_R8); + if (aterr) return FONT_ERROR_LOAD_FACE; + + font->face = face; + font->font_size = font_size; + font->atlas = atlas; + + success = true; + return FONT_ERROR_NONE; +} + +void wayc_font_deinit(struct font_s* font) { + wayc_notnull(font); + + wayc_atlas_deinit(&font->atlas); + FT_Done_Face(font->face); +} -- cgit v1.2.3