]> granicus.if.org Git - libass/commitdiff
fontselect: simplify lookup of embedded fonts
authorGrigori Goronzy <greg@chown.ath.cx>
Fri, 12 Jun 2015 00:04:43 +0000 (02:04 +0200)
committerGrigori Goronzy <greg@chown.ath.cx>
Fri, 10 Jul 2015 08:42:41 +0000 (10:42 +0200)
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

index 787e3a837a0ac88487af6cc4fcd0695f79b63fda..95a4038b8c279253829726ff23cda28af5e4eb73 100644 (file)
@@ -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)) {