From ef707a9e7d1934c433a55b9f7f4376ca6e7956d1 Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Fri, 12 Jun 2015 02:04:43 +0200 Subject: fontselect: simplify lookup of embedded fonts Currently, it is not safe to change the embedded fonts (ass_add_font/ass_clear_fonts) while an ASS_Renderer exists. We can simplify how embedded fonts are looked up because of that. At some point, ASS_Library and ASS_Renderer should be merged and we can then implement a more flexible approach. --- libass/ass_fontselect.c | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/libass/ass_fontselect.c b/libass/ass_fontselect.c index 787e3a8..95a4038 100644 --- a/libass/ass_fontselect.c +++ b/libass/ass_fontselect.c @@ -110,7 +110,6 @@ typedef struct font_data_ft FontDataFT; struct font_data_ft { ASS_Library *lib; FT_Face face; - char *name; int idx; }; @@ -129,24 +128,9 @@ static void destroy_font_ft(void *data) FontDataFT *fd = (FontDataFT *)data; FT_Done_Face(fd->face); - free(fd->name); free(fd); } -/** - * \brief find a memory font by name - * \param library ASS library - * \param name font name - */ -static int find_font(ASS_Library *library, char *name) -{ - int i; - for (i = 0; i < library->num_fontdata; ++i) - if (strcasecmp(name, library->fontdata[i].name) == 0) - return i; - return -1; -} - static size_t get_data_embedded(void *data, unsigned char *buf, size_t offset, size_t len) { @@ -154,9 +138,6 @@ get_data_embedded(void *data, unsigned char *buf, size_t offset, size_t len) ASS_Fontdata *fd = ft->lib->fontdata; int i = ft->idx; - if (ft->idx < 0) - ft->idx = i = find_font(ft->lib, ft->name); - if (buf == NULL) return fd[i].size; @@ -792,10 +773,9 @@ static void process_fontdata(ASS_FontProvider *priv, ASS_Library *library, continue; } - ft->lib = library; - ft->face = face; - ft->name = strdup(name); - ft->idx = -1; + ft->lib = library; + ft->face = face; + ft->idx = idx; if (ass_font_provider_add_font(priv, &info, NULL, face_index, NULL, ft)) { -- cgit v1.2.3