diff options
| author | Fabrice <fabrice@schaub-dev.xyz> | 2026-02-12 22:18:30 +0100 |
|---|---|---|
| committer | Fabrice <fabrice@schaub-dev.xyz> | 2026-02-12 22:18:30 +0100 |
| commit | 8bb8fe61649ceab5e9b2ba231b767a5a7bbc344c (patch) | |
| tree | 8ad65cca37831c2496f4c6f359b7139648611511 /src/text.cc | |
| parent | 59912666dcd3e3119ca821c15b7a68ec612f6c18 (diff) | |
creating font
Diffstat (limited to 'src/text.cc')
| -rw-r--r-- | src/text.cc | 37 |
1 files changed, 36 insertions, 1 deletions
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); +} |
