Skip to content

Commit

Permalink
font: Add FreeType cleanups
Browse files Browse the repository at this point in the history
Release the font face when the font is no longer used and deinitialize
the FT library on shutdown.

Signed-off-by: Alexander Shishkin <[email protected]>
  • Loading branch information
virtuoso committed Oct 5, 2024
1 parent 978b38d commit 8b22263
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/clap.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ void clap_done(struct clap_context *ctx, int status)
phys_done();
if (ctx->cfg.graphics)
gl_done();
if (ctx->cfg.font)
font_done();
messagebus_done();
exit_cleanup_run(status);
}
8 changes: 8 additions & 0 deletions core/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static void font_drop(struct ref *ref)
for (i = 0; i < array_size(font->g); i++)
texture_deinit(&font->g[i].tex);
free(font->name);
FT_Done_Face(font->face);
}

DECLARE_REFCLASS(font);
Expand Down Expand Up @@ -153,3 +154,10 @@ int font_init(void)
dbg("freetype initialized\n");
return 0;
}

void font_done(void)
{
if (default_font)
font_put(default_font);
FT_Done_FreeType(ft);
}
1 change: 1 addition & 0 deletions core/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct glyph {

struct font;
int font_init(void);
void font_done(void);
const char *font_name(struct font *font);
struct font *font_open(const char *name, unsigned int size);
void font_put(struct font *font);
Expand Down

0 comments on commit 8b22263

Please sign in to comment.