# HG changeset patch # User eugeni # Date 1166297373 0 # Node ID 8111d4625194000268cfbfee854c63676fef71be # Parent 10f001e35b9149f662f0599466a89d18ea25a575 Avoid storing font file path and index in ass_font_t. diff -r 10f001e35b91 -r 8111d4625194 libass/ass_font.c --- a/libass/ass_font.c Sat Dec 16 19:28:21 2006 +0000 +++ b/libass/ass_font.c Sat Dec 16 19:29:33 2006 +0000 @@ -96,8 +96,6 @@ font = calloc(1, sizeof(ass_font_t)); font->ftlibrary = ftlibrary; - font->path = strdup(path); - font->index = index; font->face = face; font->desc.family = strdup(desc->family); font->desc.bold = desc->bold; @@ -137,7 +135,7 @@ } #ifdef HAVE_FONTCONFIG -static void ass_font_reselect(void* fontconfig_priv, ass_font_t* font) +static void ass_font_reselect(void* fontconfig_priv, ass_font_t* font, uint32_t ch) { char* path; int index; @@ -146,10 +144,6 @@ path = fontconfig_select_with_charset(fontconfig_priv, font->desc.family, font->desc.bold, font->desc.italic, &index, font->charset); - if (strcasecmp(path, font->path) == 0 && index == font->index) { - free(path); - return; - } error = FT_New_Face(font->ftlibrary, path, index, &face); if (error) { @@ -158,12 +152,15 @@ } charmap_magic(face); + error = FT_Get_Char_Index(face, ch); + if (error == 0) { // the new font face is not better then the old one + FT_Done_Face(face); + return; + } + if (font->face) FT_Done_Face(font->face); - free(font->path); font->face = face; - font->path = strdup(path); - font->index = index; FT_Set_Transform(font->face, &font->m, &font->v); FT_Set_Pixel_Sizes(font->face, 0, font->size); @@ -203,7 +200,7 @@ if (index == 0) { mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_LIBASS_GlyphNotFoundReselectingFont, ch, font->desc.family, font->desc.bold, font->desc.italic); - ass_font_reselect(fontconfig_priv, font); + ass_font_reselect(fontconfig_priv, font, ch); index = FT_Get_Char_Index(font->face, ch); if (index == 0) { mp_msg(MSGT_ASS, MSGL_ERR, MSGTR_LIBASS_GlyphNotFound, @@ -253,7 +250,6 @@ void ass_font_free(ass_font_t* font) { if (font->face) FT_Done_Face(font->face); - if (font->path) free(font->path); if (font->desc.family) free(font->desc.family); #ifdef HAVE_FONTCONFIG if (font->charset) FcCharSetDestroy(font->charset); diff -r 10f001e35b91 -r 8111d4625194 libass/ass_font.h --- a/libass/ass_font.h Sat Dec 16 19:28:21 2006 +0000 +++ b/libass/ass_font.h Sat Dec 16 19:29:33 2006 +0000 @@ -33,8 +33,6 @@ typedef struct ass_font_s { ass_font_desc_t desc; - char* path; - int index; FT_Library ftlibrary; FT_Face face; FT_Matrix m; // current transformation